Advertisement
muhata84

task3-sales!!!!

Oct 31st, 2019
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. //5
  2. //Sofia beer 1.20 160
  3. //Varna chocolate 2.35 86
  4. //Sofia coffee 0.40 853
  5. //Varna apple 0.86 75.44
  6. //Plovdiv beer 1.10 88
  7. //
  8. //Plovdiv -> 96.80
  9. //Sofia -> 533.20
  10. //Varna -> 266.98
  11.  
  12. #include <iostream>
  13. #include <string>
  14. #include <map>
  15.  
  16. using namespace std;
  17.  
  18. class Sales
  19. {
  20. public:
  21. Sales() = default;
  22.  
  23. void add(string town, string product /*not used*/, double price, double quantity)
  24. {
  25. sales[town] += price * quantity;
  26. }
  27.  
  28. void print() const
  29. {
  30. cout << fixed;
  31. cout.precision(2);
  32. for (const auto& item : sales)
  33. cout << item.first << " -> " << item.second << endl;
  34. }
  35.  
  36. private:
  37. map<string, double> sales;
  38. };
  39.  
  40. int main()
  41. {
  42. Sales s;
  43. string town, product;
  44. double price, quantity;
  45. int n;
  46.  
  47. cin >> n;
  48.  
  49. for (size_t i = 0; i < n; i++)
  50. {
  51. cin >> town >> product >> price >> quantity;
  52. s.add(town, product, price, quantity);
  53. }
  54.  
  55. s.print();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement