Advertisement
Guest User

Untitled

a guest
May 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. struct check_product
  7. {
  8. int number;
  9. std::string name;
  10. double check_price;
  11. double check_amount;
  12. double check_all;
  13. };
  14. /*struct check
  15. {
  16. int day;
  17. int month;
  18. std::vector<check_product> check_p;
  19. };*/
  20.  
  21. struct product
  22. {
  23. int articl;
  24. std::string name;
  25. double price;
  26. double amount;
  27. };
  28. void print_check(const std::vector<check_product>& list)
  29. {
  30.  
  31. }
  32.  
  33.  
  34. void print_product_list(const std::vector<product>& list)
  35. {
  36. for (unsigned i = 0; i < list.size(); ++i)
  37. {
  38. std::cout << " articl = " << list[i].articl <<'\n'<<
  39. " name = " << list[i].name <<'\n'<<
  40. " price = " << list[i].price <<'\n'<<
  41. " amount = " << list[i].amount <<'\n'<<
  42. std::endl;
  43. }
  44.  
  45. }
  46.  
  47.  
  48. int main()
  49. {
  50. std::vector<check_product> check_end;
  51.  
  52. std::string path = "myfile.txt";
  53. std::fstream fs;
  54. fs.open(path); // std::fstream::in | std::fstream::out | std::fstream::app);
  55.  
  56. if (!fs.is_open())
  57. {
  58. std::cout<< "Error";
  59. }
  60.  
  61. int passwod;
  62. std::cout<<"Enter a passwod: ";
  63. std::cin>>passwod;
  64.  
  65. if (passwod==160716)
  66. {
  67. std::cout<<"All Ok. Go to shopping "<<std::endl;
  68. std::vector<product> products_list;
  69. std::string temp_name;
  70. std::string temp_price, temp_amount, delim;
  71. std::string temp_articl;
  72.  
  73.  
  74. while (!fs.eof()) // filling struct
  75. {
  76. fs >> temp_articl >> temp_name >> temp_price >> temp_amount >> delim;
  77. products_list.push_back({std::stoi(temp_articl.c_str()), temp_name, std::atof(temp_price.c_str()), std::atof(temp_amount.c_str())});
  78. }
  79. std::string paths = "Check.txt";
  80.  
  81. std::fstream ft;
  82. ft.open(paths);
  83.  
  84. print_product_list(products_list);
  85. int sum = 0;
  86. double temp_amounts;
  87.  
  88. while(1)
  89. {
  90. int a;
  91.  
  92. std::cout<<"If you want to buy a product via category enter 1\n "
  93. "If you want to pay enter 2\n"
  94. "If you want to return product enter 3"<<std::endl;
  95. std::cin>>a;
  96. switch (a)
  97. {
  98. case 1:
  99. {
  100. int n=0;
  101. while(1)
  102. {
  103. std::cout<<"Choose the category:\n"
  104. "1-Fruits and vegetables\n"
  105. "2-Meat\n"
  106. "3-Grocery\n"
  107. "4-Drinks\n"
  108. "0-Return\n";
  109.  
  110. int category;
  111. std::cin>>category;
  112. if (category==0) break;
  113. switch (category)
  114. {
  115. case 1:
  116. {
  117. for (unsigned i=0; i<12; i++)
  118. {
  119. if(products_list[i].articl>10000)
  120. {
  121. if(products_list[i].articl<10100)
  122. {
  123. std::cout << " articl = " << products_list[i].articl <<'\n'<<
  124. " name = " << products_list[i].name <<'\n'<<
  125. " price = " << products_list[i].price <<'\n'<<
  126. " amount = " << products_list[i].amount <<'\n'<<
  127. std::endl;
  128. }
  129. }
  130. }
  131. break;
  132. }
  133. case 2:
  134. {
  135. for (unsigned i=0; i<12; i++)
  136. {
  137. if(products_list[i].articl>20000)
  138. {
  139. if(products_list[i].articl<20100)
  140. {
  141. std::cout << " articl = " << products_list[i].articl <<'\n'<<
  142. " name = " << products_list[i].name <<'\n'<<
  143. " price = " << products_list[i].price <<'\n'<<
  144. " amount = " << products_list[i].amount <<'\n'<<
  145. std::endl;
  146. }
  147. }
  148. }
  149. break;
  150. }
  151. case 3:
  152. {
  153. for (unsigned i=0; i<12; i++)
  154. {
  155. if(products_list[i].articl>30000)
  156. {
  157. if(products_list[i].articl<30100)
  158. {
  159. std::cout << " articl = " << products_list[i].articl <<'\n'<<
  160. " name = " << products_list[i].name <<'\n'<<
  161. " price = " << products_list[i].price <<'\n'<<
  162. " amount = " << products_list[i].amount <<'\n'<<
  163. std::endl;
  164. }
  165. }
  166. }
  167. break;
  168. }
  169. case 4:
  170. {
  171. for (unsigned i=0; i<12; i++)
  172. {
  173. if(products_list[i].articl>40000)
  174. {
  175. if(products_list[i].articl<40100)
  176. {
  177. std::cout << " articl = " << products_list[i].articl <<'\n'<<
  178. " name = " << products_list[i].name <<'\n'<<
  179. " price = " << products_list[i].price <<'\n'<<
  180. " amount = " << products_list[i].amount <<'\n'<<
  181. std::endl;
  182. }
  183. }
  184. }
  185.  
  186. }
  187. default:
  188. break;
  189. }
  190.  
  191.  
  192. std::cout<<"Entera article of product\n";
  193. int temp_article;
  194. std::cin>>temp_article;
  195. for (unsigned j=0;j<20;j++)
  196. {
  197. if(temp_article==products_list[j].articl)
  198. {
  199. std::cout << " articl = " << products_list[j].articl <<'\n'<<
  200. " name = " << products_list[j].name <<'\n'<<
  201. " price = " << products_list[j].price <<'\n'<<
  202. " amount = " << products_list[j].amount <<'\n'<<
  203. std::endl;
  204. std::cout<<"Choose a amount of product:";
  205. std::cin >> temp_amounts;
  206. products_list[j].amount-= temp_amounts;
  207. sum += temp_amounts*products_list[j].price;
  208.  
  209. }
  210. if(temp_article==products_list[j].articl)
  211. {
  212. check_end[n].name=products_list[j].name;
  213. check_end[n].check_price=products_list[j].price;
  214. check_end[n].check_amount=products_list[j].amount;
  215. check_end[n].check_all=products_list[j].price*temp_amounts;
  216. }
  217. }
  218. n++;
  219. }
  220.  
  221. break;
  222. }
  223. case 2:
  224. {
  225. std::cout<<sum<<std::endl;
  226. print_check(check_end);
  227.  
  228. break;
  229. }
  230. case 3:
  231. {
  232.  
  233. break;
  234. }
  235. case 4:
  236. {
  237.  
  238. break;
  239. }
  240. default:
  241. std::cout << "k";
  242. }
  243.  
  244. }
  245. // check228[1].check_p[1].check_all;
  246. }
  247.  
  248. else {std::cout<<"Passwod is not right";}
  249.  
  250.  
  251.  
  252. fs.close();
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement