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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
|
#include <string>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
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
string drinkOrder[4], appOrder[4], entreeOrder[5], dessertOrder[3];
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[]);
// Will print a specific menu when called
void printMenu(int);
void makeOrder();
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[]) {
int counter = 0;
ifstream iFile;
for (int i = 0; i < 5; ++i) {
iFile.open(fileNames[i]); // Open the file
if (i == 0) {
// Read entire Main.txt file and store contents in the mainMenu string
mainMenu.assign(istreambuf_iterator<char>(iFile), istreambuf_iterator<char>());
}
else {
iFile.ignore(256, '\n');
iFile.ignore(256, '\n');
while (!iFile.eof()) {
if (i == 1) {
// Assign values to drinks
getline(iFile, drinks[counter], '$');
drinks[counter] = trim(drinks[counter]);
iFile >> drinkPrices[counter];
}
else if (i == 2) {
// Assign values to appetizers
getline(iFile, appetizers[counter], '$');
appetizers[counter] = trim(appetizers[counter]);
iFile >> appetizerPrices[counter];
}
else if (i == 3) {
// Assign values to entrees
getline(iFile, entrees[counter], '$');
entrees[counter] = trim(entrees[counter]);
iFile >> entreePrices[counter];
}
else if (i == 4) {
// Assign values to desserts
getline(iFile, desserts[counter], '$');
desserts[counter] = trim(desserts[counter]);
iFile >> dessertPrices[counter];
}
iFile.ignore(256, '\n');
++counter;
}
counter = 0;
}
iFile.close();
}
}
void printMenu(int menu) {
switch (menu) {
case 1:
cout << "Drinks Menu" << endl;
cout << "Please choose an item from the list below." << endl << endl;
cout << "0. Back to Main Menu" << endl;
for (int i = 0; i < 4; ++i) {
cout << i + 1 << ". ";
cout << left << setw(25) << fixed << setprecision(2);
cout << drinks[i] << "$" << drinkPrices[i] << endl;
}
cout << endl;
break;
case 2:
cout << "Appetizers Menu" << endl;
cout << "Please choose an item from the list below." << endl << endl;
cout << "0. Back to Main Menu" << endl;
for (int i = 0; i < 3; ++i) {
cout << i + 1 << ". ";
cout << left << setw(25) << fixed << setprecision(2);
cout << appetizers[i] << "$" << appetizerPrices[i] << endl;
}
cout << endl;
break;
case 3:
cout << "Entrees Menu" << endl;
cout << "Please choose an item from the list below." << endl << endl;
cout << "0. Back to Main Menu" << endl;
for (int i = 0; i < 5; ++i) {
cout << i + 1 << ". ";
cout << left << setw(25) << fixed << setprecision(2);
cout << entrees[i] << "$" << entreePrices[i] << endl;
}
cout << endl;
break;
case 4:
cout << "Desserts Menu" << endl;
cout << "Please choose an item from the list below." << endl << endl;
cout << "0. Back to Main Menu" << endl;
for (int i = 0; i < 3; ++i) {
cout << i + 1 << ". ";
cout << left << setw(25) << fixed << setprecision(2);
cout << desserts[i] << "$" << dessertPrices[i] << endl;
}
cout << endl;
break;
}
}
void makeOrder() {
enum menuType { MAIN, DRINK, APPETIZER, ENTREE, DESSERT };
bool done = false;
int selection = -1;
int quantity;
menuType curMenu = MAIN;
while (!done) {
if (curMenu == MAIN) {
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;
case 4:
curMenu = DESSERT;
break;
}
}
else if (curMenu == DRINK) {
printMenu(1);
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) {
printMenu(2);
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) {
printMenu(3);
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) {
printMenu(4);
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 makePayment() {
}
|