| | |
c++ cashier
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Good day:
My infile contains the following:
The assignment:
You are familiar with computer-driven systems used by cashiers in fast food restaurants. In this
project, you will plan and write a program that will simulate such a point-of-sale device. Here's how
it will work.
When a customer orders, the cashier presses a key for each item ordered (WITHOUT PRESSING
<ENTER>). If more than one of the same item is ordered, the key is pressed an appropriate
number of times. As each key is pressed, the name of the item and its price are displayed on the
next available line on the monitor. Typically, a customer might order a sandwich, then fries or
onion rings and finally, a drink or dessert.
After the customer finishes ordering, a key is pressed to indicate that the order is finished. The
computer at this point displays the amount of the bill, then a 6% sales tax and a total of the order
(amount plus tax). The customer gives the cashier money, the cashier enters the amount given
(tendered). The computer calculates and displays the amount of change that should be returned
to the customer. lf the amount of money tendered is insufficient to cover the total, the program
should alert the cashier to this fact and request re-entry of the tendered amount. The program will
then print the entire order and transaction to the printer so that the customer can have a receipt.
The letters, names and prices of the different menu items must be read in from a file named
"food.txt" and be stored in three parallel arrays and then accessed as needed.
The EQUAL KEY ( = ) will be used as the key to indicate that the order is finished. The items in
the disk file or the arrays must NOT be displayed as a menu on the screen. The following is an
alphabetical list of the food items offered for sales along with their respective key letters and
prices.
On the reverse side is a sample receipt so that you can design your output accordingly. Naturally,
the name of your restaurant should reflect your LAST name and show some IMAGINATION and
ORIGINALITY.
The output is suppose to look like this(as an example):
So far:
Questions:
1. Considering the nature of the infile, how do i go above storing data into the three paralel arrays and what exactly will i be storing in the array from the infile?
2. I guess that once the data is in the array, then when i select a food type, it will automatically come up on the screen until the termination key (in this case '=') is pressed?
Any additional pointers are appreciated.
My infile contains the following:
C++ Syntax (Toggle Plain Text)
U Apple Pie 1.29 A Bacon Burger 3.45 V Burrito 2.09 S Cheeseburger, Double 3.59 W Cheeseburger, Regular 2.95 Y Chicken Nuggets 1.87 H Chicken Sandwich 3.33 C Chili, Bowl 2.12 X Chili Dog 2.29 N Chocolate Milk 0.98 D Coffee 1.09 R Fries, Large 1.89 F Fries, Small 1.19 Q Hamburger 2.45 Z Hot Dog 1.99 T Onion Rings, Large 2.59 G Onion Rings, Small 1.57 J Peach Pie 1.29 I Potato, Baked 1.47 P Salad, Regular 3.69 K Salad, Side 1.95 M Shake, Large 1.98 B Shake, Small 1.49 O Soft Drink, Large 1.69 L Soft Drink, Regular 1.49 E Soft Drink, Small 1.06
You are familiar with computer-driven systems used by cashiers in fast food restaurants. In this
project, you will plan and write a program that will simulate such a point-of-sale device. Here's how
it will work.
When a customer orders, the cashier presses a key for each item ordered (WITHOUT PRESSING
<ENTER>). If more than one of the same item is ordered, the key is pressed an appropriate
number of times. As each key is pressed, the name of the item and its price are displayed on the
next available line on the monitor. Typically, a customer might order a sandwich, then fries or
onion rings and finally, a drink or dessert.
After the customer finishes ordering, a key is pressed to indicate that the order is finished. The
computer at this point displays the amount of the bill, then a 6% sales tax and a total of the order
(amount plus tax). The customer gives the cashier money, the cashier enters the amount given
(tendered). The computer calculates and displays the amount of change that should be returned
to the customer. lf the amount of money tendered is insufficient to cover the total, the program
should alert the cashier to this fact and request re-entry of the tendered amount. The program will
then print the entire order and transaction to the printer so that the customer can have a receipt.
The letters, names and prices of the different menu items must be read in from a file named
"food.txt" and be stored in three parallel arrays and then accessed as needed.
The EQUAL KEY ( = ) will be used as the key to indicate that the order is finished. The items in
the disk file or the arrays must NOT be displayed as a menu on the screen. The following is an
alphabetical list of the food items offered for sales along with their respective key letters and
prices.
C++ Syntax (Toggle Plain Text)
KEY ITEM PRICE U Apple Pie 1.29 Q Hamburger 2.45 A Bacon Burger 3.45 Z Hot Dog 1.99 V Burrito 2.09 T Onion Rings, Large 2.59 S Cheeseburger, Double 3.59 G Onion Rings, Small 1.57 W Cheeseburger, Regular 2.95 J Peach Pie 1.29 Y Chicken Nuggets 1.87 I Potato, Baked 1.47 H Chicken Sandwich 3.33 P Salad, Regular 3.69 C Chili, Bowl 2.12 K Salad, Side 1.95 X Chili Dog 2.29 M Shake, Large 1.98 N Chocolate Milk 0.98 B Shake, Small 1.49 D Coffee 1.09 O Soft Drink, Large 1.89 R Fries, Large 1.89 L Soft Drink, Regular 1 .49 F Fries, Small 1.19 E Soft Drink, Small 1.06
the name of your restaurant should reflect your LAST name and show some IMAGINATION and
ORIGINALITY.
The output is suppose to look like this(as an example):
C++ Syntax (Toggle Plain Text)
Zandiago’s Z-BURGER SHACK Date: Oct 25-07 Time: 18:31:26 Hamburger .............................. 2.45 Salad, Regular ......................... 3.69 Cheeseburger, Regular .................. 2.95 Soft Drink, Regular .................... 1.69 Soft Drink, Small ...................... 1.06 Potato, Baked .......................... 1.47 Fries, Large ........................... 2.59 Apple Pie .............................. 1.29 Onion Rings, Large ..................... 2.59 Chicken Nuggets ........................ 1.87 Amount 20.95 6% Sales Tax 1.26 Total 22.21 Amount Tendered 25.00 Change 2.79 THANK YOU FOR VISITING Zandiago’s ZBURGER SHACK
C++ Syntax (Toggle Plain Text)
#include <iomanip> #include <cmath> #include <fstream> #include<string> #include<iostream> #include<conio> float Tax; float subtotal; float total; float price; using namespace std; /*functions protypes*/ void enterItemPrice(); void subTotal(); void calculatetax(); void totalprice(); void output(); int main() { cout<<"Zandiago's Z-Burger Shack"<<endl; enterItemPrice(); subTotal(); calculatetax(); totalprice(total); output(); return 0; } void enterItemPrice() { while ((targetletter = getch())!='=') } void subTotal() { return subtotal; } void calculatetax() { Tax = subtotal * TaxRate; } void totalprice() { total= Tax + subtotal; } void output() { cout<<item<<endl; cout<<"------------------------------------------"<<endl; cout<<total<<price<<endl; cout<<"6 % Sales Tax"<<Tax<<endl; cout"============================================"<<endl; cout"Total"<<subtotal<<endl; cout<<"Amount tendered"<<cashin<<endl; cout<<"Change"<<(cashin-subtotal)<<endl; cout<<"Thank you for visiting"'\n'; cout<<"Zandiago's Z-Burger Shack"<<endl; }
1. Considering the nature of the infile, how do i go above storing data into the three paralel arrays and what exactly will i be storing in the array from the infile?
2. I guess that once the data is in the array, then when i select a food type, it will automatically come up on the screen until the termination key (in this case '=') is pressed?
Any additional pointers are appreciated.
Last edited by zandiago; Oct 25th, 2007 at 10:26 am.
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
Sequentially read in a char, a string, and a double. The char goes in one array, the string in another and the double in a third. The index of the array and the array name is the key to accessing any one of items in any array. So when the user inputs a V you search the char array until you find V. Then index is then used in the string array to find the name and in the double array to find the cost. Then it's a matter of setting up control structures and counters to allow the user to select as many items in any order they want. It appears that the receipt isn't printed on the run, but only after the = sign has been entered, so you will probably need to keep track of all selections in a separate char array/vector/list and loop through the container once the input is completed.
Thx for your input. So i guess something like this:
If you look at my infile (as show before), how do i get the data from each individual line to be stored in the array?
C++ Syntax (Toggle Plain Text)
myarray[letter][item][cost];
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
Nah, it's something like this:
char itemID[]
string itemName[]
double itemCost[]
If the file to be read in is exactly the one posted then you know the total number of items to be read in so you know the exact size the arrays need to be.
Since the information that goes in each array comes from the file, you will need to oopen the file for reading. Since each item is listed on a separate line you can use a sequence of input statements. In this case you might use a >> followed by a getline() followed by a >>. If you do that however, be sure you ignore the newline left in the input buffer by the >> called just before the call to getline() or you'll get off track.
char itemID[]
string itemName[]
double itemCost[]
If the file to be read in is exactly the one posted then you know the total number of items to be read in so you know the exact size the arrays need to be.
Since the information that goes in each array comes from the file, you will need to oopen the file for reading. Since each item is listed on a separate line you can use a sequence of input statements. In this case you might use a >> followed by a getline() followed by a >>. If you do that however, be sure you ignore the newline left in the input buffer by the >> called just before the call to getline() or you'll get off track.
•
•
•
•
When a customer orders, the cashier presses a key for each item ordered (WITHOUT PRESSING
<ENTER>). If more than one of the same item is ordered, the key is pressed an appropriate
number of times. As each key is pressed, the name of the item and its price are displayed on the
next available line on the monitor....
•
•
•
•
If you look at my infile (as show before), how do i get the data from each individual line to be stored in the array?
Have you considered using a struct or class for each item on the menu?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Good day:
How can i get the info from the infile(one data stored on top of the other) to be stored into the arrays and i have? Thx for your input.
C++ Syntax (Toggle Plain Text)
#include <iomanip> #include <cmath> #include <fstream> #include<string> #include<iostream> #include<conio.h> using namespace std; int main() { ifstream inFile; ofstream outFile; inFile.open ("food.txt"); outFile.open ("foodout"); char letter[30]; string item[30]; double cost[30]; const double taxrate = 0.06; double mealprice, tax, amount_tendered,change, total; inFile>>letter[30]; inFile>>item[30]; inFile>>cost[30]; cout<<letter<<item<<cost<<endl; //calculate tax and total price tax = (mealprice * taxrate); subtotal = mealprice + tax; //Display receipt cout<<endl; cout<<"Zandiago’s Z-BURGER SHACK"<<endl; cout<<"Amount"<<mealprice<<endl; cout<<"6 % Sales Tax"<<tax<<endl; cout"============================================"<<endl; cout"Total"<<total<<endl; cout<<"Amount tendered"<<amount_tendered<<endl; cout<<"Change"<<(amount_tendered-total)<<endl; cout<<"Thank you for visiting"'\n'; cout<<"Zandiago's Z-Burger Shack"<<endl; return 0; }
•
•
Join Date: Jul 2005
Posts: 1,671
Reputation:
Solved Threads: 261
Whenever you want to do the same task over again think of a loop.
Remember that if you declare an array like this:
int x[10];
then accessing an element with any index over 9, like x[10], or under zero, like x[-4], is out of bounds and likely cause problems in one shape or form. This is much less a problem with vectors, which is one reason why they can be easier to use.
Remember that if you declare an array like this:
int x[10];
then accessing an element with any index over 9, like x[10], or under zero, like x[-4], is out of bounds and likely cause problems in one shape or form. This is much less a problem with vectors, which is one reason why they can be easier to use.
•
•
•
•
How can i get the info from the infile(one data stored on top of the other) to be stored into the arrays and i have? Thx for your input.
Defining
char letter[30]; gives you letter[0] thru letter[29], therefore this code C++ Syntax (Toggle Plain Text)
inFile>>letter[30]; inFile>>item[30]; inFile>>cost[30];
You need to put the inputs into a loop, using the loop index from 0 to 29 as the index into the variables.
Also, consider using whitespace for readability. For example
C++ Syntax (Toggle Plain Text)
//Display receipt cout << endl; cout << "Zandiago’s Z-BURGER SHACK" << endl; cout << "Amount" << mealprice << endl; cout << "6 % Sales Tax" << tax << endl; cout << "============================================" << endl; cout << "Total" << total << endl; cout << "Amount tendered" << amount_tendered << endl; cout << "Change" << (amount_tendered-total) << endl; cout << "Thank you for visiting"'\n'; cout << "Zandiago's Z-Burger Shack" << endl;
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Lerner....some some of the posts that i read, i see you're a strong beleiver of using vectors. I had tried to compile a program using DEV C++, in which i used vectors and it didn't compile...but the same program worked in microsoft's visual c++...unfortunately, my professor uses DEV C++ to check all assignments. Thx though for your input & also to you WaltP.
![]() |
Similar Threads
- GetSelectedIndex Datagrid? Dropdownlist (ASP.NET)
- Any recommendations on good Flash books? (Graphics and Multimedia)
- Man arrested for paying with $2 bills at Best Buy (Geeks' Lounge)
- delphi task (Pascal and Delphi)
- DataGrid: Edit mode, the index of a dropdownlist does not start at the right Value (ASP.NET)
- i need ur help (C++)
- GetSelectedIndex Datagrid? Dropdownlist (C#)
- Virgin programmer (Java)
Other Threads in the C++ Forum
- Previous Thread: Help on overload method %
- Next Thread: pointers and multi-dimensional arrays
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






