/
Leonid174
/
susu_cpp_kr5
Обзор
Документация
Войти
/
Leonid174
/
susu_cpp_kr5
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Vehicle.cpp
59 строк
1 KB
Leonid174
init commit
13 май 2026, 19:54
Верифицирован
13 май 2026, 19:54
4de3722
Код
Авторство
О чём код?
#include "Vehicle.h" #include <iostream> int Vehicle::totalPower = 0; Vehicle::Vehicle(int power, int speed, double weight) { this->power = power; this->speed = speed; this->weight = weight; totalPower += power; } Vehicle::~Vehicle() { totalPower -= power; } int Vehicle::getPower() const { return power; } int Vehicle::getSpeed() const { return speed; } double Vehicle::getWeight() const { return weight; } int Vehicle::getTotalPower() { return totalPower; } Car::Car(int power, int speed, double weight, int numDoors) : Vehicle(power, speed, weight) { this->numDoors = numDoors; } void Car::displayInfo() const { std::cout << "Car: power=" << getPower() << ", speed=" << getSpeed() << ", weight=" << getWeight() << ", doors=" << numDoors << std::endl; } double Car::calculateYearlyOwnershipCost() const { return getPower() * 100 + numDoors * 50; } Truck::Truck(int power, int speed, double weight, double loadCapacity) : Vehicle(power, speed, weight) { this->loadCapacity = loadCapacity; } void Truck::displayInfo() const { std::cout << "Truck: power=" << getPower() << ", speed=" << getSpeed() << ", weight=" << getWeight() << ", loadCapacity=" << loadCapacity << std::endl; } double Truck::calculateYearlyOwnershipCost() const { return getPower() * 200 + loadCapacity * 500; }