Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include<iomanip>
  5. using namespace std;
  6.  
  7. const int listSize = 8;
  8. const double theTax = .05;
  9.  
  10. struct menuItemType
  11. {
  12. string menuItem;
  13. double menuPrice;
  14. };
  15.  
  16. void getData(ifstream& inFile, menuItemType mlist[], int menuSize);
  17. void showMenu(menuItemType mlist[], int menuSize);
  18. void makeSlection(menuItemType mList[], int listSize, int cList[][2], int& cListLength);
  19. void printCheck(ofstream& outFile, menuItemType mlist[], int menuSize, int choices[][2], int choiceSize);
  20.  
  21.  
  22. int main()
  23. {
  24.  
  25. menuItemType menu[listSize];
  26. int choiceList[listSize][2];
  27. int choiceListLength;
  28. ifstream inFile;
  29. ofstream outFile;
  30.  
  31. inFile.open("input.txt", ios::in);
  32. outFile.open("output.txt", ios::in);
  33.  
  34. if((!inFile) || (!outFile))
  35. {
  36.  
  37. cout<<" The text file does not exist."<<endl;
  38.  
  39. }
  40. else
  41. {
  42.  
  43.  
  44. getData(inFile, menu, listSize);
  45. showMenu(menu, listSize);
  46. makeSlection(menu, listSize, choiceList, choiceListLength);
  47. printCheck(outFile, menu, listSize, choiceList, choiceListLength);
  48.  
  49. inFile.close();
  50. outFile.close();
  51.  
  52. }
  53.  
  54. system("pause");
  55. return 0;
  56.  
  57. }
  58.  
  59. void getData(ifstream& inFile, menuItemType menu[], int listSize)
  60. {
  61. for (int z = 0; z<listSize; z++)
  62. {
  63. getline(inFile, menu[z].menuItem, '$');
  64. inFile >> menu[z].menuPrice;
  65. inFile.ignore(1000, '\n');
  66. }
  67. }
  68.  
  69. void showMenu(menuItemType mlist[], int listSize)
  70. {
  71. for (int z = 0; z<listSize; z++)
  72. {
  73. cout<<(z+1)<<":"<<left<<setw(5)<<mlist[z].menuItem<<setw(10)<<mlist[z].menuPrice<<endl;
  74. }
  75. }
  76.  
  77. void makeSlection(menuItemType mList[], int listSize, int cList[][2], int& cListLength)
  78. {
  79.  
  80. int selectioNo = 0;
  81. int itemNo;
  82. int nooforder;
  83. char respond;
  84.  
  85. for (int i = 0; i<listSize; i++)
  86. {
  87. cList[i][1] = 0;
  88. }
  89. cout << " You can make up to " << listSize //8
  90. << " different selections:" << endl;
  91. cout << "Do you want to make selection Y/y (yes),N/n (N0):" << endl;
  92. cin >> respond;
  93. cout << endl;
  94.  
  95. while ((respond == 'Y' || respond == 'y') && (cListLength<listSize))
  96. {
  97. cout << "enter Item number:" << endl;
  98. cin >> itemNo;
  99. cout << endl;
  100. cout << "How many Orders:" << endl;
  101. cin >> nooforder;
  102. cList[cListLength][0] = itemNo - 1;
  103. cList[cListLength++][1] += nooforder;
  104. cout << "selection Item (Y/y (yes) , N/y (No):" << endl;
  105. cout << respond;
  106. cout << endl;
  107.  
  108. }
  109.  
  110. }
  111.  
  112. void printCheck(ofstream& outFile, menuItemType mlist[], int menuSize, int choices[][2], int choiceSize)
  113. {
  114.  
  115. double price = 0.0, tax = 0.0, total = 0.0;
  116.  
  117. outFile << "\nWelcome to Some Name Restaurant" << endl;
  118. outFile << "Orders and price:" << endl;
  119. for (int z = 0; z < listSize; z++)
  120. {
  121. outFile << mlist[z].menuItem << "\t" << mlist[z].menuPrice << endl;
  122. }
  123.  
  124. tax = 0.05 * price;
  125. total = tax + price;
  126. outFile << setprecision(2) << fixed;
  127. outFile << "\nTax= $" << tax << endl;
  128. outFile << "Amount Due= $" << total << endl;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement