Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- struct check_product
- {
- int number;
- std::string name;
- double check_price;
- double check_amount;
- double check_all;
- };
- /*struct check
- {
- int day;
- int month;
- std::vector<check_product> check_p;
- };*/
- struct product
- {
- int articl;
- std::string name;
- double price;
- double amount;
- };
- void print_check(const std::vector<check_product>& list)
- {
- }
- void print_product_list(const std::vector<product>& list)
- {
- for (unsigned i = 0; i < list.size(); ++i)
- {
- std::cout << " articl = " << list[i].articl <<'\n'<<
- " name = " << list[i].name <<'\n'<<
- " price = " << list[i].price <<'\n'<<
- " amount = " << list[i].amount <<'\n'<<
- std::endl;
- }
- }
- int main()
- {
- std::vector<check_product> check_end;
- std::string path = "myfile.txt";
- std::fstream fs;
- fs.open(path); // std::fstream::in | std::fstream::out | std::fstream::app);
- if (!fs.is_open())
- {
- std::cout<< "Error";
- }
- int passwod;
- std::cout<<"Enter a passwod: ";
- std::cin>>passwod;
- if (passwod==160716)
- {
- std::cout<<"All Ok. Go to shopping "<<std::endl;
- std::vector<product> products_list;
- std::string temp_name;
- std::string temp_price, temp_amount, delim;
- std::string temp_articl;
- while (!fs.eof()) // filling struct
- {
- fs >> temp_articl >> temp_name >> temp_price >> temp_amount >> delim;
- products_list.push_back({std::stoi(temp_articl.c_str()), temp_name, std::atof(temp_price.c_str()), std::atof(temp_amount.c_str())});
- }
- std::string paths = "Check.txt";
- std::fstream ft;
- ft.open(paths);
- print_product_list(products_list);
- int sum = 0;
- double temp_amounts;
- while(1)
- {
- int a;
- std::cout<<"If you want to buy a product via category enter 1\n "
- "If you want to pay enter 2\n"
- "If you want to return product enter 3"<<std::endl;
- std::cin>>a;
- switch (a)
- {
- case 1:
- {
- int n=0;
- while(1)
- {
- std::cout<<"Choose the category:\n"
- "1-Fruits and vegetables\n"
- "2-Meat\n"
- "3-Grocery\n"
- "4-Drinks\n"
- "0-Return\n";
- int category;
- std::cin>>category;
- if (category==0) break;
- switch (category)
- {
- case 1:
- {
- for (unsigned i=0; i<12; i++)
- {
- if(products_list[i].articl>10000)
- {
- if(products_list[i].articl<10100)
- {
- std::cout << " articl = " << products_list[i].articl <<'\n'<<
- " name = " << products_list[i].name <<'\n'<<
- " price = " << products_list[i].price <<'\n'<<
- " amount = " << products_list[i].amount <<'\n'<<
- std::endl;
- }
- }
- }
- break;
- }
- case 2:
- {
- for (unsigned i=0; i<12; i++)
- {
- if(products_list[i].articl>20000)
- {
- if(products_list[i].articl<20100)
- {
- std::cout << " articl = " << products_list[i].articl <<'\n'<<
- " name = " << products_list[i].name <<'\n'<<
- " price = " << products_list[i].price <<'\n'<<
- " amount = " << products_list[i].amount <<'\n'<<
- std::endl;
- }
- }
- }
- break;
- }
- case 3:
- {
- for (unsigned i=0; i<12; i++)
- {
- if(products_list[i].articl>30000)
- {
- if(products_list[i].articl<30100)
- {
- std::cout << " articl = " << products_list[i].articl <<'\n'<<
- " name = " << products_list[i].name <<'\n'<<
- " price = " << products_list[i].price <<'\n'<<
- " amount = " << products_list[i].amount <<'\n'<<
- std::endl;
- }
- }
- }
- break;
- }
- case 4:
- {
- for (unsigned i=0; i<12; i++)
- {
- if(products_list[i].articl>40000)
- {
- if(products_list[i].articl<40100)
- {
- std::cout << " articl = " << products_list[i].articl <<'\n'<<
- " name = " << products_list[i].name <<'\n'<<
- " price = " << products_list[i].price <<'\n'<<
- " amount = " << products_list[i].amount <<'\n'<<
- std::endl;
- }
- }
- }
- }
- default:
- break;
- }
- std::cout<<"Entera article of product\n";
- int temp_article;
- std::cin>>temp_article;
- for (unsigned j=0;j<20;j++)
- {
- if(temp_article==products_list[j].articl)
- {
- std::cout << " articl = " << products_list[j].articl <<'\n'<<
- " name = " << products_list[j].name <<'\n'<<
- " price = " << products_list[j].price <<'\n'<<
- " amount = " << products_list[j].amount <<'\n'<<
- std::endl;
- std::cout<<"Choose a amount of product:";
- std::cin >> temp_amounts;
- products_list[j].amount-= temp_amounts;
- sum += temp_amounts*products_list[j].price;
- }
- if(temp_article==products_list[j].articl)
- {
- check_end[n].name=products_list[j].name;
- check_end[n].check_price=products_list[j].price;
- check_end[n].check_amount=products_list[j].amount;
- check_end[n].check_all=products_list[j].price*temp_amounts;
- }
- }
- n++;
- }
- break;
- }
- case 2:
- {
- std::cout<<sum<<std::endl;
- print_check(check_end);
- break;
- }
- case 3:
- {
- break;
- }
- case 4:
- {
- break;
- }
- default:
- std::cout << "k";
- }
- }
- // check228[1].check_p[1].check_all;
- }
- else {std::cout<<"Passwod is not right";}
- fs.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement