Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4. using namespace std;
  5. class Transport {
  6. protected:
  7. int capacity;
  8. public:
  9. void getCapacity() {
  10. cout << "Введите грузоподьемность: ";
  11. cin >> capacity;
  12. }
  13. bool find(int a) {
  14. return (capacity <= a);
  15. }
  16. virtual void getData() = 0;
  17. };
  18.  
  19. class Car :public Transport {
  20. private:
  21. string model;
  22. int number, velocity;
  23. public:
  24. void getData() {
  25. cout << "Марка машины: "; cin >> model;
  26. cout << "Номер машины: "; cin >> number;
  27. cout << "Средняя скорость: "; cin >> velocity;
  28. Transport::getCapacity();
  29. cout << endl;
  30. }
  31. void getInfo() {
  32. cout << "Марка: " << model << endl;
  33. cout << "Номер машины: " << number << endl;
  34. cout << "Средняя скорость: " << velocity << endl;
  35. cout << "Грузоподьемность: " << capacity << endl;
  36. cout << endl;
  37. }
  38. };
  39.  
  40. class Motorbike :public Transport {
  41. private:
  42. string model;
  43. int number, velocity, carriage;
  44. public:
  45. void getData() {
  46. cout << "Марка мотоцикла: "; cin >> model;
  47. cout << "Номер мотоцикла: "; cin >> number;
  48. cout << "Средняя скорость: "; cin >> velocity;
  49. cout << "Наличие коляски('1' - есть, '0' - нет): "; cin >> carriage;
  50. switch (carriage) {
  51. case 1: {Transport::getCapacity(); cout << endl;
  52. break; }
  53. case 0: { cout << "Грузоподьемность: 0" << endl;
  54. break; }
  55. default: cout << "Введен неверный символ!";
  56. }
  57. }
  58. };
  59.  
  60. class Truck :public Transport {
  61. private:
  62. string model;
  63. int number, velocity, trailer;
  64. public:
  65. void getData() {
  66. cout << "Марка грузовика: "; cin >> model;
  67. cout << "Номер грузовика: "; cin >> number;
  68. cout << "Средняя скорость: "; cin >> velocity;
  69. cout << "Наличие прицепа('1' - есть, '0' - нет): "; cin >> trailer;
  70. switch (trailer) {
  71. case 1: {Transport::getCapacity();
  72. cout << "Грузоподьемность с прицепом: " << capacity * 2 << endl;
  73. break; }
  74. case 0: { Transport::getCapacity();
  75. break; }
  76. default: cout << "Введен неверный символ!";
  77. }
  78. }
  79. };
  80.  
  81. int main() {
  82. setlocale(LC_ALL, "russian");
  83. SetConsoleCP(1251);
  84. SetConsoleOutputCP(1251);
  85.  
  86. Car * CarBase[20];
  87. int n = 0;
  88. char choice;
  89. cout << "Добавить машину в базу данных(д/н): ";
  90. cin >> choice;
  91. do {
  92. switch (choice) {
  93. case 'д': CarBase[n] = new Car(); break;
  94. case 'н': continue;
  95. default: {cout << "Вы ввели неверный символ!" << endl;
  96. choice = 'д';
  97. continue;
  98. }
  99. }
  100. CarBase[n++]->getData();
  101. cout << " Ввести еще машину (д/н)? ";
  102. cin >> choice;
  103. } while (choice == 'д');
  104.  
  105. Motorbike mtb;
  106. mtb.getData();
  107.  
  108. Truck trck;
  109. trck.getData();
  110.  
  111. int a;
  112. cout << "Введите необходимую грузоподьемность машины: ";
  113. cin >> a;
  114. for (int j = 0; j < n; j++) {
  115. if (CarBase[j]->find(a))
  116. CarBase[j]->getInfo();
  117.  
  118. }
  119.  
  120. system("pause");
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement