Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. class Goods {
  6. public:
  7. int price;
  8. int count;
  9. string name;
  10. string type;
  11. void read() {
  12. cin >> name >> type >> price >> count;
  13. }
  14. int calculatePrice() {
  15. return price * count;
  16. }
  17. void printGood()
  18. {
  19. cout << name << ":" << type << " count:" << count << " price:" << price << endl;
  20. }
  21. };
  22. int main()
  23. {
  24. vector<Goods> vec;
  25. string comm;
  26. int summ=0;
  27. int n;
  28. cin >> n;
  29. for (int i = 0; i < n; i++)
  30. {
  31. cin >> comm;
  32. if (comm == "add")
  33. {
  34. Goods igor;
  35. igor.read();
  36. vec.push_back(igor);
  37. }
  38. else if (comm == "check")
  39. {
  40. cin >> comm;
  41. for (int i = 0; i < vec.size(); i++)
  42. {
  43. if (vec[i].type == comm)
  44. {
  45. summ += vec[i].calculatePrice();
  46. }
  47. }
  48. cout << comm << ":" << summ<<endl;
  49. summ = 0;
  50. }
  51. else if (comm == "all")
  52. {
  53. for (int i = 0; i < vec.size(); i++)
  54. {
  55. vec[i].printGood();
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement