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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
// A starting list of libaries. More could be added if needed.
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
// Global variable declarations
string mainMenu;
const double salesTax = 0.1; // This restaurant has a 10% sales tax
// Parallel arrays to store menu items and prices
string drinks[4], appetizers[4], entrees[5], desserts[3];
double drinkPrices[4], appetizerPrices[4], entreePrices[5], dessertPrices[3];
// Make more parallel arrays below this comment to store a customers order
enum menuType { MAIN, DRINK, APPETIZER, ENTREE, DESSERT };
string chooseDrinks[4], chooseAppetizers[4], chooseEntrees[5], chooseDesserts[3];
double chDrinkPrices[4], chAppPrices[4], chEntreePrices[5], chDessertsPrices[3];
//gets rid of whitespace
const string WHITESPACE = " \n\r\t\f\v|";
string ltrim(const string& s) {
size_t start = s.find_first_not_of(WHITESPACE);
return (start == string::npos) ? "" : s.substr(start);
}
string rtrim(const string& s) {
size_t end = s.find_last_not_of(WHITESPACE);
return (end == string::npos) ? "" : s.substr(0, end + 1);
}
string trim(const string& s) {
return rtrim(ltrim(s));
}
void readMenu(string[]); // Expects an array of strings that are the names of the menu files
void makeOrder();
// Should walk the user through making a payment for their order
void makePayment();
int main() {
// Each file name for the menus
string fNames[] = { "Main.txt", "Drinks.txt", "Appetizers.txt", "Entrees.txt", "Desserts.txt" };
readMenu(fNames); // Read from the files and store info into appropriate arrays
makeOrder(); // Have the user make an order
makePayment(); // Have the user pay for their meal
return 0;
}
void readMenu(string fileNames[]) {
bool done = false;
int counter = 0;
int selection = -1;
menuType curMenu = MAIN;
ifstream iFile;
for (int curMenu = 0; curMenu < 5; ++curMenu) {
iFile.open(fileNames[curMenu]); // Open the file
}
while (!done) {
if (curMenu == MAIN) {
// Read entire Main.txt file and store contents in the mainMenu string
mainMenu.assign(istreambuf_iterator<char>(iFile), istreambuf_iterator<char>());
cout << mainMenu << endl;
cout << "Please enter one of the options above: ";
cin >> selection;
switch (selection) {
case 0:
done = true;
break;
case 1:
curMenu = DRINK;
break;
case 2:
curMenu = APPETIZER;
break;
case 3:
curMenu = ENTREE;
break;
}
}
else if (curMenu == DRINK) {
// Assign values to drinks
if (iFile.is_open()) {
getline(iFile, drinks[selection], '$');
drinks[selection] = trim(drinks[selection]);
iFile >> drinkPrices[selection];
}
cout << drinks << endl;
cout << "Please enter one of the options above: ";
cin >> selection;
switch (selection) {
case 0:
curMenu = MAIN;
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
else if (curMenu == APPETIZER) {
if (iFile.is_open()) {
getline(iFile, appetizers[selection], '$');
appetizers[selection] = trim(appetizers[selection]);
iFile >> appetizerPrices[selection];
}
cout << appetizers << endl;
cout << "Please enter one of the options above: ";
cin >> selection;
switch (selection) {
case 0:
curMenu = MAIN;
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
else if (curMenu == ENTREE) {
if (iFile.is_open()) {
getline(iFile, entrees[selection], '$');
entrees[selection] = trim(entrees[selection]);
iFile >> entreePrices[selection];
}
cout << entrees << endl;
cout << "Please enter one of the options above: ";
cin >> selection;
switch (selection) {
case 0:
curMenu = MAIN;
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
else if (curMenu == DESSERT) {
if (iFile.is_open()) {
getline(iFile, desserts[selection], '$');
desserts[selection] = trim(desserts[selection]);
iFile >> dessertPrices[selection];
}
cout << desserts << endl;
cout << "Please enter one of the options above: ";
cin >> selection;
switch (selection) {
case 0:
curMenu = MAIN;
break;
case 1:
break;
case 2:
break;
case 3:
break;
}
}
system("cls");
}
}
void makeOrder() {
}
void makePayment() {
}
|