Savelyev_Vyacheslav

OOP L3

Aug 1st, 2021 (edited)
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.49 KB | None | 0 0
  1. // ООП_3.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. class Substance
  8. {
  9.     int weight;
  10.     char* name;
  11.     char* type;
  12. public:
  13.     Substance(int _weight, char* _name, char* _type)
  14.     {
  15.         weight = _weight;
  16.         name = _name;
  17.         type = _type;
  18.     }
  19.     void unique_method_Substance()
  20.     {
  21.         cout << "Уникальный метод для класса вещество" << endl;
  22.     }
  23.     void show()
  24.     {
  25.         cout << "Вес: " << weight << endl;
  26.         cout << "название: " << name << endl;
  27.         cout << "тип:" << type << endl;
  28.     }
  29.     virtual ~Substance()
  30.     {
  31.         delete[] type;
  32.         delete[] name;
  33.         cout << "---destruct_Substance---" << endl;
  34.     }
  35. };
  36.  
  37. class Water
  38. {
  39.     int name_volume;
  40. public:
  41.     Water(int Volume)
  42.     {
  43.         name_volume = Volume;
  44.     }
  45.     void unique_method_Water()
  46.     {
  47.         cout << "Уникальный метод для класса вода" << endl;
  48.     }
  49.     void show()
  50.     {
  51.         cout << "Объем воды: " << name_volume << endl;
  52.     }
  53.     virtual ~Water()
  54.     {
  55.         cout << "---destruct_Water---" << endl;
  56.     }
  57. };
  58.  
  59. class Solute : public Substance, public Water
  60. {
  61. public:
  62.     Solute(int _weight, char* _name, char* _type, int Volume) : Substance(_weight, _name, _type), Water(Volume) {};
  63.     void show()
  64.     {
  65.         Substance::show();
  66.         Water::show();
  67.     }
  68.     void unique_method_Solute()
  69.     {
  70.         cout << "Уникальный метод для класса Раствор" << endl;
  71.         unique_method_Substance();
  72.         unique_method_Water();
  73.     }
  74.     ~Solute()
  75.     {
  76.         cout << "---destruct_Solute---" << endl;
  77.     }
  78. };
  79.  
  80. int main()
  81. {
  82.     setlocale(LC_ALL, "Russian");
  83.     int i;
  84.     while (1)
  85.     {
  86.         cout << "Выберите цифру:" << endl;
  87.         cout << "1 - Работа с классом вещество" << endl;
  88.         cout << "2 - Работа с классом вода" << endl;
  89.         cout << "3 - Работа с классом раствор" << endl;
  90.         cout << "4 - Выход" << endl;
  91.         cin >> i;
  92.         switch (i)
  93.         {
  94.         case 1:
  95.         {
  96.             int _weight;
  97.             char* _name = new char[10];
  98.             char* _type = new char[20];
  99.             cout << "Введите вес:" << endl;
  100.             cin >> _weight;
  101.             cout << "Введите название вещества:" << endl;
  102.             cin >> _name;
  103.             cout << "Введите тип вещества:" << endl;
  104.             cin >> _type;
  105.             Substance* class_Substance = new Substance(_weight, _name, _type);
  106.             class_Substance->show();
  107.             class_Substance->unique_method_Substance();
  108.             delete class_Substance;
  109.             break;
  110.         }
  111.         case 2:
  112.         {
  113.             int Volume;
  114.             cout << "Введите объем воды:" << endl;
  115.             cin >> Volume;
  116.             Water* class_Water = new Water(Volume);
  117.             class_Water->show();
  118.             class_Water->unique_method_Water();
  119.             delete class_Water;
  120.             break;
  121.         }
  122.         case 3:
  123.         {
  124.             int _weight;
  125.             char* _name = new char[10];
  126.             int Volume;
  127.             char* _type = new char[20];
  128.             cout << "Введите вес раствора:" << endl;
  129.             cin >> _weight;
  130.             cout << "Введите название раствора:" << endl;
  131.             cin >> _name;
  132.             cout << "Введите тип раствора:" << endl;
  133.             cin >> _type;
  134.             cout << "Введите объем раствора:" << endl;
  135.             cin >> Volume;
  136.             Solute* class_Solute = new Solute(_weight, _name, _type, Volume);
  137.             int n;
  138.             while (1)
  139.             {
  140.                 cout << "Выберите цифру:" << endl;
  141.                 cout << "1 - Работа с методами класса Раствор" << endl;
  142.                 cout << "2 - Работа с методами базовых классов Вода и Вещество" << endl;
  143.                 cout << "3 - Выход" << endl;
  144.                 cin >> n;
  145.                 if (n == 3)
  146.                 {
  147.                     break;
  148.                 }
  149.                 switch (n)
  150.                 {
  151.                 case 1:
  152.                 {
  153.                     class_Solute->show();
  154.                     class_Solute->unique_method_Solute();
  155.                     break;
  156.                 }
  157.                 case 2:
  158.                 {
  159.                     class_Solute->Substance::show();
  160.                     class_Solute->Water::show();
  161.                     class_Solute->unique_method_Substance();
  162.                     class_Solute->unique_method_Water();
  163.                     break;
  164.                 }
  165.                 }
  166.             }
  167.             delete class_Solute;
  168.             break;
  169.  
  170.  
  171.         }
  172.         case 4:return 0;
  173.         }
  174.     }
  175. }
  176.  
  177.  
  178. // Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
  179. // Отладка программы: F5 или меню "Отладка" > "Запустить отладку"
  180.  
  181. // Советы по началу работы
  182. //   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
  183. //   2. В окне Team Explorer можно подключиться к системе управления версиями.
  184. //   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
  185. //   4. В окне "Список ошибок" можно просматривать ошибки.
  186. //   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
  187. //   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.
Add Comment
Please, Sign In to add comment