Advertisement
xeRicker

Untitled

Apr 28th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6. map<int, string> carModels;
  7. map<int, string> carBrands;
  8. map<int, float> carCapacities;
  9. map<int, float> carVelocities;
  10.  
  11. cout << "==============================" << endl;
  12. cout << "CAR DATABASE" << endl;
  13. cout << "==============================" << endl;
  14.  
  15. cout << "How many cars would you like to add?" << endl;
  16. int carAmount; cin >> carAmount;
  17. cout << "Cars to be added: " << carAmount << endl;
  18.  
  19. for (int i = 1; i <= carAmount; i++) {
  20.  
  21. cout << "------------------------------" << endl;
  22. cout << "Car " << i << ": Enter the MODEL" << endl;
  23. if (!(cin)) cin.clear();
  24. string model; cin >> model;
  25.  
  26. cout << "------------------------------" << endl;
  27. cout << "Car " << i << ": Enter the BRAND" << endl;
  28. if (!(cin)) cin.clear();
  29. string brand; cin >> brand;
  30.  
  31. cout << "------------------------------" << endl;
  32. cout << "Car " << i << ": Enter the CAPACITY" << endl;
  33. if (!(cin)) cin.clear();
  34. float capacity; cin >> capacity;
  35.  
  36. cout << "------------------------------" << endl;
  37. cout << "Car " << i << ": Enter the VELOCITY" << endl;
  38. if (!(cin)) cin.clear();
  39. int velocity; cin >> velocity;
  40.  
  41. cout << "------------------------------" << endl;
  42.  
  43. carModels[i] = model;
  44. carBrands[i] = brand;
  45. carCapacities[i] = capacity;
  46. carVelocities[i] = velocity;
  47. cout << "Car " << i << ": "<< model << ", " << brand << ", " << capacity << ", " << velocity << endl;
  48. }
  49.  
  50. while (true) {
  51. cout << "------------------------------" << endl;
  52. cout << "Commands:" << endl;
  53. cout << "getmodel" << endl;
  54. cout << "getbrand" << endl;
  55. cout << "getcapacity" << endl;
  56. cout << "getvelocity" << endl;
  57. cout << "calccapacity" << endl;
  58. cout << "calcvelocity" << endl;
  59. cout << "------------------------------" << endl;
  60. string argument; cin >> argument;
  61.  
  62. if (argument == "getmodel") {
  63. cout << "------------------------------" << endl;
  64. cout << "Please enter the Car ID" << endl;
  65. int carId; cin >> carId;
  66. if (carModels.find(carId) == carModels.end()) {
  67. cout << "Invalid Car ID" << endl;
  68. cout << "------------------------------" << endl;
  69. continue;
  70. }
  71. cout << "Result: " << carModels[carId] << endl;
  72. cout << "------------------------------" << endl;
  73. }
  74.  
  75. if (argument == "getbrand") {
  76. cout << "------------------------------" << endl;
  77. cout << "Please enter the Car ID" << endl;
  78. int carId; cin >> carId;
  79. if (carBrands.find(carId) == carBrands.end()) {
  80. cout << "Invalid Car ID" << endl;
  81. cout << "------------------------------" << endl;
  82. continue;
  83. }
  84. cout << "Result: " << carBrands[carId] << endl;
  85. cout << "------------------------------" << endl;
  86. }
  87.  
  88. if (argument == "getcapacity") {
  89. cout << "------------------------------" << endl;
  90. cout << "Please enter the Car ID" << endl;
  91. int carId; cin >> carId;
  92. if (carCapacities.find(carId) == carCapacities.end()) {
  93. cout << "Invalid Car ID" << endl;
  94. cout << "------------------------------" << endl;
  95. continue;
  96. }
  97. cout << "Result: " << carCapacities[carId] << endl;
  98. cout << "------------------------------" << endl;
  99. }
  100.  
  101. if (argument == "getvelocity") {
  102. cout << "------------------------------" << endl;
  103. cout << "Please enter the Car ID" << endl;
  104. int carId; cin >> carId;
  105. if (carVelocities.find(carId) == carVelocities.end()) {
  106. cout << "Invalid Car ID" << endl;
  107. cout << "------------------------------" << endl;
  108. continue;
  109. }
  110. cout << "Result: " << carVelocities[carId] << endl;
  111. cout << "------------------------------" << endl;
  112. }
  113.  
  114. if (argument == "calccapacity") {
  115. cout << "------------------------------" << endl;
  116. cout << "Please enter the Car ID" << endl;
  117. int car1Id; cin >> car1Id;
  118. if (carCapacities.find(car1Id) == carCapacities.end()) {
  119. cout << "Invalid Car ID" << endl;
  120. cout << "------------------------------" << endl;
  121. continue;
  122. }
  123.  
  124. cout << "Please enter the Car ID" << endl;
  125. int car2Id; cin >> car2Id;
  126. if (carCapacities.find(car2Id) == carCapacities.end()) {
  127. cout << "Invalid Car ID" << endl;
  128. cout << "------------------------------" << endl;
  129. continue;
  130. }
  131.  
  132. float sumCapacity = carCapacities[car1Id] + carCapacities[car2Id];
  133. cout << "Result: " << sumCapacity << endl;
  134. cout << "------------------------------" << endl;
  135. }
  136.  
  137. if (argument == "calcvelocity") {
  138. cout << "------------------------------" << endl;
  139. cout << "Please enter the Car ID" << endl;
  140. int car1Id; cin >> car1Id;
  141. if (carVelocities.find(car1Id) == carVelocities.end()) {
  142. cout << "Invalid Car ID" << endl;
  143. cout << "------------------------------" << endl;
  144. continue;
  145. }
  146.  
  147. cout << "Please enter the Car ID" << endl;
  148. int car2Id; cin >> car2Id;
  149. if (carVelocities.find(car2Id) == carVelocities.end()) {
  150. cout << "Invalid Car ID" << endl;
  151. cout << "------------------------------" << endl;
  152. continue;
  153. }
  154.  
  155. int sumVelocity = carVelocities[car1Id] + carVelocities[car2Id];
  156. int avgVelocity = sumVelocity / 2;
  157. cout << "Result: " << avgVelocity << endl;
  158. cout << "------------------------------" << endl;
  159. }
  160. }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement