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
|
/*
* File Name: fantastivaPOS.cpp
* Description: Displays an event driven menu, the subtotal and then the selected items and the total.
*/
// Preprocessor Directives
#include <iostream>
#include <iomanip>
using namespace std;
// Prototype
void displayMenu(string menu[], double price[], int size);
void displaySubTotal(double total, int menuChoice);
int getChoice();
double processMenu(string menu[], double price[], int menuChoice, double total, int selectedOptions[], int counter);
/*
* Name: main()
* Parameters: None.
* Processes:
* Return Value: An integer representing an error code; if the program ends without error, zero
* will be returned to the calling program or operating system.
*/
int main()
{
// Constants and Variables
int menuChoice = 0, counter = 0;
double total = 0.0;
const int SIZE = 5;
int selectedOptions[SIZE] = {0};
string menu[SIZE] = {"Steak and Shake combo","Deluxe Burger combo", "Noodle and Shrimp combo", "Chicken and Rice combo", "Surf n' Turf combo"};
double price[SIZE] = {17.99, 12.99, 11.99, 10.99, 15.99};
// Welcome message
cout << "Welcome to Fantastiva! It's great to see ya!\n";
cout << "\nMay I take your order?\n\n";
// Restaurant Menu
do
{
// Calling functions
displayMenu(menu, price, SIZE);
menuChoice = getChoice();
total = processMenu(menu, price, menuChoice, total, selectedOptions, counter);
displaySubTotal(total, menuChoice);
// Storing selections
selectedOptions[counter] = menuChoice -1;
if(menuChoice !=6)
{
counter++;
}
}
while (menuChoice != 6);
system("pause");
return 0;
}
/*
* Name: displayMenu()
* Parameters: menu[] Retrieves the menu items.
* price[] Retrieves the menu prices.
* size Retrieves the constant value for the size of the array.
* selectedOptions Retrieves the stored input.
* Processes: Display the event driven menu for the restaurant.
* Return Value: Nothing.
*/
void displayMenu(string menu[], double price[], int size)
{
// Output
cout << fixed << setprecision(2);
cout << "\n\t\tMenu\n\n";
for (int i = 0; i < size; i++)
{
cout << i + 1 << ". " << menu[i] << "." << setw(15) << "\t$ " << price[i] << endl;
}
cout << "6. Nothing else. \n";
}
/*
* Name: displaySubTotal()
* Parameters: price[] Retrieves the menu prices.
* size Retrieves the constant value for the size of the array.
* total Retrieves the amount total.
* menuChoice Retrieves the input.
* Processes: Display the event driven menu for the restaurant.
* Return Value: Nothing.
*/
void displaySubTotal(double total, int menuChoice)
{
// Output
if (menuChoice != 6)
{
cout << "\n\tTotal so far: "<< setw(20) << "$ " << total << endl << endl;
}
}
/*
* Name: getChoice()
* Parameters: None.
* Processes: Receives the user's menu selection.
* Return Value: The user's selection from the event driven menu.
*/
int getChoice()
{
// Constants and Variables
int menuChoice = 0;
// Input
cout << "\n\nEnter item: ";
cin >> menuChoice;
return menuChoice;
}
/*
* Name: processMenu()
* Parameters: meu[] Retrieves the menu items.
* price[] Retrieves the menu prices.
* size Retrieves the constant value for the size of the array.
* menuChoice Retrieves the selection the user made from the menu.
* total Retrieves the total amount.
* selectedOptions Retrieves the stored input.
* counter Retrieves the counter to store input.
* Processes: Display the event driven menu for the restaurant.
* Return Value: sumToAdd Returns this value to be calculated in another function.
*/
double processMenu(string menu[], double price[], int menuChoice, double total, int selectedOptions[], int counter)
{
// Constants and Variable
int k = 0;
double sumToAdd = 0.0;
const int SIZE = 5;
// Calculations
switch (menuChoice)
{
case 1:
sumToAdd += price[0];
total = total + sumToAdd;
break;
case 2:
sumToAdd += price[1];
total = total + sumToAdd;
break;
case 3:
sumToAdd += price[2];
total = total + sumToAdd;
break;
case 4:
sumToAdd += price[3];
total = total + sumToAdd;
break;
case 5:
sumToAdd += price[4];
total = total + sumToAdd;
break;
case 6:
// Storing menu selection
selectedOptions[counter] = menuChoice;
// Output
cout << "\nThat's:\t";
for (int k = 0; k < counter; k++)
{
menuChoice = selectedOptions[k];
cout << menu[menuChoice] << "\n\t";
}
cout << "\n\n\tThe total is: " << setw(19) << "\t$ " << total;
cout << "\n\nThank you for choosing Fantastiva! Have a Fantastic day!\n\n";
break;
default:
cout << "\n******************ERROR*********************\n"
<< "* Invalid menu selection. *\n"
<< "********************************************\n\n";
}
return total;
}
|