Advertisement
jbonanno

Multiset Clothing Store

Nov 17th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <set>
  8. #include <map>
  9. #include <algorithm>
  10.  
  11.  
  12. class Clothing
  13. {
  14. public:
  15. Clothing(string name, int code, int cost) :
  16.   name_(name), ClothingCode_(code), cost_(cost)
  17.   {
  18.     quantity_ = 10;
  19.     }
  20. bool leftForSale()
  21. {
  22.   if(quantity_ > 0)
  23.   {
  24.     quantity_--;
  25.     return true;
  26.   }
  27.   return false;
  28. }
  29. string name_;
  30. int ClothingCode_;
  31. int cost_;
  32. int quantity_;
  33. private:
  34. Clothing();
  35. };
  36.  
  37. void sellClothing(string name, multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
  38. {
  39. multimap<string, Clothing*>::iterator it = clothingItemInventory.find(name);
  40. if(it != clothingItemInventory.end())
  41. {
  42.   if ((*it->second).leftForSale())
  43.   {
  44.     itemsSold.insert((*it->second).ClothingCode_);
  45.   }
  46. }
  47. else
  48. {
  49.   cout << "This item is out of place : " << name << endl;
  50. }
  51. }
  52.  
  53. void itemsSoldList(multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
  54. {
  55. multimap<string, Clothing*>::iterator it = clothingItemInventory.begin();
  56. for(it = clothingItemInventory.begin(); it != clothingItemInventory.end(); ++it)
  57. {
  58.   int soldCount = itemsSold.count((*it->second).ClothingCode_);
  59.   cout<<"Clothing = " << (*it->second).name_ << ", Quantity Sold = " << soldCount << endl;
  60. }
  61. }
  62.  
  63. int checkSales(multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
  64. {
  65. int totalSales = 0;
  66. multimap<string, Clothing*>::iterator it;
  67. for(it = clothingItemInventory.begin(); it != clothingItemInventory.end(); ++it)
  68. {
  69.   int soldCount = itemsSold.count((*it->second).ClothingCode_);
  70.   totalSales += soldCount * (*it->second).cost_;
  71. }
  72. return totalSales;
  73. }
  74.  
  75. int main()
  76. {
  77.  
  78.   multimap<string, Clothing*> clothingItemInventory;
  79. Clothing* clothing1 = new Clothing("shirts", 2000, 17);
  80. Clothing* clothing22 = new Clothing("skirts", 3000, 20);
  81. Clothing* clothing3 = new Clothing("pants", 4000, 25);
  82. Clothing* clothing4 = new Clothing("dresses", 5000, 50);
  83. Clothing* clothing5 = new Clothing("hats", 6000, 15);
  84. clothingItemInventory.insert(pair<string, Clothing*>("shirts",clothing1));
  85. clothingItemInventory.insert(pair<string, Clothing*>("skirts",clothing22));
  86. clothingItemInventory.insert(pair<string, Clothing*>("pants",clothing3));
  87. clothingItemInventory.insert(pair<string, Clothing*>("dresses",clothing4));
  88. clothingItemInventory.insert(pair<string, Clothing*>("hats",clothing5));
  89.  
  90. multiset <int> itemsSold;
  91.  
  92. sellClothing("shirts", clothingItemInventory, itemsSold);
  93. sellClothing("shirts", clothingItemInventory, itemsSold);
  94. sellClothing("shirts", clothingItemInventory, itemsSold);
  95. sellClothing("shirts", clothingItemInventory, itemsSold);
  96. sellClothing("shirts", clothingItemInventory, itemsSold);
  97. sellClothing("shirts", clothingItemInventory, itemsSold);
  98. sellClothing("shirts", clothingItemInventory, itemsSold);
  99. sellClothing("skirts", clothingItemInventory, itemsSold);
  100. sellClothing("bonnets", clothingItemInventory, itemsSold);
  101. sellClothing("skirts", clothingItemInventory, itemsSold);
  102. sellClothing("skirts", clothingItemInventory, itemsSold);
  103. sellClothing("skirts", clothingItemInventory, itemsSold);
  104. sellClothing("pants", clothingItemInventory, itemsSold);
  105. sellClothing("pants", clothingItemInventory, itemsSold);
  106. sellClothing("pants", clothingItemInventory, itemsSold);
  107. sellClothing("dresses", clothingItemInventory, itemsSold);
  108. sellClothing("dresses", clothingItemInventory, itemsSold);
  109. sellClothing("hats", clothingItemInventory, itemsSold);
  110.  
  111. itemsSoldList(clothingItemInventory, itemsSold);
  112.  
  113. cout<<"Total sales = " << checkSales(clothingItemInventory, itemsSold) << endl;
  114.  
  115. delete clothing1;
  116. delete clothing22;
  117. delete clothing3;
  118. delete clothing4;
  119. delete clothing5;
  120.  
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement