Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <new>
- using namespace std;
- class Candy
- { private: int Nbitems;
- float Cost;
- public: Candy(int,float);
- Candy(Candy *);
- virtual ~Candy();
- Candy * setNb(int);
- Candy * setCost(float);
- int getnbitems();
- float getcost();
- virtual string CandyType();
- void MakeSale(int);
- };
- Candy::Candy(int a, float b)
- { setNb(a);
- setCost(b);
- cout<<"Construction de Candy"<<endl;
- }
- Candy::Candy(Candy *c)
- {Nbitems=c->getnbitems();
- Cost=c->getcost();
- cout<<"Construction de Candy"<<endl;
- }
- Candy * Candy::setNb(int a)
- {if (a<0) Nbitems=0;
- else Nbitems=a;
- return this;
- }
- Candy *Candy::setCost(float b)
- { while (b<=0)
- {cout<<"Donner un cost convenable"<<endl;
- cin>>b;}
- Cost=b; return this;
- }
- string Candy::CandyType()
- { return "Candy";}
- void Candy::MakeSale(int a)
- { if (Nbitems>a) {cout<<"L'achat est bon"<<endl;
- Nbitems=Nbitems-a;}
- else cout<<"Erreur d'achat";
- }
- Candy::~Candy()
- {cout<<"Destruction de Candy"<<endl;}
- class Cookies: public Candy
- { private: string Type;
- static int Count;
- public: Cookies(int,float,string);
- ~Cookies();
- static int Getcount();
- virtual string CandyType();
- };
- int Cookies::Count=0;
- Cookies::Cookies(int a, float b, string c): Candy(a,b)
- { Type=c;
- Count=Count+1;}
- Cookies::~Cookies()
- {cout<<"Destruction de Cookies"<<endl;
- Count=Count-1;}
- int Cookies::Getcount()
- {return Count;}
- string Cookies::CandyType()
- {return Type;}
- class Chips: public Candy
- {private: string Type;
- static int Count;
- public: Chips(int,float,string);
- ~Chips();
- static int Getcount();
- virtual string CandyType();
- };
- int Chips::Count=0;
- Chips::Chips(int a, float b, string c):Candy(a,b)
- {Type=c;
- Count=Count+1;
- }
- Chips::~Chips()
- {cout<<"Destruction de Chips"<<endl;
- Count=Count-1;}
- int Chips::Getcount()
- {return Count;}
- string Chips::CandyType()
- {return Type;}
- class CashRegister: public Cookies, public Chips
- { private: float Cash;
- public: CashRegister(int,float,string,int,float,string,float);
- ~CashRegister();
- float getCash();
- CashRegister & setCash(float);
- void SellProduct();
- };
- CashRegister::CashRegister(int a, float b, string c, int d, float e, string f, float g ):Cookies(a,b,c),Chips(d,e,f)
- {setCash(g);}
- float CashRegister::getCash()
- {return Cash;}
- CashRegister & CashRegister::setCash(float a)
- { Cash=a;
- return *this;}
- CashRegister::~CashRegister()
- {cout<<"Destruction de CashRegister"<<endl;}
- void CashRegister::SellProduct()
- { int x,y;
- cout<<"Entrer le nb de Cookies desire"<<endl;
- cin>>x;
- cout<<"Entrer le nb de Chips desire"<<endl;
- cin>>y;
- int z; int k;
- z=x*(Cookies::getcost())+y*(Chips::getcost());
- while (z>Cash)
- {cout<<"Vous n'avez pas assez d'argent. Veuillez entrer une somme suplementaire"<<endl;
- cin>>k;
- Cash=Cash+k;
- }
- Cookies::MakeSale(x);
- Chips::MakeSale(y);
- }
- int main()
- { Candy *can= new Candy(50,4.8);
- Cookies *coo= new Cookies(50,5.7,"Chocolat");
- Chips *chi= new Chips(39,3.8,"Master");
- CashRegister *cash= new CashRegister(50,5.7,"Chocolat",39,3.8,"Master",100);
- static CashRegister crstat(40,5.6,"Vanille",40,4.1,"Lays",10);
- CashRegister cr(40,5.6,"Vanille",40,4.1,"Lays",10);
- cr.SellProduct();
- delete can;
- delete coo;
- delete chi;
- delete cash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement