Загрузка данных


#include <iostream>
#include <string>
using namespace std;

// Базовый класс "Легковой автомобиль"
class LightCar {
protected:
    string brand;
    string color;
    double tankVolume;
    double fuelRate;

public:
    LightCar(string b, string c, double tv, double fr) {
        brand = b;
        color = c;
        tankVolume = tv;
        fuelRate = fr;
        cout << "Создан легковой: " << brand << endl;
    }
    
    ~LightCar() {
        cout << "Удален легковой: " << brand << endl;
    }
    
    void show() {
        cout << "Марка: " << brand << ", Цвет: " << color 
             << ", Бак: " << tankVolume << "л, Расход: " << fuelRate << "л/100км" << endl;
    }
    
    double maxDistance() {
        return (tankVolume / fuelRate) * 100;
    }
};

// Производный класс "Грузовой автомобиль"
class Truck : public LightCar {
private:
    double capacity;
    const double price = 50;

public:
    Truck(string b, string c, double tv, double fr, double cap) 
        : LightCar(b, c, tv, fr) {
        capacity = cap;
        cout << "Создан грузовой: " << brand << " (грузоподъемность " << capacity << "т)" << endl;
    }
    
    ~Truck() {
        cout << "Удален грузовой: " << brand << endl;
    }
    
    void show() {
        LightCar::show();
        cout << "Грузоподъемность: " << capacity << "т" << endl;
    }
    
    double costPerTonPerKm() {
        return ((fuelRate / 100) * price) / capacity;
    }
};

int main() {
    setlocale(LC_ALL, "Russian");
    
    cout << "===== ДЕМОНСТРАЦИЯ ООП И НАСЛЕДОВАНИЯ =====\n" << endl;
    
    // Объект базового класса (легковой автомобиль)
    LightCar car("Toyota Camry", "Black", 60, 9.5);
    car.show();
    cout << "Макс. расстояние: " << car.maxDistance() << " км" << endl;
    
    cout << "\n----------------------\n" << endl;
    
    // Объект производного класса (грузовой автомобиль)
    Truck truck("Volvo FH", "Orange", 400, 32, 20);
    truck.show();
    cout << "Макс. расстояние: " << truck.maxDistance() << " км" << endl;
    cout << "Себестоимость: " << truck.costPerTonPerKm() << " руб/(т·км)" << endl;
    
    cout << "\n=========================================\n" << endl;
    
    return 0;
}