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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void menu();
void fillUp(vector<int> &price, vector<string> &name);
void showModel(vector<int> &selectedPrices, vector<string> selectedOptions, vector<char> &selectedModel);
void selectModel(vector<int> &selectedPrices, vector<char> &selectedModel);
void selectOption(vector<int> &selectedPrices, vector<string> &selectedOptions, vector<int> price, vector<string> name);
void removeOption(vector<int> &selectedPrices, vector<string> &selectedOptions, vector<int> price, vector<string> name);
void displayOption2(vector<int> &price, vector<string> &name);
void cancelOrder(vector<int> &selectedPrices, vector<string> &selectedOptions, vector<char> &selectedModel);
bool check(int &choice, vector<int> &checkNumber);
int main()
{
int choice; // Stores in user choice
vector<int> price; // Stores in the prices of the options/model from the options.txt file
vector<int> selectedPrices; // Stores in the prices from the added options the user has selected
vector<string> name; // Stores in the names of the options from the options.txt file
vector<string> selectedOptions; // Stores in the options' names from the added options the user has selected
vector<char> selectedModel; // Stores the chosen model name from the user
vector<int> checkNumber; // Stores in user inputs for selecting choices in menu
fillUp(price, name); // Load objects from options.txt file
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
// Have user input a choice
while (cin >> choice)
{
cin.ignore();
// First choice
if (choice == 1)
{
// Checks to make sure options were already displayed. Result if user did print out options
if (check(choice, checkNumber) == 1)
{
selectModel(selectedPrices, selectedModel); // Have user select model
cout << endl;
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
}
// Result if user did not print out options
else
{
cout << "Please Display options first" << endl
<< endl; // Prompts user to display options first
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
}
}
// Choice 2
else if (choice == 2)
{
check(choice, checkNumber); // Reads in the user has selected choice 2
cout << endl;
displayOption2(price, name); // Display options and prices
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
}
// Choice 3
else if (choice == 3)
{
// Executes following code if no model is selected
if (selectedModel.empty())
{
cout << "Please select a Model first" << endl
<< endl; // Tells user to first select model
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
}
// Executes following code a model is selected
else
{
selectOption(selectedPrices, selectedOptions, price, name); // Have user add an option
cout << endl;
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Display menu
}
}
// Choice 4
else if (choice == 4)
{
removeOption(selectedPrices, selectedOptions, price, name); // Have user remove option
cout << endl;
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu();
}
// Choice 5
else if (choice == 5)
{
// Executes following code if no model is selected
if (selectedModel.empty())
{
cout << "Please Select a Model first" << endl
<< endl; // Tells user to first select model
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Displays menu
}
// Executes following code a model is selected
else
{
cancelOrder(selectedPrices, selectedOptions, selectedModel); // Cancels order
menu(); // Displays menu
}
}
// Choice 6
else if (choice == 6)
{
cout << "Exiting program..." << endl; // Tells user program is exiting
break; // Breaks out of while loop
}
// Misc input
else
{
cout << "Wrong input, try again" << endl
<< endl; // Tells user to enter a choice again
showModel(selectedPrices, selectedOptions, selectedModel); // Display model, total price, and added options
menu(); // Displays menu
}
}
return 0; // Exits main function, causing the program to close
}
|