Advertisement
Guest User

Untitled

a guest
May 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 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 check_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. std::vector<product> products_list;
  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::string temp_name;
  69. std::string temp_price, temp_amount, delim;
  70. std::string temp_articl;
  71.  
  72.  
  73. while (!fs.eof()) // filling struct
  74. {
  75. fs >> temp_articl >> temp_name >> temp_price >> temp_amount >> delim;
  76. products_list.push_back({std::atoi(temp_articl.c_str()), temp_name, std::atof(temp_price.c_str()), std::atof(temp_amount.c_str())});
  77. }
  78. //std::string paths = "Check.txt";
  79.  
  80. //std::fstream ft;
  81. //ft.open(paths);
  82.  
  83. print_product_list(products_list);
  84. int sum = 0;
  85. double temp_amounts;
  86.  
  87. while(1)
  88. {
  89. int a;
  90.  
  91. std::cout<<"If you want to buy a product via category enter 1\n "
  92. "If you want to pay enter 2\n"
  93. "If you want to return product enter 3"<<std::endl;
  94. std::cin>>a;
  95. switch (a)
  96. {
  97. case 1:
  98. {
  99. double b;
  100. unsigned 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. break;
  186.  
  187. }
  188. default:
  189. {
  190. break;
  191. }
  192. }
  193.  
  194.  
  195. std::cout<<"Entera article of product\n";
  196. int temp_article;
  197. std::cin>>temp_article;
  198. for (unsigned j=0;j<20;j++)
  199. {
  200. if(temp_article==products_list[j].articl)
  201. {
  202. std::cout << " articl = " << products_list[j].articl <<'\n'<<
  203. " name = " << products_list[j].name <<'\n'<<
  204. " price = " << products_list[j].price <<'\n'<<
  205. " amount = " << products_list[j].amount <<'\n'<<
  206. std::endl;
  207. std::cout<<"Choose a amount of product:";
  208. std::cin >> temp_amounts;
  209. products_list[j].amount-= temp_amounts;
  210. sum += temp_amounts*products_list[j].price;
  211.  
  212. }
  213. if(temp_article==products_list[j].articl)
  214. {
  215. check_end[n].check_name=products_list[j].name;
  216. check_end[n].check_price=products_list[j].price;
  217. check_end[n].check_amount=products_list[j].amount;
  218. check_end[n].check_all=products_list[j].price*temp_amounts;
  219. }
  220. }
  221. n++; temp_amounts=0;temp_article=0;category=0;a=0;
  222. }
  223.  
  224. break;
  225. }
  226. case 2:
  227. {
  228. std::cout<<sum<<std::endl;
  229. print_check(check_end);
  230.  
  231. break;
  232. }
  233. case 3:
  234. {
  235.  
  236. break;
  237. }
  238. case 4:
  239. {
  240.  
  241. break;
  242. }
  243. default:
  244. std::cout << "k";
  245. }
  246.  
  247. }
  248.  
  249. }
  250.  
  251. else {std::cout<<"Passwod is not right";}
  252.  
  253.  
  254.  
  255. fs.close();
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement