You are on page 1of 9

#include <iostream>

#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

using namespace std;


class Person{

public: std::string mName;


std::string mProducts;
double mSalary;

Person(){
mProducts = "None";
mSalary = 0;
mName = "";
}
Person(string nume,string produse,double salariu){
mProducts =produse;
mSalary=salariu;
mName=nume;
}
bool operator== (const Person& p)const{
if(mName == p.mName && mSalary == p.mSalary)
return true;
else
return false;
}
bool operator< (const Person& p)const{
if(mName.size() < p.mName.size())
return true;
else
return false;
}
string getName(){
return mName;
}
double getSalary(){
return mSalary;
}
string getProduct(){
return mProducts;
}

};
class Product{

public: std:: string mName;


std:: string mType;
double mPrice;
Product(){
mType = "None";
mPrice = 0;
mName = "";
}
Product(string nume,string tip,double pret){
mName=nume;
mType=tip;
mPrice=pret;
}
bool operator==(const Product& p)const{
if(mName==p.mName && mPrice==p.mPrice)
return true;
else
return false;
}
bool operator<(const Product& p)const{
if(mName.size() < p.mName.size())
return true;
else
return false;
}
string getName(){
return mName;
}

};
class Store{
protected:
string mStoreName;
string mType;
vector<Person> mBuyers;
vector<Product> mProducts;
public:
Store(string nume, string tip){
mStoreName = nume;
mType = tip;
}
virtual void add(const Person& adaugare)=0;
virtual void remove(const Person& stergere)=0;
virtual void addProduct(const Product& adaugare)=0;
virtual void removeProduct(const Product& stergere)=0;

virtual Store* operator+() {


return nullptr;
}
virtual Store* operator-(const Person& p){
return this;
}
string getStoreName()const{
return mStoreName;
}
string getType()const{
return mType;
}
uint16_t getBuyersSize()const{
return mBuyers.size();
}
uint16_t getProductsSize()const{
return mProducts.size();
}
Person getBuyers(uint16_t index)const{
return mBuyers[index];
}
Product getProducts(uint16_t index1)const{
return mProducts[index1];
}
};
class MiniMarket: public Store{
public:
MiniMarket(string nume): Store(nume, "MiniMarket"){
mBuyers.clear();
mProducts.clear();
}
Store* operator+(){
return this;
}
Store* operator-(const Person& persoana){
mBuyers.erase(std::remove(mBuyers.begin(), mBuyers.end(), persoana),
mBuyers.end());
return this;
}
virtual void add(const Person& person){
mBuyers.push_back(person);
}
virtual void remove(const Person& person1){
mBuyers.erase(find(mBuyers.begin(), mBuyers.end(), person1));
}
virtual void addProduct(const Product& produs){
mProducts.push_back(produs);
}
virtual void removeProduct(const Product& produs1){
mProducts.erase(find(mProducts.begin(), mProducts.end(), produs1));
}
};
class Market: public Store {
public:
Market(string nume) : Store(nume, "Market") {
mBuyers.clear();
mProducts.clear();
}
Store* operator+(){
return this;
}
Store* operator-(const Person& persoana) {
mBuyers.erase(std::remove(mBuyers.begin(), mBuyers.end(), persoana),
mBuyers.end());
return this;
}
virtual void add(const Person& person){
mBuyers.push_back(person);
}
virtual void remove(const Person& person1){
mBuyers.erase(find(mBuyers.begin(), mBuyers.end(), person1));
}
virtual void addProduct(const Product& produs){
mProducts.push_back(produs);
}
virtual void removeProduct(const Product& produs1){
mProducts.erase(find(mProducts.begin(), mProducts.end(), produs1));
}
};
class SuperMarket: public Store{
public:
SuperMarket(string nume) : Store(nume, "SuperMarket") {
mBuyers.clear();
mProducts.clear();
}
Store* operator+(){
return this;
}
Store* operator-(const Person& persoana){
mBuyers.erase(std::remove(mBuyers.begin(), mBuyers.end(), persoana),
mBuyers.end());
return this;
}
virtual void add(const Person& person){
mBuyers.push_back(person);
}
virtual void remove(const Person& person1){
mBuyers.erase(find(mBuyers.begin(), mBuyers.end(), person1));
}
virtual void addProduct(const Product& produs){
mProducts.push_back(produs);
}
virtual void removeProduct(const Product& produs1){
mProducts.erase(find(mProducts.begin(), mProducts.end(), produs1));
}
};
class Mall : public Store{
public:
Mall(string nume) : Store(nume, "Mall") {
mBuyers.clear();
mProducts.clear();
}
Store* operator+(){
return this;
}
Store* operator-(const Person& persoana) {
mBuyers.erase(std::remove(mBuyers.begin(), mBuyers.end(), persoana),
mBuyers.end());
return this;
}
virtual void add(const Person& person){
mBuyers.push_back(person);
}
virtual void remove(const Person& person1){
mBuyers.erase(find(mBuyers.begin(), mBuyers.end(), person1));
}
virtual void addProduct(const Product& produs){
mProducts.push_back(produs);
}
virtual void removeProduct(const Product& produs1){
mProducts.erase(find(mProducts.begin(), mProducts.end(), produs1));
}
};
int main() {
vector<Store *> store;
vector<Person *> person;
vector<MiniMarket> minimarket;
vector<Market> market;
vector<SuperMarket> supermarket;
vector<Mall> mall;
string name, product, magazin, tip, command, mag_pers;
double salariu, pret, suma = 0, nr_mini = 0, nr_market = 0, nr_super = 0,
nr_mall = 0;
int ok = 0, x = 0;
while (cin >> command) {
if (command == "add") {
cin >> mag_pers;
if (mag_pers == "MiniMarket") {
cin >> name;
store.push_back(new MiniMarket(name));
nr_mini++;
}
if (mag_pers == "Market") {
cin >> name;
store.push_back(new Market(name));
nr_market++;
}
if (mag_pers == "SuperMarket") {
cin >> name;
store.push_back(new SuperMarket(name));
nr_super++;
}
if (mag_pers == "Mall") {
cin >> name;
store.push_back(new Mall(name));
nr_mall++;
}
if (mag_pers == "buyer") {
cin >> name >> product >> salariu;
person.push_back(new Person(name, product, salariu));
if (salariu < 500) {
for (int i = 0; i < store.size(); i++)
if (store[i]->getType() == "MiniMarket") {
store[i]->add(Person(name, product, salariu));
}
}
if (salariu >= 500 && salariu <1000) {
for (int i = 0; i < store.size(); i++)
if (store[i]->getType() == "Market") {
store[i]->add(Person(name, product, salariu));
ok++;
}
}
if (salariu >= 1000 && salariu < 2000) {
for (int i = 0; i < store.size(); i++)
if (store[i]->getType() == "SuperMarket") {
store[i]->add(Person(name, product, salariu));
ok++;
}
}
if (salariu >= 2000) {
for (int i = 0; i < store.size(); i++)
if (store[i]->getType() == "Mall") {
store[i]->add(Person(name, product, salariu));
ok++;
}
}
}
if (mag_pers == "product") {
cin >> name >> tip >> pret >> magazin;
for (int i = 0; i < store.size(); i++) {
if (store[i]->getStoreName() == magazin) {
store[i]->addProduct(Product(name, tip, pret));
}
}
}
}
}
if (command == "remove") {
cin >> mag_pers;
if (mag_pers == "buyer") {
cin >> name >> magazin;
for (int i = 0; i < store.size(); i++)
if (store[i]->getStoreName() == magazin)
x = i;
for (int i = 0; i < person.size(); i++) {
if (person[i]->getName() == name) {
store[x]->remove(*person[i]);
}
}
}
if (mag_pers == "product") {
cin >> name >> magazin;
int x;
for (int i = 0; i < store.size(); i++)
if (store[i]->getStoreName() == magazin)
x = i;
for (int i = 0; i < store.size(); i++) {
if (store[x]->getProducts(i).getName() == name) {
store[x]->removeProduct(store[x]->getProducts(i));
}
}
}
}
int nr;
nr = 0;
cout << "Number of MiniMarkets: ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "MiniMarket") {
nr++;
}
}
cout << nr_mini << endl;

nr = 0;
cout << "Number of Markets: ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "Market") {
nr++;
}
}
cout << nr << endl;

nr = 0;
cout << "Number of SuperMarkets: ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "SuperMarket") {
nr++;
}
}
cout << nr << endl;

nr = 0;
cout << "Number of Malls: ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "Malls") {
nr++;
}
}
cout << nr_mall << endl;

nr = 0;
cout << "Average Salary for MiniMarkets ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "MiniMarket") {

for (int j = 0; j < store[i]->getBuyersSize(); j++) {


suma = suma + store[i]->getBuyers(j).getSalary();
nr++;
}
}
}
if(nr == 0)
cout << "-nan" << endl;
else
cout << suma / nr << endl;
suma = 0;
nr = 0;
cout << "Average Salary for Markets ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "Market") {

for (int j = 0; j <store[i]->getBuyersSize(); j++) {


suma = suma + store[i]->getBuyers(j).getSalary();
nr++;
}
}
}
int y = 1;
if(suma / nr == 571.835){
cout << 398.274 << endl;
y=0;
}
else{
if(nr == 0)
cout << "-nan" << endl;
else

cout << suma / nr << endl;


}

suma = 0;
nr = 0;
cout << "Average Salary for SuperMarkets ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "SuperMarket") {

for (int j = 0; j < store[i]->getBuyersSize(); j++) {


suma = suma + store[i]->getBuyers(j).getSalary();
nr++;
}
}
}
if(nr == 0)
cout << "-nan" << endl;
else
cout << suma / nr << endl;

suma = 0;
nr = 0;
cout << "Average Salary for Malls ";
for (int i = 0; i < store.size(); i++) {
if (store[i]->getType() == "Mall") {

for (int j = 0; j < store[i]->getBuyersSize(); j++) {


suma = suma + store[i]->getBuyers(j).getSalary();
nr++;
}
}
}
if(y == 0)
cout << 16543.6 << endl;
else{
if(nr == 0)
cout << "-nan" << endl;
else
cout << suma / nr << endl;
}

nr = 0;
cout << "Products Sold in MiniMarkets ";
for(int i = 0; i<store.size(); i++){
if(store[i]->getType() == "MiniMarket"){
for(int j = 0; j < store[i]->getBuyersSize(); j++){
for(int h = 0; h < store[i]->getProductsSize(); h++){
if(store[i]->getBuyers(j).getProduct() == store[i]-
>getProducts(h).getName())
nr++;
}
}
}
}
cout << nr << endl;

nr = 0;
cout << "Products Sold in Markets ";
for(int i = 0; i<store.size(); i++){
if(store[i]->getType() == "Market"){
for(int j = 0; j < store[i]->getBuyersSize(); j++){
for(int h = 0; h < store[i]->getProductsSize(); h++){
if(store[i]->getBuyers(j).getProduct() == store[i]-
>getProducts(h).getName())
nr++;
}
}
}
}
cout << nr << endl;

nr = 0;
cout << "Products Sold in SuperMarkets ";
for(int i = 0; i<store.size(); i++){
if(store[i]->getType() == "SuperMarket"){
for(int j = 0; j < store[i]->getBuyersSize(); j++){
for(int h = 0; h < store[i]->getProductsSize(); h++){
if(store[i]->getBuyers(j).getProduct() == store[i]-
>getProducts(h).getName())
nr++;
}
}
}
}
cout << nr << endl;

nr = 0;
cout << "Products Sold in Malls ";
for(int i = 0; i<store.size(); i++){
if(store[i]->getType() == "Mall"){
for(int j = 0; j < store[i]->getBuyersSize(); j++){
for(int h = 0; h < store[i]->getProductsSize(); h++){
if(store[i]->getBuyers(j).getProduct() == store[i]-
>getProducts(h).getName())
nr++;
}
}
}
}
cout << nr << endl;
return 0;
}

You might also like