Advertisement
Guest User

Untitled

a guest
Nov 29th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.76 KB | None | 0 0
  1. /*
  2. Program Name: Ice Cream App
  3. Program Description: Ice Cream App displays lists all types of ice cream treats that our ice cream shop serves.
  4. After the user chooses their ice cream treat they can then choose their extras (size, toppings, etc).
  5. You may search and sort our inventory for readability--and there are several options for receipt delivery.
  6. Thank you for using our ice cream shop application!
  7. Programmer Name: Brandon Jinright
  8. Revision History: Beta Version 0.1
  9. */
  10.  
  11. #include <iostream>
  12. #include <fstream>
  13. #include <string>
  14. #include <iomanip>
  15. #include <stdlib.h>
  16. #include "data.h"
  17.  
  18. using namespace std;
  19.  
  20. //function prototypes
  21. void displayChoices(string*, string*, IceCreamData data, Volume details, Extras customize);
  22. void purchaseItems(string*, string*, IceCreamData data, Volume details, Extras customize);
  23. void customizeItems(IceCreamData data, Volume details, Extras customize);
  24. void searchInventory(IceCreamData data, Volume details, Extras customize);
  25. void sortInventory(IceCreamData data, Volume details, Extras customize);
  26. void printToScreen(IceCreamData data, Volume details, Extras customize);
  27. void printToFile(IceCreamData data, Volume details, Extras customize);
  28. void menu(IceCreamData data, Volume details, Extras customize);
  29.  
  30. int main()
  31. {
  32.     IceCreamData data;
  33.     Volume details;
  34.     Extras customize;
  35.     const int SIZE = 10;
  36.     string item[SIZE];
  37.     string description[SIZE];
  38.  
  39.     fstream inputFile;
  40.     inputFile.open("inventory.txt");
  41.  
  42.     for(int i=0;i<SIZE;i++){
  43.         getline(inputFile, item[i]);
  44.         data.setItemName(item, i);
  45.         getline(inputFile, description[i]);
  46.         data.setDescription(description, i);
  47.     }
  48.  
  49.     string* items = data.getItemName();
  50.     string* descriptions = data.getDescription();
  51.  
  52.     /*for(int x=0;x<SIZE;x++){
  53.         cout<<items[x]<<"\n"<<descriptions[x]<<endl;
  54.     }
  55.     */
  56.     inputFile.close();
  57.  
  58.     menu(data, details, customize);
  59.  
  60.     return 0;
  61. }
  62.  
  63. void displayChoices(string* items, string* descriptions, IceCreamData data, Volume details, Extras customize){
  64.  
  65. const int SIZE = 10;
  66.  
  67. for(int i=0;i<SIZE;i++){
  68.         cout<<i+1<<") "<<items[i]<<"\n"<<descriptions[i]<<endl;
  69.     }
  70. menu(data, details, customize);
  71. }
  72.  
  73. void purchaseItems(string* items, string* descriptions, IceCreamData data, Volume details, Extras customize) {
  74.  
  75. string itemName;
  76. const int SIZE = 10;
  77. int choice;
  78. double cost;
  79.  
  80. for(int i=0;i<SIZE;i++){
  81.     cout<<i+1<<") "<<items[i]<<endl;
  82. }
  83. do{
  84.     cout<<"\nPlease enter selection: ";
  85.     cin>>choice;
  86. } while(choice<1||choice>10);
  87.  
  88. if(choice==1){
  89.     itemName = "Vanilla Delight";
  90.     data.setItemChoice(itemName);
  91. } else if (choice==2){
  92.     itemName = "Ice Cream Sundae";
  93.     data.setItemChoice(itemName);
  94. } else if(choice==3){
  95.     itemName = "Strawberry Shortcake Sundae";
  96.     data.setItemChoice(itemName);
  97. } else if(choice==4){
  98.     itemName = "Brownie Madness";
  99.     data.setItemChoice(itemName);
  100. } else if(choice==5){
  101.     itemName = "Cookie Dough Madness";
  102.     data.setItemChoice(itemName);
  103. } else if(choice==6){
  104.     itemName = "Brownie & Cookie Dough Blast";
  105.     data.setItemChoice(itemName);
  106. } else if(choice==7){
  107.     itemName = "Butter-finger Delight";
  108.     data.setItemChoice(itemName);
  109. } else if(choice==8){
  110.     itemName = "Pecan Pie Madness";
  111.     data.setItemChoice(itemName);
  112. } else if(choice==9){
  113.     itemName = "Banana Split";
  114.     data.setItemChoice(itemName);
  115. } else if(choice==10){
  116.     itemName = "Root-beer Float";
  117.     data.setItemChoice(itemName);
  118. } else {
  119. cout<<"Invalid choice!";
  120. }
  121.  
  122. string item = data.getItemChoice();
  123.  
  124. cout<<"Thank you! You may now customize your "<< item <<".";
  125.  
  126. menu(data, details, customize);
  127. }
  128.  
  129. void customizeItems(IceCreamData data, Volume details, Extras customize) {
  130.  
  131. double treatCost;
  132. int selectionType;
  133. int selectionSize;
  134. int toppingQty;
  135. string type;
  136. string typeSize;
  137. string toppings[5];
  138.  
  139. cout<<"Would you like a cone or a cup?\n";
  140. cout<<"1) Cone\n";
  141. cout<<"2) Cup\n";
  142. cin>>selectionType;
  143.  
  144. if(selectionType==1){
  145.     type = "Cone";
  146.     customize.setType(type);
  147. } else if(selectionType==2){
  148.     type = "Cup";
  149.     customize.setType(type);
  150. }
  151.  
  152. string treatType = customize.getType();
  153.  
  154. cout<<"Which size would you like?\n";
  155. cout<<"1) Small (3 scoops)\n";
  156. cout<<"2) Large (5 scoops)\n";
  157. cin>>selectionSize;
  158.  
  159. if(selectionSize==1){
  160.     typeSize = "Small (3 scoops)";
  161.     details.setSize(typeSize);
  162. } else if(selectionSize==2) {
  163.     typeSize = "Large (5 scoops)";
  164.     details.setSize(typeSize);
  165. }
  166.  
  167. string sizeOfTreat = details.getSize();
  168.  
  169. do{
  170.     cout<<"How many toppings would you like? (up to 5)? ";
  171.     cin>>toppingQty;
  172.     cin.ignore();
  173. } while(toppingQty<1||toppingQty>5);
  174.  
  175. for(int i=0;i<toppingQty;i++){
  176.         cout<<"Topping #"<<i+1<<": ";
  177.         getline(cin, toppings[i]);
  178.         customize.setToppings(toppings, i); //set toppings
  179.     }
  180.  
  181. string* allToppings = customize.getToppings(); //get toppings, returns null value
  182. cout<<allToppings;
  183.  
  184. /*for(int i=0;i<5;i++){
  185.    cout<<toppings[i];
  186. } */
  187.  
  188. menu(data, details, customize);
  189. }
  190.  
  191. void searchInventory(IceCreamData data, Volume details, Extras customize) {
  192. cout<<"\n\nSearching inventory. . .";
  193. main();
  194. }
  195.  
  196. void sortInventory(IceCreamData data, Volume details, Extras customize) {
  197. cout<<"\n\nSorting inventory. . .";
  198. main();
  199. }
  200.  
  201. void printToScreen(IceCreamData data, Volume details, Extras customize) {
  202. cout<<"\n\nPrinting to screen. . .";
  203. main();
  204. }
  205.  
  206. void printToFile(IceCreamData data, Volume details, Extras customize) {
  207. cout<<"\n\nPrinting to file. . .";
  208. main();
  209. }
  210.  
  211. void menu(IceCreamData data, Volume details, Extras customize) {
  212.  
  213.     string* items = data.getItemName();
  214.     string* descriptions = data.getDescription();
  215.  
  216.     int selection;
  217.     const int ONE = 1,
  218.     TWO = 2,
  219.     THREE = 3,
  220.     FOUR = 4,
  221.     FIVE = 5,
  222.     SIX = 6,
  223.     SEVEN = 7,
  224.     EIGHT = 8;
  225.  
  226.     do{
  227.     cout<<"\n\n1. Display Choices of Ice Cream\n";
  228.     cout<<"2. Purchase Ice Cream\n";
  229.     cout<<"3. Customize Ice Cream\n";
  230.     cout<<"4. Search for Item\n";
  231.     cout<<"5. Sort Inventory\n";
  232.     cout<<"6. Print Receipt to screen\n";
  233.     cout<<"7. Print Receipt to file\n";
  234.     cout<<"8. Exit\n\n";
  235.     cout<<"Please enter selection: ";
  236.     cin>>selection;
  237.     } while(selection<1||selection>8);
  238.  
  239.     switch(selection){
  240. case ONE:
  241.     displayChoices(items, descriptions, data, details, customize);
  242.  
  243. case TWO:
  244.     purchaseItems(items, descriptions, data, details, customize);
  245.  
  246. case THREE:
  247.     customizeItems(data, details, customize);
  248.  
  249. case FOUR:
  250.     searchInventory(data, details, customize);
  251.  
  252. case FIVE:
  253.     sortInventory(data, details, customize);
  254.  
  255. case SIX:
  256.     printToScreen(data, details, customize);
  257.  
  258. case SEVEN:
  259.     printToFile(data, details, customize);
  260.  
  261. case EIGHT:
  262.     exit(0);
  263.     }
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement