Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #include <iostream>
- #include <string>
- #include <set>
- #include <map>
- #include <algorithm>
- class Clothing
- {
- public:
- Clothing(string name, int code, int cost) :
- name_(name), ClothingCode_(code), cost_(cost)
- {
- quantity_ = 10;
- }
- bool leftForSale()
- {
- if(quantity_ > 0)
- {
- quantity_--;
- return true;
- }
- return false;
- }
- string name_;
- int ClothingCode_;
- int cost_;
- int quantity_;
- private:
- Clothing();
- };
- void sellClothing(string name, multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
- {
- multimap<string, Clothing*>::iterator it = clothingItemInventory.find(name);
- if(it != clothingItemInventory.end())
- {
- if ((*it->second).leftForSale())
- {
- itemsSold.insert((*it->second).ClothingCode_);
- }
- }
- else
- {
- cout << "This item is out of place : " << name << endl;
- }
- }
- void itemsSoldList(multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
- {
- multimap<string, Clothing*>::iterator it = clothingItemInventory.begin();
- for(it = clothingItemInventory.begin(); it != clothingItemInventory.end(); ++it)
- {
- int soldCount = itemsSold.count((*it->second).ClothingCode_);
- cout<<"Clothing = " << (*it->second).name_ << ", Quantity Sold = " << soldCount << endl;
- }
- }
- int checkSales(multimap<string, Clothing*>& clothingItemInventory, multiset <int> &itemsSold)
- {
- int totalSales = 0;
- multimap<string, Clothing*>::iterator it;
- for(it = clothingItemInventory.begin(); it != clothingItemInventory.end(); ++it)
- {
- int soldCount = itemsSold.count((*it->second).ClothingCode_);
- totalSales += soldCount * (*it->second).cost_;
- }
- return totalSales;
- }
- int main()
- {
- multimap<string, Clothing*> clothingItemInventory;
- Clothing* clothing1 = new Clothing("shirts", 2000, 17);
- Clothing* clothing22 = new Clothing("skirts", 3000, 20);
- Clothing* clothing3 = new Clothing("pants", 4000, 25);
- Clothing* clothing4 = new Clothing("dresses", 5000, 50);
- Clothing* clothing5 = new Clothing("hats", 6000, 15);
- clothingItemInventory.insert(pair<string, Clothing*>("shirts",clothing1));
- clothingItemInventory.insert(pair<string, Clothing*>("skirts",clothing22));
- clothingItemInventory.insert(pair<string, Clothing*>("pants",clothing3));
- clothingItemInventory.insert(pair<string, Clothing*>("dresses",clothing4));
- clothingItemInventory.insert(pair<string, Clothing*>("hats",clothing5));
- multiset <int> itemsSold;
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("shirts", clothingItemInventory, itemsSold);
- sellClothing("skirts", clothingItemInventory, itemsSold);
- sellClothing("bonnets", clothingItemInventory, itemsSold);
- sellClothing("skirts", clothingItemInventory, itemsSold);
- sellClothing("skirts", clothingItemInventory, itemsSold);
- sellClothing("skirts", clothingItemInventory, itemsSold);
- sellClothing("pants", clothingItemInventory, itemsSold);
- sellClothing("pants", clothingItemInventory, itemsSold);
- sellClothing("pants", clothingItemInventory, itemsSold);
- sellClothing("dresses", clothingItemInventory, itemsSold);
- sellClothing("dresses", clothingItemInventory, itemsSold);
- sellClothing("hats", clothingItemInventory, itemsSold);
- itemsSoldList(clothingItemInventory, itemsSold);
- cout<<"Total sales = " << checkSales(clothingItemInventory, itemsSold) << endl;
- delete clothing1;
- delete clothing22;
- delete clothing3;
- delete clothing4;
- delete clothing5;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment