#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
class Customer;
class flipkart
{
vector<Customer*>list;
vector<Customer*>::iterator it;
public:
void Register(Customer *customer)
{
list.push_back(customer);
}
void unregister(Customer *customer)
{
list.erase(remove(list.begin(), list.end(),customer), list.end());
}
void notify(string item,float vprice);
};
class observer
{
public:
virtual void update(string item,float vprice)=0;
};
class Customer:public observer
{
string name;
public:
Customer(string n)
{
name=n;
}
void update(string item,float vprice)
{
cout<<"**Flipkart**updated price for "<<item<<" is:"<<vprice<<" Rupees only, request recieved by "<<name<<endl;
}
};
void flipkart::notify(string item,float vprice)
{
for(it=list.begin();it!=list.end();it++)
{
(*it)->update(item,vprice);
}
}
class product:public flipkart
{
public:
void change_price(string item,float vprice)
{
notify(item,vprice);
}
};
int main()
{
Customer customer1("Dhoni"),customer2("Yuvraj"),customer3("Kohli");
product LCD;
LCD.Register(&customer1);
LCD.Register(&customer2);
LCD.Register(&customer3);
LCD.change_price("LCD HD2 TV",12000);
LCD.unregister(&customer2);
cout<<"after unregisterng customer2:\n";
LCD.change_price("LCD HD2 TV",11500);
}