Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.61 KB | None | 0 0
  1. /* Background: You have just opened a small business named “Cool Choices” selling 4 items. Create a menu of choices:
  2.  
  3.   1 Vanilla cone        - $1.35
  4.   2 Lemonade            - $2.25
  5.   3 Bubblegum slush     - $3.15
  6.   4 Yogurt breeze       - $4.05
  7.  
  8. Your program should display the menu of 4 choices. Allow user input for the choice and validate that the user has entered a correct choice. Prompt the user to enter the quantity for this choice and validate that this is a positive number. Calculate the price which includes a sales tax of 8.25%. Display a sales receipt that includes the choice, the price for a single item, the quantity for this item, the total item cost (without tax), the total tax, the total price (including tax) and a “Thanks for your business” type message.
  9.  
  10. Develop functions to perform the tasks. Suggestions for function prototypes:
  11. void DisplayMenu();
  12. int GetChoice();
  13. int GetNumberOfItems(int itemChoice);
  14. double CalculateTotalItemCost(int itemChoice, int numItems);
  15. double CalculateSalesTax(double totalItemCost);
  16. void CreateSalesReceipt(int itemChoice, int numItems,
  17.                         double totalItemCost, double totalTax,
  18.                         double totalPrice);
  19.  
  20. Use global constants for the tax rate and the 4 price choices.
  21.  
  22. Each function definition should include the following documentation:
  23.   Purpose:
  24.   Pre-Condition:
  25.   Post-Condition:
  26.  
  27. For example:
  28. int GetNumberOfItems(int itemChoice)
  29. //Purpose:        To return the quantity that the customer wants to purchase.
  30. //Pre-Condition:  User has selected one menu item.
  31. //Post-Condition: Returns the quantity that the customer wants to purchase
  32. //                of the item selected from the menu.
  33. {
  34.    //declare local variables, if necessary
  35.    int quantity;               //select the quantity for this itemChoice
  36.      . . .
  37.    return quantity;
  38. }
  39.  
  40. */
  41.  
  42. // o also think i need to code for it to output to file, which i bet i can code, just gotta look at notes that filestream bullshit of.stream(fag.txt
  43.  // ios:app)
  44.  
  45. my code;
  46.  
  47.  
  48. #include <iostream>    //cin, cout
  49. #include <iomanip>     //setw, setprecision
  50. using namespace std;
  51.  
  52.  
  53.  
  54.  
  55.  
  56. void DisplayMenu(void);
  57. void GetChoice(int *);
  58. void GetNumberOfItems(int *);
  59. void CalculateTotalItemCost(int, int, double * );
  60. void CalculateSalesTax(double, double * );
  61. void CreateSalesReceipt(int , int , double, double);
  62.                        
  63.  
  64. int main (void)
  65. {
  66.  
  67.  
  68.  int choice, quantity;
  69.  double rate, cost, total, totaltax;
  70.      
  71.      cout << fixed << showpoint << setprecision(2);
  72.  
  73. DisplayMenu ();
  74.        
  75. GetChoice (&choice);
  76. GetNumberOfItems (&quantity);
  77. CalculateTotalItemCost(choice, quantity, &cost);  
  78. CalculateSalesTax(cost, &totaltax);
  79. CreateSalesReceipt(choice, quantity, cost, totaltax);
  80. return 0;    
  81. }
  82.  
  83.  
  84.  
  85.  
  86. void DisplayMenu (void)
  87.  
  88. {
  89.      cout << "PLEASE CHOOSE ONE OF THE FOLLOWING: \n\n" ;
  90.      cout << "1. Vanilla Cone    - $1.35\n" ;
  91.      cout << "2. Lemonade        - $2.25\n" ;
  92.      cout << "3. Bubblegum Slush - $3.15\n" ;
  93.      cout << "4. Yogurt Breeze   - $4.05\n" ;    
  94. }
  95.  
  96. void GetChoice (int *choicePtr)
  97.  
  98. {
  99.      cout << "Please Enter Choice: " ;
  100.      cin >> *choicePtr;
  101.    
  102.      while ((*choicePtr < 1)) || (*choicePtr > 4 ))
  103.  {
  104.  cout << "Invalid Option.\n Please enter choice" ;
  105.  cin >> *choicePtr;
  106.  
  107.  }
  108.      
  109. }
  110.      
  111.  
  112. void GetNumberOfItems (int *quantityPtr)
  113.  
  114. {
  115.     cout << "\nPLEASE ENTER # OF ITEMS: ";
  116.     cin >> *quantityPtr;
  117.     while (*quantityPtr < 1){
  118.         //It said we needed verification,
  119.     cout << "\n invalid selection. Please enter # of items:";
  120.     cin >> *quantityPtr;
  121. }  
  122.  
  123.    
  124.  
  125.  
  126. void CalculateTotalItemCost (int choice, int quantity, double *cost)    
  127. double cost = 0;
  128. {  
  129.        if (choice = 1)
  130.        {
  131.              *cost = 1.35 * quantity ;
  132.        }
  133.  
  134.        if (choice = 2)
  135.        {
  136.              *cost = 2.25 * quantity ;
  137.        }
  138.  
  139.        if (choice = 3)
  140.        {
  141.              *cost = 3.15 * quantity ;
  142.        }
  143.  
  144.        if (choice = 4)
  145.        {
  146.              *cost = 4.05 * quantity ;
  147.        }
  148. }
  149.  
  150.  
  151.  
  152. void CalculateSalesTax(double cost, double *tax){
  153. *tax = cost * .0825;
  154. }
  155.  
  156. void CreateSalesReceipt(int item, int quantity, double cost, double tax){
  157. cout << "\n\nSALES RECIEPT\n";
  158. cout << "ITEM: ";
  159. if (item == 1) {
  160.     cout << "Vanilla Cone\n";}
  161. if else (item == 2) {
  162.     cout << "Lemonade\n";}
  163. if else (item == 3) {
  164.     cout << "Bubble Gum Slush\n";}
  165. else {
  166.     cout << "Yogurt Breeze\n";}
  167. cout << "QUANTITY: "<< quantity ;
  168. cout << "\nPRICE WITHOUT TAX: " << cost ;
  169. cout << "\n\nTAX: " << tax;
  170. cout << "\n-----------------------";
  171. cout << "\nTOTAL: "<< (cost + tax);
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement