Advertisement
muhata84

Task 3 – Sales

Oct 30th, 2019
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. void find_first_str(string word, vector<string> & sort_word);
  11.  
  12. class sales
  13. {
  14. private:
  15. ///town, product, price, quantity.
  16. string town;
  17. string product;
  18. double price;
  19. double quantity;
  20. double volume;
  21.  
  22. public:
  23. sales(){}
  24.  
  25. sales(string _town,string _product,double _price , double _quantity):
  26. town(_town),product(_product),price(_price), quantity(_quantity)
  27. {}
  28.  
  29. string & getTown(){return town;}
  30. void setTown(string _town){town = _town;}
  31.  
  32. string & getProduct(){return product;}
  33.  
  34. void setProduct(string _product){product = _product;}
  35.  
  36. double & getPrice(){return price;}
  37. void setPricen(double _price){price = _price;}
  38.  
  39. double & getQuantity(){return quantity;}
  40. void setQuantity(double _quantity){quantity = _quantity;}
  41.  
  42. double & getVolume(){return volume;}
  43. void setVolume(double _volume){volume = _volume;}
  44.  
  45.  
  46. void print(vector<sales> &inputVector,vector<string> & first_town)
  47. {
  48.  
  49. sort(first_town.begin(), first_town.end());
  50.  
  51. for(vector<string>:: iterator itr = first_town.begin(); itr !=first_town.end(); ++itr){
  52. for (vector<sales>::iterator it=inputVector.begin(); it!=inputVector.end(); ++it){
  53.  
  54. if(it->getTown() == (*itr)){
  55. std::cout << std::fixed;
  56. std::cout.precision(2);
  57. std::cout << it->getTown()<<" -> "<< it->getVolume()<<endl;
  58.  
  59. }
  60. }
  61.  
  62. }
  63.  
  64. }
  65.  
  66.  
  67. bool find_town(vector<sales> & inputVector, string city,double volume_){
  68.  
  69. for (vector<sales>::iterator it=inputVector.begin(); it!=inputVector.end(); ++it){
  70. if(it->getTown() == city){
  71. double sum = it->getVolume();
  72. sum +=volume_;
  73. it->setVolume(sum);
  74. return true;
  75. }
  76. }
  77.  
  78. }
  79. ~sales(){}
  80.  
  81. };
  82.  
  83.  
  84. int main()
  85. {
  86. sales sale;
  87.  
  88. vector<sales> vec;
  89. vector<sales> ::iterator it;
  90. int n = 0;
  91. cin>>n;
  92.  
  93. string townIn;
  94. string productIn;
  95. double priceIn;
  96. double quantityIn;
  97. double volume;
  98.  
  99. vector<string> sort_word;
  100.  
  101.  
  102. for(int i =0; i < n; i++){
  103. cin>>townIn;
  104. sale.setTown(townIn);
  105.  
  106. find_first_str(townIn,sort_word);
  107.  
  108.  
  109. cin>>productIn;
  110. sale.setProduct(productIn);
  111. cin>>priceIn;
  112. sale.setPricen(priceIn);
  113. cin>>quantityIn;
  114. sale.setQuantity(quantityIn);
  115. volume = priceIn * quantityIn;
  116. sale.setVolume(volume);
  117.  
  118. bool find_shit = sale.find_town(vec,townIn,volume);
  119. if(!find_shit ){
  120. vec.push_back(sale);
  121. }
  122. }
  123.  
  124. sale.print(vec,sort_word);
  125.  
  126. return 0;
  127. }
  128.  
  129. void find_first_str(string word,vector<string> & sort_word){
  130.  
  131. std::vector<string>::iterator itr = std::find(sort_word.begin(), sort_word.end(), word);
  132. if (itr == sort_word.end()){
  133. sort_word.push_back(word);
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement