Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Car{
- public:
- int price{};
- string about{};
- Car(){};
- virtual int getPrice(){
- return price;
- }
- virtual string getAbout(){
- return about;
- }
- };
- class Audi : public Car{
- public:
- Audi(){
- price = getPrice() + 200000;
- about = getAbout() + "Audi";
- }
- };
- class Fiat : public Car{
- public:
- Fiat(){
- price = getPrice() + 5000;
- about = getAbout() + "Fiat";
- }
- };
- class Decorator : public Car{
- public:
- };
- class Wheels : public Decorator{
- public:
- Car *car;
- Wheels(Car *c):Decorator(){
- car = c;
- price = car->getPrice() + 1000;
- about = car->getAbout() + " + Wheels";
- }
- };
- class Door : public Decorator{
- public:
- Car *car;
- Door(Car *c):Decorator(){
- car = c;
- price = car->getPrice() + 100;
- about = car->getAbout() + " + Door";
- }
- };
- int main() {
- Car *c1 = new Audi();
- cout << c1 -> about << " " << c1 -> price << endl;
- c1 = new Wheels(c1);
- cout << c1 -> about << " " << c1 -> price << endl;
- c1 = new Door(c1);
- cout << c1 -> about << " " << c1 -> price << endl;
- Car *c2 = new Fiat();
- cout << c2 -> about << " " << c2 -> price << endl;
- c2 = new Wheels(c2);
- cout << c2 -> about << " " << c2 -> price << endl;
- c2 = new Door(c2);
- cout << c2 -> about << " " << c2 -> price << endl;
- c2 = new Door(c2);
- cout << c2 -> about << " " << c2 -> price << endl;
- c2 = new Door(c2);
- cout << c2 -> about << " " << c2 -> price << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement