evcamels

lr-6-4

Nov 23rd, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  lr-6-2
  4. //
  5. //  Created by Nikita Korvyakov on 21.11.2020.
  6. //  Copyright © 2020 Nikita Korvyakov. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <list>
  11. using namespace std;
  12. class product{
  13. public:
  14.     virtual void show() = 0;
  15.     virtual void add() = 0;
  16.     list <string> a;
  17.     list <string> :: iterator i;
  18. };
  19. class detail : public product{
  20. protected:
  21.     void add() override{
  22.         a.push_back("Деталь");
  23.     }
  24.     void show() override{
  25.         for(i = a.begin(); i!=a.end();i++){
  26.             cout << (*i) << endl;
  27.         }
  28.     }
  29. };
  30. class mechanizm : public product{
  31. protected:
  32.     void add() override{
  33.         a.push_back("Механизм");
  34.     }
  35.     void show() override{
  36.      for(i = a.begin(); i!=a.end();i++){
  37.             cout << (*i) << endl;
  38.         }
  39.     }
  40. };
  41. class node : public product{
  42. protected:
  43.     void add() override{
  44.         a.push_back("Узел");
  45.     }
  46.     void show() override{
  47.         for(i = a.begin(); i!=a.end();i++){
  48.             cout << (*i) << endl;
  49.         }
  50.     }
  51. };
  52. class org1{
  53. public:
  54.     void show(product *p){
  55.         p->show();
  56.     }
  57.     void add(product *ad){
  58.         ad->add();
  59.     }
  60. };
  61. int main() {
  62.     detail e;
  63.     mechanizm w;
  64.     node en;
  65.     org1 per;
  66.     cout << "Список продуктов: " << endl;
  67.     per.add(&e);
  68.     per.show(&e);
  69.     per.add(&w);
  70.     per.show(&w);
  71.     per.add(&en);
  72.     per.show(&en);
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment