944,066 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 5478
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 25th, 2007
0

c++ cashier

Expand Post »
Good day:
My infile contains the following:
C++ Syntax (Toggle Plain Text)
  1. U
  2. Apple Pie
  3. 1.29
  4. A
  5. Bacon Burger
  6. 3.45
  7. V
  8. Burrito
  9. 2.09
  10. S
  11. Cheeseburger, Double
  12. 3.59
  13. W
  14. Cheeseburger, Regular
  15. 2.95
  16. Y
  17. Chicken Nuggets
  18. 1.87
  19. H
  20. Chicken Sandwich
  21. 3.33
  22. C
  23. Chili, Bowl
  24. 2.12
  25. X
  26. Chili Dog
  27. 2.29
  28. N
  29. Chocolate Milk
  30. 0.98
  31. D
  32. Coffee
  33. 1.09
  34. R
  35. Fries, Large
  36. 1.89
  37. F
  38. Fries, Small
  39. 1.19
  40. Q
  41. Hamburger
  42. 2.45
  43. Z
  44. Hot Dog
  45. 1.99
  46. T
  47. Onion Rings, Large
  48. 2.59
  49. G
  50. Onion Rings, Small
  51. 1.57
  52. J
  53. Peach Pie
  54. 1.29
  55. I
  56. Potato, Baked
  57. 1.47
  58. P
  59. Salad, Regular
  60. 3.69
  61. K
  62. Salad, Side
  63. 1.95
  64. M
  65. Shake, Large
  66. 1.98
  67. B
  68. Shake, Small
  69. 1.49
  70. O
  71. Soft Drink, Large
  72. 1.69
  73. L
  74. Soft Drink, Regular
  75. 1.49
  76. E
  77. Soft Drink, Small
  78. 1.06
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.
C++ Syntax (Toggle Plain Text)
  1. KEY ITEM PRICE
  2. U Apple Pie 1.29
  3. Q Hamburger 2.45
  4. A Bacon Burger 3.45
  5. Z Hot Dog 1.99
  6. V Burrito 2.09
  7. T Onion Rings, Large 2.59
  8. S Cheeseburger, Double 3.59
  9. G Onion Rings, Small 1.57
  10. W Cheeseburger, Regular 2.95
  11. J Peach Pie 1.29
  12. Y Chicken Nuggets 1.87
  13. I Potato, Baked 1.47
  14. H Chicken Sandwich 3.33
  15. P Salad, Regular 3.69
  16. C Chili, Bowl 2.12
  17. K Salad, Side 1.95
  18. X Chili Dog 2.29
  19. M Shake, Large 1.98
  20. N Chocolate Milk 0.98
  21. B Shake, Small 1.49
  22. D Coffee 1.09
  23. O Soft Drink, Large 1.89
  24. R Fries, Large 1.89
  25. L Soft Drink, Regular 1 .49
  26. F Fries, Small 1.19
  27. E Soft Drink, Small 1.06
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):
C++ Syntax (Toggle Plain Text)
  1. Zandiago’s Z-BURGER SHACK
  2. Date: Oct 25-07 Time: 18:31:26
  3. Hamburger .............................. 2.45
  4. Salad, Regular ......................... 3.69
  5. Cheeseburger, Regular .................. 2.95
  6. Soft Drink, Regular .................... 1.69
  7. Soft Drink, Small ...................... 1.06
  8. Potato, Baked .......................... 1.47
  9. Fries, Large ........................... 2.59
  10. Apple Pie .............................. 1.29
  11. Onion Rings, Large ..................... 2.59
  12. Chicken Nuggets ........................ 1.87
  13. Amount 20.95
  14. 6% Sales Tax 1.26
  15. Total 22.21
  16. Amount Tendered 25.00
  17. Change 2.79
  18. THANK YOU FOR VISITING
  19. Zandiago’s ZBURGER SHACK
So far:
C++ Syntax (Toggle Plain Text)
  1. #include <iomanip>
  2. #include <cmath>
  3. #include <fstream>
  4. #include<string>
  5. #include<iostream>
  6. #include<conio>
  7.  
  8.  
  9. float Tax;
  10. float subtotal;
  11. float total;
  12. float price;
  13.  
  14. using namespace std;
  15.  
  16. /*functions protypes*/
  17.  
  18. void enterItemPrice();
  19. void subTotal();
  20. void calculatetax();
  21. void totalprice();
  22. void output();
  23.  
  24. int main()
  25. {
  26. cout<<"Zandiago's Z-Burger Shack"<<endl;
  27.  
  28. enterItemPrice();
  29. subTotal();
  30. calculatetax();
  31. totalprice(total);
  32. output();
  33.  
  34.  
  35. return 0;
  36. }
  37.  
  38. void enterItemPrice()
  39. {
  40. while ((targetletter = getch())!='=')
  41.  
  42. }
  43.  
  44. void subTotal()
  45. {
  46.  
  47. return subtotal;
  48.  
  49. }
  50.  
  51. void calculatetax()
  52. {
  53. Tax = subtotal * TaxRate;
  54. }
  55.  
  56. void totalprice()
  57. {
  58. total= Tax + subtotal;
  59. }
  60.  
  61. void output()
  62. {
  63. cout<<item<<endl;
  64. cout<<"------------------------------------------"<<endl;
  65. cout<<total<<price<<endl;
  66. cout<<"6 % Sales Tax"<<Tax<<endl;
  67. cout"============================================"<<endl;
  68. cout"Total"<<subtotal<<endl;
  69. cout<<"Amount tendered"<<cashin<<endl;
  70. cout<<"Change"<<(cashin-subtotal)<<endl;
  71. cout<<"Thank you for visiting"'\n';
  72. cout<<"Zandiago's Z-Burger Shack"<<endl;
  73. }
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.
Last edited by zandiago; Oct 25th, 2007 at 10:26 am.
Similar Threads
Featured Poster
Reputation Points: 129
Solved Threads: 26
Nearly a Posting Maven
zandiago is offline Offline
2,463 posts
since Jun 2007
Oct 25th, 2007
0

Re: c++ cashier

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Oct 25th, 2007
0

Re: c++ cashier

Thx for your input. So i guess something like this:
C++ Syntax (Toggle Plain Text)
  1. myarray[letter][item][cost];
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?
Featured Poster
Reputation Points: 129
Solved Threads: 26
Nearly a Posting Maven
zandiago is offline Offline
2,463 posts
since Jun 2007
Oct 25th, 2007
0

Re: c++ cashier

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Oct 25th, 2007
0

Re: c++ cashier

Click to Expand / Collapse  Quote originally posted by zandiago ...
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....
Ouch!!! Considering Standard CPP cannot do this, your instuctor is teaching techniques that cannot be used normally in the industry. I don't like this at all.

Click to Expand / Collapse  Quote originally posted by zandiago ...
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?
Read the line and break it up into it's 3 parts. To learn the most, test the line character by character and process each section accordingly.

Have you considered using a struct or class for each item on the menu?
Moderator
Reputation Points: 3281
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Oct 26th, 2007
0

Re: c++ cashier

Thx for the input. Salem, we haven't yet done struct/class, but i'll read up on it to see how i could do it. Let me make some more modifications to see how far we can go. Thx again for the assistance.
Featured Poster
Reputation Points: 129
Solved Threads: 26
Nearly a Posting Maven
zandiago is offline Offline
2,463 posts
since Jun 2007
Oct 26th, 2007
0

Re: c++ cashier

Good day:
C++ Syntax (Toggle Plain Text)
  1. #include <iomanip>
  2. #include <cmath>
  3. #include <fstream>
  4. #include<string>
  5. #include<iostream>
  6. #include<conio.h>
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12. int main()
  13. {
  14.  
  15. ifstream inFile;
  16. ofstream outFile;
  17.  
  18. inFile.open ("food.txt");
  19. outFile.open ("foodout");
  20.  
  21. char letter[30];
  22. string item[30];
  23. double cost[30];
  24.  
  25. const double taxrate = 0.06;
  26. double mealprice, tax, amount_tendered,change, total;
  27.  
  28. inFile>>letter[30];
  29. inFile>>item[30];
  30. inFile>>cost[30];
  31.  
  32. cout<<letter<<item<<cost<<endl;
  33.  
  34. //calculate tax and total price
  35. tax = (mealprice * taxrate);
  36. subtotal = mealprice + tax;
  37.  
  38. //Display receipt
  39. cout<<endl;
  40. cout<<"Zandiago’s Z-BURGER SHACK"<<endl;
  41. cout<<"Amount"<<mealprice<<endl;
  42. cout<<"6 % Sales Tax"<<tax<<endl;
  43. cout"============================================"<<endl;
  44. cout"Total"<<total<<endl;
  45. cout<<"Amount tendered"<<amount_tendered<<endl;
  46. cout<<"Change"<<(amount_tendered-total)<<endl;
  47. cout<<"Thank you for visiting"'\n';
  48. cout<<"Zandiago's Z-Burger Shack"<<endl;
  49.  
  50.  
  51.  
  52. return 0;
  53. }
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.
Featured Poster
Reputation Points: 129
Solved Threads: 26
Nearly a Posting Maven
zandiago is offline Offline
2,463 posts
since Jun 2007
Oct 26th, 2007
0

Re: c++ cashier

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Oct 26th, 2007
0

Re: c++ cashier

Click to Expand / Collapse  Quote originally posted by zandiago ...
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.
You're close.

Defining char letter[30]; gives you letter[0] thru letter[29], therefore this code
C++ Syntax (Toggle Plain Text)
  1. inFile>>letter[30];
  2. inFile>>item[30];
  3. inFile>>cost[30];
reads the first 3 values into the array entries after the array definitions.

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)
  1. //Display receipt
  2. cout << endl;
  3. cout << "Zandiago’s Z-BURGER SHACK" << endl;
  4. cout << "Amount" << mealprice << endl;
  5. cout << "6 % Sales Tax" << tax << endl;
  6. cout << "============================================" << endl;
  7. cout << "Total" << total << endl;
  8. cout << "Amount tendered" << amount_tendered << endl;
  9. cout << "Change" << (amount_tendered-total) << endl;
  10. cout << "Thank you for visiting"'\n';
  11. cout << "Zandiago's Z-Burger Shack" << endl;
Moderator
Reputation Points: 3281
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Oct 26th, 2007
0

Re: c++ cashier

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.
Featured Poster
Reputation Points: 129
Solved Threads: 26
Nearly a Posting Maven
zandiago is offline Offline
2,463 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Error wrapping up Win32 'CreateThread' ( error C3867)
Next Thread in C++ Forum Timeline: Please help. Large integers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC