Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. class Car{
  7. public:
  8. int price{};
  9. string about{};
  10. Car(){};
  11. virtual int getPrice(){
  12. return price;
  13. }
  14. virtual string getAbout(){
  15. return about;
  16. }
  17. };
  18.  
  19. class Audi : public Car{
  20. public:
  21. Audi(){
  22. price = getPrice() + 200000;
  23. about = getAbout() + "Audi";
  24. }
  25. };
  26.  
  27. class Fiat : public Car{
  28. public:
  29. Fiat(){
  30. price = getPrice() + 5000;
  31. about = getAbout() + "Fiat";
  32. }
  33. };
  34.  
  35. class Decorator : public Car{
  36. public:
  37.  
  38. };
  39.  
  40. class Wheels : public Decorator{
  41. public:
  42. Car *car;
  43. Wheels(Car *c):Decorator(){
  44. car = c;
  45. price = car->getPrice() + 1000;
  46. about = car->getAbout() + " + Wheels";
  47. }
  48. };
  49.  
  50. class Door : public Decorator{
  51. public:
  52. Car *car;
  53. Door(Car *c):Decorator(){
  54. car = c;
  55. price = car->getPrice() + 100;
  56. about = car->getAbout() + " + Door";
  57. }
  58. };
  59.  
  60. int main() {
  61. Car *c1 = new Audi();
  62. cout << c1 -> about << " " << c1 -> price << endl;
  63.  
  64. c1 = new Wheels(c1);
  65. cout << c1 -> about << " " << c1 -> price << endl;
  66.  
  67. c1 = new Door(c1);
  68. cout << c1 -> about << " " << c1 -> price << endl;
  69.  
  70. Car *c2 = new Fiat();
  71. cout << c2 -> about << " " << c2 -> price << endl;
  72.  
  73. c2 = new Wheels(c2);
  74. cout << c2 -> about << " " << c2 -> price << endl;
  75.  
  76. c2 = new Door(c2);
  77. cout << c2 -> about << " " << c2 -> price << endl;
  78.  
  79. c2 = new Door(c2);
  80. cout << c2 -> about << " " << c2 -> price << endl;
  81.  
  82. c2 = new Door(c2);
  83. cout << c2 -> about << " " << c2 -> price << endl;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement