Advertisement
istomina_sofia

сложное наследование

Jun 25th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class electronics   //класс электроника (родитель 1)
  7. {
  8.     string name;
  9. public:
  10.     void Setname(string name1)
  11.     {
  12.         name = name1;
  13.     }
  14.     void Getname()
  15.     {
  16.         cout << "Раздел электроники: " << name << endl;
  17.     }
  18. };
  19.  
  20. class zavodsborki  //родитель 2
  21. {
  22.     string a;
  23.     int c;
  24. public:
  25.     void SetA(string a1, int c1)
  26.     {
  27.         a = a1;
  28.         c = c1;
  29.     }
  30.     void GetA()
  31.     {
  32.         cout << "Название завода: " << a << endl;
  33.         cout << "Время сборки: " << c << " часов" << endl;
  34.     }
  35. };
  36.  
  37. class komplect :public electronics  //класс комплектующие (потомок от родителя 1)
  38. {
  39.     string b;
  40. public:
  41.     void SetB(string b1)
  42.     {
  43.         b = b1;
  44.     }
  45.     void GetB()
  46.     {
  47.         cout << "Бренд комплектующих: " << b << endl;
  48.     }
  49. };
  50.  
  51. class computer :public komplect, public zavodsborki  //класс компьютер (потомок родителя 2 и потомка родителя 1)
  52. {
  53.     int d;
  54. public:
  55.     void SetC(int d1)
  56.     {
  57.         d = d1;
  58.     }
  59.     void GetC()
  60.     {
  61.         cout << "Гарантийный срок: " << d << " лет" << endl;
  62.     }
  63. };
  64.  
  65. class ofcomputer :public computer  //класс офисный компьютер
  66. {
  67.     int p;
  68. public:
  69.     void SetD(int p1)
  70.     {
  71.         p = p1;
  72.     }
  73.     void GetD()
  74.     {
  75.         cout << "\nОфисный компьютер : \n";
  76.         cout << "Цена: " << p << " рублей" << endl;
  77.     }
  78. };
  79.  
  80. class gmcomputer :public computer  //класс игровой компьютер
  81. {
  82.     int g;
  83. public:
  84.     void SetG(int g1)
  85.     {
  86.         g = g1;
  87.     }
  88.     void GetG()
  89.     {
  90.         cout << "\nИгровой компьютер : \n";
  91.         cout << "Цена: " << g << " рублей" << endl;
  92.     }
  93. };
  94.  
  95. int main()
  96. {
  97.     setlocale(LC_ALL, "RUS");
  98.     ofcomputer r;
  99.     r.Setname("компьютерная техника");
  100.     r.SetA("Сборгрант", 5);
  101.     r.SetB("Lenovo");
  102.     r.SetD(43999);
  103.     r.Getname();
  104.     r.GetB();
  105.     r.GetA();
  106.     r.GetD();
  107.     gmcomputer v;
  108.     v.SetG(115999);
  109.     v.GetG();
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement