Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- //void addCar(string, string, int, float, float);
- struct Car {
- string make;
- string model;
- int year;
- int mileage;
- int speed;
- };
- void displayMenu();
- void addCar(vector<Car> &);
- void displayCar(Car);
- int main() {
- vector<Car>collection;
- Car c1 = {"VW", "GTI", 2015, 105000, 0};
- collection.push_back(c1);
- Car c2 = {"Dodge", "Durango", 2011, 1050, 0};
- collection.push_back(c2);
- Car c3 = {"Toyota", "Rav4", 1999, 12000, 0};
- collection.push_back(c3);
- while(true)
- {
- displayMenu();
- cout << "\t> ";
- int entry;
- cin >> entry;
- switch (entry)
- {
- case 1:
- displayCar(c1);
- displayCar(c2);
- displayCar(c3);
- break;
- case 2:
- addCar(collection);
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- return 0;
- default:
- cout << "\t> 1-6 only." << endl;
- }
- }
- return 0;
- }
- void displayMenu() {
- cout << "Select:" << endl;
- cout << "\t[1] Output car collection status" << endl;
- cout << "\t[2] Add a car to the collection" << endl;
- cout << "\t[3] Remove a car from the collection" << endl;
- cout << "\t[4] Accelerate a car" << endl;
- cout << "\t[5] Decelerate a car" << endl;
- cout << "\t[6] Quit" << endl;
- }
- void displayCar(Car c) {
- cout << "\t> " << c.year << " " << c.make << " " << c.model << endl;
- cout << "\t\t> Mileage: " << c.mileage << endl;
- cout << "\t\t> Speed: " << c.speed << endl;
- }
- void addCar(vector<Car> &c) {
- Car c4;
- cout << "\t> Make: ";
- cin >> c4.make;
- cout << "\t> Model: ";
- cin >> c4.model;
- cout << "\t> Year: ";
- cin >> c4.year;
- cout << "\t> Mileage: ";
- cin >> c4.mileage;
- cout << "\t> Speed: ";
- cin >> c4.speed;
- c.push_back(c4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement