AlexandrTalchuk

Untitled

Dec 6th, 2020 (edited)
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3. #include<windows.h>
  4. using namespace std;
  5.  
  6. class Car
  7. {
  8. public:
  9.     string NameOfCar;
  10.  
  11.     virtual void ToStartTheCar()
  12.     {
  13.         cout << "Engine is running" << endl;
  14.     }
  15.  
  16.     virtual void SwitchGears()
  17.     {
  18.         cout << "The clutch is squeezed out!" << endl;
  19.     }
  20. };
  21.  
  22. class SuspensionBracket : private Car
  23. {
  24. protected:
  25.     string NameOfSuspensition;
  26. };
  27.  
  28. class Transmition: public Car
  29. {
  30. protected:
  31.     string NameOfTransmition;
  32.     int CountOfGears;
  33.     int NumberOfGear=0;
  34.     int t;
  35. public:
  36.  void SwitchGears() override
  37.     {
  38.         cout << " 1. Shift gear up" << endl << " 2. Shift gear down" << endl << " 3. Shift into reverse" << endl;  
  39.         cin >> t;
  40.         if (t == 1)
  41.         {
  42.             cout << "The transmission switched" << NumberOfGear++ << endl;
  43.         }
  44.         else if (t == 2)
  45.         {
  46.             cout << "The transmission switched" << NumberOfGear-- << endl;
  47.         }
  48.         else if (t == 3)
  49.         {
  50.             cout << "Reverse gear is engaged" << endl;
  51.             NumberOfGear = 0;
  52.         }
  53.         else
  54.         {
  55.             cout << "Try again" << endl;
  56.             cin >> t;
  57.         }
  58.         cout << "Current gear is " << NumberOfGear << endl;
  59.        
  60.     }
  61. };
  62.  
  63. class Engine: public Car
  64. {
  65. protected:
  66.     int ValueOfEngine;
  67.     int CountOfCylinder;
  68.     int y;
  69. public:
  70.     void setNameAndEngine()
  71.     {
  72.         cout << "Enter Name of Car: ";
  73.         cin >> NameOfCar;
  74.         cout << "Enter Value of Engine: ";
  75.         cin >> ValueOfEngine;
  76.         cout << "Enter Count of Cylinders: ";
  77.         cin >> CountOfCylinder;
  78.     }
  79.     void getNameAndEngine()
  80.     {
  81.         cout << "Name of car: " << NameOfCar << endl << "Value of Engine: " << ValueOfEngine << endl << "Count of Cylinders: " << CountOfCylinder << endl;
  82.     }
  83.  
  84.     void ToStartTheCar() override
  85.     {
  86.         cout << " 1. To add engine speed" << endl << " 2. Reduce the engine speed" << endl;
  87.         cin >> y;
  88.         if (y == 1)
  89.         {
  90.             cout << "Engine speed added, it's time to shift up gear" << endl;
  91.             return;
  92.         }
  93.         else if (y == 2)
  94.         {
  95.             cout << "Engine speed was reduced, it's time to shift down gear" << endl;
  96.             return;
  97.         }
  98.         else
  99.         {
  100.             cout << "Try again!" << endl;
  101.             cin >> y;
  102.         }
  103.     }
  104. };
  105.  
  106. class Wheel: public Transmition,public Engine
  107. {
  108. protected:
  109.     int SizeOfWheel;
  110. public:
  111.     void setTransmitionAndWheels()
  112.     {
  113.         cout << "Enter name of transmition: ";
  114.         cin >> NameOfTransmition;
  115.         cout <<"Enter count of Gears: ";
  116.         cin >> CountOfGears;
  117.         cout << "Enter size of wheel: ";
  118.         cin >> SizeOfWheel;
  119.  
  120.     }
  121.     void getTransmitionAndWheels()
  122.     {
  123.         cout << "Name of Transmition: " << NameOfTransmition << endl << "Count of Gears: " << CountOfGears << endl << "Size of Wheels: " << SizeOfWheel << endl;
  124.     }
  125.  
  126.     void  SwitchGears() override                                
  127.     {
  128.         if (NumberOfGear >= 0 && NumberOfGear <= 3)
  129.         {
  130.             cout << "Step on the gas son" << endl;
  131.         }
  132.         else if (NumberOfGear>3&&NumberOfGear<=5)
  133.         {
  134.             cout << "You're driver!" << endl;
  135.         }
  136.         else if (NumberOfGear>=6)
  137.         {
  138.             cout << "Don't rush brother, mothers need us" << endl;
  139.         }
  140.        
  141.     }
  142. };
  143.  
  144. void  menu()
  145. {
  146.     bool f = false;
  147.     int k,size;
  148.     string name;
  149.     cout << "How many cars do you want to enter?"<<endl;
  150.     cin >> size;
  151.     Wheel* wheel = new Wheel[size];
  152.     Car* car = new Car[size];
  153.     Engine* engine = new Engine[size];
  154.     Transmition* transmition = new Transmition[size];
  155.     do
  156.     {
  157.         cout<<" 1. Enter cars "<<endl<<" 2. View cars"<<endl<<" 3. Joke"<<endl<<" 4. Exit"<< endl;
  158.         cin >> k;
  159.         switch (k)
  160.         {
  161.         case 1:
  162.             for (int i = 0; i < size; i++)
  163.             {
  164.                 wheel[i].setNameAndEngine();
  165.                 wheel[i].setTransmitionAndWheels();
  166.                 cout << endl;
  167.             }
  168.             Sleep(300);
  169.             system("cls");
  170.             break;
  171.         case 2:
  172.             for (int i = 0; i < size; i++)
  173.             {
  174.                 wheel[i].getNameAndEngine();
  175.                 wheel[i].getTransmitionAndWheels();
  176.                 cout << endl;
  177.             }
  178.             Sleep(3000);
  179.             system("cls");
  180.             break;
  181.         case 3:
  182.             car->ToStartTheCar();
  183.             engine->ToStartTheCar();
  184.             car->SwitchGears();
  185.             transmition->SwitchGears();
  186.             Sleep(5000);
  187.             system("cls");
  188.             break;
  189.         case 4:
  190.             f = true;
  191.             delete[]wheel;
  192.             delete[]car;
  193.             delete[]engine;
  194.             delete[]transmition;
  195.             break;
  196.         default:
  197.             cout << "Try again!" << endl;
  198.             break;
  199.         }
  200.     } while (!f);
  201. }
  202.  
  203. int main()
  204. {
  205.     menu();
  206. }
  207.  
RAW Paste Data