Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- class mainClassPlanes { //Main Class
- public:
- mainClassPlanes(const std::string& planeName, const std::string& originCountry, int originYear)
- : planeName(planeName), originCountry(originCountry), originYear(originYear){}
- virtual ~mainClassPlanes() {} //destructor
- virtual void displayInfo() const = 0;
- protected:
- std::string planeName;
- std::string originCountry;
- int originYear;
- };
- class ww2Planes : public mainClassPlanes { //WW2 Class derived from Main Class
- public:
- ww2Planes(const std::string& planeName, const std::string& originCountry, int originYear, const std::string& alliance, int numberBuilt, int planeSeats)
- : alliance(alliance), numberBuilt(numberBuilt), planeSeats(planeSeats), mainClassPlanes(planeName, originCountry, originYear){}
- virtual void displayInfo() const override {
- std::cout << "Plane name: " << planeName << std::endl;
- std::cout << "Country of origin: " << originCountry << std::endl;
- std::cout << "Year of origin: " << originYear << std::endl;
- std::cout << "Alliance: " << alliance << std::endl;
- std::cout << "Number built: " << numberBuilt << std::endl;
- std::cout << "Plane seats: " << planeSeats << std::endl;
- }; //display
- protected:
- std::string alliance;
- int numberBuilt;
- int planeSeats;
- };
- class ww1Planes : public mainClassPlanes { //WW1 Class derived from Main Class
- public:
- ww1Planes(const std::string& planeName, const std::string& originCountry, int originYear, const std::string& alliance, int numberBuilt, float size)
- : alliance(alliance), numberBuilt(numberBuilt), size(size), mainClassPlanes(planeName, originCountry, originYear){}
- virtual void displayInfo() const override {
- std::cout << "Plane name: " << planeName << std::endl;
- std::cout << "Country of origin " << originCountry << std::endl;
- std::cout << "Year of origin: " << originYear << std::endl;
- std::cout << "Alliance: " << alliance << std::endl;
- std::cout << "Number built: " << numberBuilt << std::endl;
- std::cout << "Plane size: " << size << " meters" << std::endl;
- }; //display
- protected:
- std::string alliance;
- int numberBuilt;
- float size;
- };
- int main()
- {
- ww2Planes bf109("Messerschmitt Bf 109", "Nazi Germany", 1937, "Axis", 34248, 2);
- ww2Planes yak9("Yakovlev Yak-9", "Soviet Union", 1942, "Allies", 16769, 1);
- ww1Planes fokkerDVII("Fokker D.VII", "Germany", 1918, "Central Powers", 3300, 6.95);
- ww1Planes bristolF2("Bristol F.2", "United Kingdom", 1916, "Entente Powers", 5329, 7.87);
- std::vector<std::shared_ptr<mainClassPlanes>> planes;
- planes.push_back(std::make_shared<ww2Planes>(bf109));
- planes.push_back(std::make_shared<ww2Planes>(yak9));
- planes.push_back(std::make_shared<ww1Planes>(fokkerDVII));
- planes.push_back(std::make_shared<ww1Planes>(bristolF2));
- for (const auto& mainClassPlanes : planes)
- {
- mainClassPlanes->displayInfo();
- std::cout << "-------------------------------------" << std::endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment