AlexandrTalchuk

Untitled

Dec 7th, 2020
54
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. while (!(cin >> ValueOfEngine) || (cin.peek() != '\n'))
  76. {
  77. cin.clear();
  78. while (cin.get() != '\n');
  79. cout << "Try again!" << endl;
  80. }
  81. cout << "Enter Count of Cylinders: ";
  82. while (!(cin >> CountOfCylinder) || (cin.peek() != '\n'))
  83. {
  84. cin.clear();
  85. while (cin.get() != '\n');
  86. cout << "Try again!" << endl;
  87. }
  88. }
  89. void getNameAndEngine()
  90. {
  91. cout << "Name of car: " << NameOfCar << endl << "Value of Engine: " << ValueOfEngine << endl << "Count of Cylinders: " << CountOfCylinder << endl;
  92. }
  93.  
  94. void ToStartTheCar() override
  95. {
  96. cout << " 1. To add engine speed" << endl << " 2. Reduce the engine speed" << endl;
  97. cin >> y;
  98. if (y == 1)
  99. {
  100. cout << "Engine speed added, it's time to shift up gear" << endl;
  101. return;
  102. }
  103. else if (y == 2)
  104. {
  105. cout << "Engine speed was reduced, it's time to shift down gear" << endl;
  106. return;
  107. }
  108. else
  109. {
  110. cout << "Try again!" << endl;
  111. cin >> y;
  112. }
  113. }
  114. };
  115.  
  116. class Wheel: public Transmition,public Engine
  117. {
  118. protected:
  119. int SizeOfWheel;
  120. public:
  121. void setTransmitionAndWheels()
  122. {
  123. cout << "Enter name of transmition: ";
  124. cin >> NameOfTransmition;
  125. cout <<"Enter count of Gears: ";
  126. while (!(cin >> CountOfGears) || (cin.peek() != '\n'))
  127. {
  128. cin.clear();
  129. while (cin.get() != '\n');
  130. cout << "Try again!" << endl;
  131. }
  132. cout << "Enter size of wheel: ";
  133. while (!(cin >> SizeOfWheel) || (cin.peek() != '\n'))
  134. {
  135. cin.clear();
  136. while (cin.get() != '\n');
  137. cout << "Try again!" << endl;
  138. }
  139.  
  140. }
  141. void getTransmitionAndWheels()
  142. {
  143. cout << "Name of Transmition: " << NameOfTransmition << endl << "Count of Gears: " << CountOfGears << endl << "Size of Wheels: " << SizeOfWheel << endl;
  144. }
  145.  
  146. void SwitchGears() override
  147. {
  148. if (NumberOfGear >= 0 && NumberOfGear <= 3)
  149. {
  150. cout << "Step on the gas son" << endl;
  151. }
  152. else if (NumberOfGear>3&&NumberOfGear<=5)
  153. {
  154. cout << "You're driver!" << endl;
  155. }
  156. else if (NumberOfGear>=6)
  157. {
  158. cout << "Don't rush brother, mothers need us" << endl;
  159. }
  160.  
  161. }
  162. };
  163.  
  164. void menu()
  165. {
  166. bool f = false;
  167. int k,size;
  168. string name;
  169. cout << "How many cars do you want to enter?"<<endl;
  170. cin >> size;
  171. Wheel* wheel = new Wheel[size];
  172. Car* car = new Car[size];
  173. Engine* engine = new Engine[size];
  174. Transmition* transmition = new Transmition[size];
  175. do
  176. {
  177. cout<<" 1. Enter cars "<<endl<<" 2. View cars"<<endl<<" 3. Joke"<<endl<<" 4. Exit"<< endl;
  178. cin >> k;
  179. switch (k)
  180. {
  181. case 1:
  182. for (int i = 0; i < size; i++)
  183. {
  184. wheel[i].setNameAndEngine();
  185. wheel[i].setTransmitionAndWheels();
  186. cout << endl;
  187. }
  188. Sleep(300);
  189. system("cls");
  190. break;
  191. case 2:
  192. for (int i = 0; i < size; i++)
  193. {
  194. wheel[i].getNameAndEngine();
  195. wheel[i].getTransmitionAndWheels();
  196. cout << endl;
  197. }
  198. Sleep(3000);
  199. system("cls");
  200. break;
  201. case 3:
  202. car->ToStartTheCar();
  203. engine->ToStartTheCar();
  204. car->SwitchGears();
  205. transmition->SwitchGears();
  206. Sleep(5000);
  207. system("cls");
  208. break;
  209. case 4:
  210. f = true;
  211. delete[]wheel;
  212. delete[]car;
  213. delete[]engine;
  214. delete[]transmition;
  215. break;
  216. default:
  217. cout << "Try again!" << endl;
  218. break;
  219. }
  220. } while (!f);
  221. }
  222.  
  223. int main()
  224. {
  225. menu();
  226. }
  227.  
RAW Paste Data