loading
open in
main.cpp
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
/*
 Problem:
 Todo's
 Create the following functions:
 1. Function getData: This function loads the data into the array menuList
 2. Function showMenu: This function shows the different items offered by the restaurant and twlls the user how to select the items.
 3. Function printCheck: This function calculates and prints the check. Note: Billing amount shold include a 5% tax
 
 Format requirements: Format your output with two decimal places. The name of each item in the output must be left justified. you may assume that the user selects only one item of a particular type.
 
 ///////
 Algorithm/PseudoCode
 
 In getData function, read data and put it into struct elements of an array
 a. Every element in the array is a datastructure of struc type menuItemType
 
 create restaurant meal (restMeal) datastructure with string (mealName) and int (mealPrice) data types
 //Definition of data structure
 struct menuItemType
 {
 string menuItem;
 double menuPrice;
 
 }
 
 
 /// declaration
 menuItemType menuList
 
 Create 2 arrays (menuitem[] and menuprice[] in the data scructure
 */



//////////////////////////////////////////


#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
using namespace std;



//Structure Definitions
struct menuItemType
{
    
    string menuItem; // menu item name
    double menuPrice; // menu item price
    
    
};

struct chargeType
{
    string chargedItems;
    double chargedPrices;
};


//Function prototype
void getData(menuItemType menuList[], ifstream&);
void showMenu(menuItemType menuList[], chargeType chargelist[], ifstream&, double& orderTotal, int& orderNum);
void printCheck(menuItemType menuList[],chargeType chargeList[], double& orderTotal, int& orderNum);



//Global Variables



//Main Function
int main() {
    
    //Description Header
    cout << "================================================" << endl;
    cout << "Description: Restaurant Project" << endl;
    cout << "Author: Christian Araya" << endl;
    cout << "================================================\n\n\n" << endl;
    
    
    
    //Declarations & Initializations
    menuItemType menuList[8]; //Array with datastructure elements of type menuItemType
    menuItemType menuOrder[8] = {}; //Empty array
    chargeType chargeOrder[] = {};
    double orderTotal = 0;
    int orderNum;
    
    
    // Gen Format
    
    
    
    //Output
    
    
    //Process
    ifstream inFile; //Declare input variable
    inFile.open("input.txt"); // open file
    
    cout << "Welcome to the Rodeo Cafe!\n"
         << "Take a look at our menu\n\n";

    getData(menuOrder, inFile); // Put text file data into data structure
    showMenu(menuOrder, chargeOrder, inFile, orderTotal, orderNum); // Print menu and instructions for the user
    chargeType chargeList[orderNum];
    
    printCheck(menuOrder, chargeOrder, orderTotal, orderNum);
    
    
    
    inFile.close(); // close file
    return 0;
}

//Function Definitions
void getData(menuItemType menuList[], ifstream& inFile)
{
    
    cout << fixed << showpoint << setprecision(2);
    int i = 0;
    char ch;
    while (!inFile.eof())
    {
        getline(inFile, menuList[i].menuItem);
        inFile >> menuList[i].menuPrice;
        inFile.get(ch);
        i++;
    }
}

void showMenu(menuItemType menuList[],chargeType chargeList[], ifstream& inFile, double& orderTotal, int& orderNum)
{
    
    menuItemType array[8] = {};
    getData(array, inFile);
    
    char ch;
    string itemName;
    for (int i = 0; i <= 7; i++)
    {
        cout << setw(15) << left << menuList[i].menuItem;
        cout << setw(10) << right << menuList[i].menuPrice;
        cout << endl;
    }
    cout << endl << endl;
    cout << "Please enter the number of items from the menu that you'd like then press the return key:\n";
    cin >> orderNum;
    cin.get(ch);
    
    cout << "You'd like to place an order for " << orderNum << " item(s)\n\n";
    
    if (orderNum == 0)
    {
        cout << "Thanks for stopping by. Hope to see you next time!";
    }
    else
    {

        
        for (int k = 0; k < orderNum; k++)
        {
            
            cout << "\nPlease enter the name of an item then press the 'return' key to select it:\n\n";
            getline(cin,itemName);
            cout << endl << endl;
            
            
            if (itemName == "Plain Egg")
            {
                orderTotal = orderTotal + menuList[0].menuPrice;
                chargeList[k].chargedItems = menuList[0].menuItem;
                chargeList[k].chargedPrices = menuList[0].menuPrice;
            }
            else if (itemName == "Bacon and Egg")
            {
                orderTotal = orderTotal + menuList[1].menuPrice;
                chargeList[k].chargedItems = menuList[1].menuItem;
                chargeList[k].chargedPrices = menuList[1].menuPrice;
            }
            else if (itemName == "Muffin")
            {
                orderTotal = orderTotal + menuList[2].menuPrice;
                chargeList[k].chargedItems = menuList[2].menuItem;
                chargeList[k].chargedPrices = menuList[2].menuPrice;
            }
            else if (itemName == "French Toast")
            {
                orderTotal = orderTotal + menuList[3].menuPrice;
                chargeList[k].chargedItems = menuList[3].menuItem;
                chargeList[k].chargedPrices = menuList[3].menuPrice;
            }
            else if (itemName == "Fruit Basket")
            {
                orderTotal = orderTotal + menuList[4].menuPrice;
                chargeList[k].chargedItems = menuList[4].menuItem;
                chargeList[k].chargedPrices = menuList[4].menuPrice;
            }
            else if (itemName == "Cereal")
            {
                orderTotal = orderTotal + menuList[5].menuPrice;
                chargeList[k].chargedItems = menuList[5].menuItem;
                chargeList[k].chargedPrices = menuList[5].menuPrice;
            }
            else if (itemName == "Coffee")
            {
                orderTotal = orderTotal + menuList[6].menuPrice;
                chargeList[k].chargedItems = menuList[6].menuItem;
                chargeList[k].chargedPrices = menuList[6].menuPrice;
            }
            else if (itemName == "Tea")
            {
                orderTotal = orderTotal + menuList[7].menuPrice;
                chargeList[k].chargedItems = menuList[7].menuItem;
                chargeList[k].chargedPrices = menuList[7].menuPrice;
            }
            else
            {
                cout << "Item names are case sensitive. Please enter the exact menu item name\n";
                k--;
            }//end else
        }//end for
        
    }//end else
    
}//end showMenu function

void printCheck(menuItemType menuList[], chargeType chargeList[], double& orderTotal, int& orderNum)
{
    cout << "\nThanks for chowing down at the Rodeo Cafe. Come back soon!\n\n";
    for (int m = 0; m < orderNum; m++)
    {
        cout << setw(15) << left << chargeList[m].chargedItems
             << setw(10) << right << "$" << chargeList[m].chargedPrices << endl;
    }
    
    cout << setw(15) << left << "Taxes"
         << setw(10) << right << "$" << orderTotal*.05 << endl;
    
    cout << setw(15) << left << "Amount Due"
    << setw(10) << right << "$" << orderTotal + orderTotal*.05 << endl << endl;
    
}
gcc version 4.6.3