Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. struct custInfo
  8. {
  9. char custName[30];
  10. char custTel[20];
  11. char orderType[20];
  12. char orderMenu[30];
  13. int orderUnit;
  14. char modePurchase;
  15.  
  16. float totalPrice;
  17. } customer[30];
  18.  
  19. void readData(custInfo[], ifstream &);
  20. void calculatePrice(custInfo[]);
  21. void Sales(custInfo[], ofstream &);
  22.  
  23. int main()
  24. {
  25. ifstream read;
  26. read.open("data.txt");
  27.  
  28. if(read.fail())
  29. {
  30. cout << "Unable to open file!";
  31. exit(0);
  32. }
  33.  
  34. ofstream write;
  35. write.open("theSales.txt");
  36.  
  37. if(write.fail())
  38. {
  39. cout << "Unable to open file!";
  40. exit(0);
  41. }
  42.  
  43. readData(customer, read);
  44. read.close();
  45.  
  46. calculatePrice(customer);
  47. Sales(customer, write);
  48. write.close();
  49. }
  50.  
  51. void readData(custInfo customer[], ifstream & read)
  52. {
  53. while(!read.eof())
  54. {
  55. for(int i = 0; i < 30; i++)
  56. {
  57. read >> customer[i].custName;
  58. read >> customer[i].custTel;
  59. read >> customer[i].orderType;
  60. read >> customer[i].orderMenu;
  61. read >> customer[i].orderUnit;
  62. read >> customer[i].modePurchase;
  63. }
  64. }
  65.  
  66. }
  67.  
  68. void calculatePrice(custInfo customer[])
  69. {
  70.  
  71. for(int k = 0; k < 30; k++)
  72. {
  73. if(strcmp(customer[k].orderType, "Broiler") == 0)
  74. {
  75. if(strcmp(customer[k].orderMenu, "salmon") == 0)
  76. {
  77. customer[k].totalPrice = 60.00;
  78. }
  79. else if(strcmp(customer[k].orderMenu, "catfish") == 0)
  80. {
  81. customer[k].totalPrice = 45.00;
  82. }
  83. else if(strcmp(customer[k].orderMenu, "trout") == 0)
  84. {
  85. customer[k].totalPrice = 30.00;
  86. }
  87. }
  88. else if(strcmp(customer[k].orderType, "fryer") == 0)
  89. {
  90. if(strcmp(customer[k].orderMenu, "fish plate") == 0)
  91. {
  92. customer[k].totalPrice = 25.00;
  93. }
  94. else if(strcmp(customer[k].orderMenu, "calamari plate") == 0)
  95. {
  96. customer[k].totalPrice = 35.00;
  97. }
  98. else if(strcmp(customer[k].orderMenu, "fish and chips") == 0)
  99. {
  100. customer[k].totalPrice = 30.00;
  101. }
  102. }
  103.  
  104. if(customer[k].modePurchase == 'R')
  105. {
  106. customer[k].totalPrice = customer[k].totalPrice;
  107. }
  108. else if(customer[k].modePurchase == 'W')
  109. {
  110. customer[k].totalPrice = customer[k].totalPrice - (customer[k].totalPrice * 5/100);
  111. }
  112. }
  113.  
  114. }
  115.  
  116. void Sales(custInfo customer[], ofstream & write)
  117. {
  118.  
  119. for(int i = 0; i < 30; i++)
  120. {
  121. write << customer[i].custName;
  122. write << customer[i].custTel;
  123. write << customer[i].orderType;
  124. write << customer[i].orderMenu;
  125. write << customer[i].orderUnit;
  126. write << customer[i].totalPrice;
  127. }
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement