Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class mainCarClass {
- public:
- mainCarClass(const string& carModel, int carYearOfManifacture) : carModel(carModel), carYearOfManifacture(carYearOfManifacture) {}
- virtual ~mainCarClass() {}
- virtual void displayInfo() const = 0;
- protected:
- string carModel;
- int carYearOfManifacture;
- };
- class sportsCar : mainCarClass {
- public:
- sportsCar(const string& carModel, int carYearOfManifacture, int horsePower, double price) : mainCarClass(carModel, carYearOfManifacture), horsePower(horsePower), price(price) {}
- virtual void displayInfo() const override {
- cout << "Sports car model: " << carModel << endl;
- cout << "Sports car year of manifacture: " << carYearOfManifacture << endl;
- cout << "Sports car horsepower: " << horsePower << endl;
- cout << "Sports car price: " << price << " USD" << endl;
- cout << endl;
- }
- protected:
- int horsePower;
- double price;
- };
- class classicCar : mainCarClass {
- public:
- classicCar(const string& carModel, int carYearOfManifacture, const string& condition, bool isWorking) : mainCarClass(carModel, carYearOfManifacture), condition(condition), isWorking(isWorking) {}
- virtual void displayInfo() const override {
- cout << "Classic car model: " << carModel << endl;
- cout << "Classic car year of manifacture: " << carYearOfManifacture << endl;
- cout << "Classic car condition: " << condition << endl;
- if (isWorking == true)
- {
- cout << "Classic car " << carModel << " is working" << endl;
- }
- else
- {
- cout << "Classic car " << carModel << "is not working" << endl;
- }
- cout << endl;
- }
- protected:
- string condition;
- bool isWorking;
- };
- int main()
- {
- classicCar chevFleet("Chevrolet Fleetmaster", 1946, "Lightly used", true);
- chevFleet.displayInfo();
- classicCar volkBeetle("Volkswagen Type 1 Beetle", 1938, "Heavily used", false);
- volkBeetle.displayInfo();
- sportsCar porsche911("Porsche 911 GT3 RS", 2022, 518, 184550);
- porsche911.displayInfo();
- sportsCar mcLarenP1("McLaren P1", 2013, 903, 1150000);
- mcLarenP1.displayInfo();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement