1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// Main Function
int main()
{
// Declare variables and STL vector
bool cont = true;
vector < Vehicle * > vehicles;
// While loop to check whether program should run
while (cont)
{
// Loop variables
int optionSelect;
int createSelect;
// Ask the user to select a type of vehicle
cout << "- Main Menu -" << endl << endl;
cout << "Please select an option: " << endl << endl;
cout << "0: Bicycle" << endl;
cout << "1: Car" << endl;
cout << "2: Motorcycle" << endl;
cout << "3: Motorhome" << endl;
cout << "4: Train" << endl;
cout << "5: Van" << endl;
cout << "6: Print" << endl << endl;
// Read user selection
cout << "Selection: ";
cin >> optionSelect;
cout << endl;
// Switch statement to create new vehicle objects
switch (optionSelect)
{
case 0:
{
// Create a new Bicycle object and populate it
vehicles.push_back(new Bicycle("", "", 0, 0, 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 1:
{
// Create a new Car object and populate it
vehicles.push_back(new Car("", "", 0, "", "", 0, "", 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 2:
{
// Create a new Motorcycle object and populate it
vehicles.push_back(new Motorcycle("", "", 0, "", "", 0, 0, 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 3:
{
// Create a new Motorhome object and populate it
vehicles.push_back(new Motorhome("", "", 0, "", "", 0, 0, 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 4:
{
// Create a new Train object and populate it
vehicles.push_back(new Train("", "", 0, "", "", 0, 0, 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 5:
{
// Create a new Van object and populate it
vehicles.push_back(new Van("", "", 0, "", "", 0, 0, 0));
vehicles[vehicles.size() -1]->populate();
break;
}
case 6:
{
// Display all vehicles created
for (size_t i = 0; i < vehicles.size(); i++)
{
vehicles[i]->display();
}
}
break;
default:
{
break;
}
}
// Ask the user to create a new vehicle
cout << "Create or Quit?" << endl;
cout << "[1] Create" << endl;
cout << "[0] Quit" << endl << endl;
// Retrieve user input
cout << "Selection: ";
cin >> createSelect;
cout << endl;
// If user selects the option "Quit"
if (createSelect == 0)
{
// Delete objects
for (size_t i = 0; i < vehicles.size(); i++)
{
delete vehicles[i];
}
// Ensure vector has no elements
vector <Vehicle *> vehicles;
// Quit the program
cont = false;
}
}
return 0;
}
|