Предмет:
ИнформатикаАвтор:
demetriusОтвет:
#include <iostream>
#include <string>
//set colors(enum)
enum class Color {
RED,
BLUE,
GREEN,
WHITE,
BLACK
};
// Create classes and constructors...
class Car {
protected:
std::string model;
double speed;
Color color;
public:
Car() {
std::cout << "Car default " << this << std::endl;
model = "";
speed = 0.0;
color = Color::WHITE;
}
Car(std::string model, double speed, Color color) {
std::cout << "Car full " << this << std::endl;
this->model = model;
this->speed = speed;
this->color = color;
}
std::string GetModel() const {
return model;
}
double GetSpeed() const {
return speed;
}
Color GetColor() const {
return color;
}
void SetModel(const std::string& model) {
this->model = model;
}
void SetSpeed(double speed) {
this->speed = speed;
}
void SetColor(Color color) {
this->color = color;
}
};
class Truck : public Car {
private:
double cargoVolume;
public:
Truck() : Car() {
std::cout << "Truck default " << this << std::endl;
cargoVolume = 0.0;
}
Truck(std::string model, double speed, Color color, double cargoVolume)
: Car(model, speed, color) {
std::cout << "Truck full " << this << std::endl;
this->cargoVolume = cargoVolume;
}
double GetCargoVolume() const {
return cargoVolume;
}
void SetCargoVolume(double volume) {
cargoVolume = volume;
}
};
//create main function
int main() {
Car car("Mercedes", 160.0, Color::GREEN); //input case
Truck truck("Ford", 80.0, Color::BLACK, 1000.0); //input case
std::cout << "Car model: " << car.GetModel() << ", Speed: " << car.GetSpeed()
<< ", Color: " << static_cast<int>(car.GetColor()) << std::endl;
std::cout << "Truck model: " << truck.GetModel() << ", Speed: " << truck.GetSpeed()
<< ", Color: " << static_cast<int>(truck.GetColor())
<< ", Cargo Volume: " << truck.GetCargoVolume() << std::endl;
return 0;
}
Автор:
oakley2i96Добавить свой ответ
Предмет:
Русский языкАвтор:
cottonОтветов:
Смотреть
Предмет:
Русский языкАвтор:
chaneyОтветов:
Смотреть
Предмет:
Українська літератураАвтор:
giancarloboothОтветов:
Смотреть