Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. //void addCar(string, string, int, float, float);
  7.  
  8. struct Car {
  9. string make;
  10. string model;
  11. int year;
  12. int mileage;
  13. int speed;
  14. };
  15.  
  16. void displayMenu();
  17. void addCar(vector<Car> &);
  18. void displayCar(Car);
  19.  
  20. int main() {
  21.  
  22. vector<Car>collection;
  23.  
  24. Car c1 = {"VW", "GTI", 2015, 105000, 0};
  25. collection.push_back(c1);
  26. Car c2 = {"Dodge", "Durango", 2011, 1050, 0};
  27. collection.push_back(c2);
  28. Car c3 = {"Toyota", "Rav4", 1999, 12000, 0};
  29. collection.push_back(c3);
  30.  
  31. while(true)
  32. {
  33. displayMenu();
  34. cout << "\t> ";
  35. int entry;
  36. cin >> entry;
  37. switch (entry)
  38. {
  39. case 1:
  40. displayCar(c1);
  41. displayCar(c2);
  42. displayCar(c3);
  43.  
  44. break;
  45. case 2:
  46. addCar(collection);
  47. break;
  48. case 3:
  49. break;
  50. case 4:
  51. break;
  52. case 5:
  53. break;
  54. case 6:
  55. return 0;
  56. default:
  57. cout << "\t> 1-6 only." << endl;
  58. }
  59. }
  60.  
  61. return 0;
  62. }
  63.  
  64. void displayMenu() {
  65. cout << "Select:" << endl;
  66. cout << "\t[1] Output car collection status" << endl;
  67. cout << "\t[2] Add a car to the collection" << endl;
  68. cout << "\t[3] Remove a car from the collection" << endl;
  69. cout << "\t[4] Accelerate a car" << endl;
  70. cout << "\t[5] Decelerate a car" << endl;
  71. cout << "\t[6] Quit" << endl;
  72. }
  73.  
  74. void displayCar(Car c) {
  75. cout << "\t> " << c.year << " " << c.make << " " << c.model << endl;
  76. cout << "\t\t> Mileage: " << c.mileage << endl;
  77. cout << "\t\t> Speed: " << c.speed << endl;
  78. }
  79.  
  80. void addCar(vector<Car> &c) {
  81. Car c4;
  82. cout << "\t> Make: ";
  83. cin >> c4.make;
  84. cout << "\t> Model: ";
  85. cin >> c4.model;
  86. cout << "\t> Year: ";
  87. cin >> c4.year;
  88. cout << "\t> Mileage: ";
  89. cin >> c4.mileage;
  90. cout << "\t> Speed: ";
  91. cin >> c4.speed;
  92. c.push_back(c4);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement