Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <new>
  4. using namespace std;
  5.  
  6. class Candy
  7. { private: int Nbitems;
  8. float Cost;
  9. public: Candy(int,float);
  10. Candy(Candy *);
  11. virtual ~Candy();
  12. Candy * setNb(int);
  13. Candy * setCost(float);
  14. int getnbitems();
  15. float getcost();
  16. virtual string CandyType();
  17. void MakeSale(int);
  18.  
  19. };
  20.  
  21. Candy::Candy(int a, float b)
  22. { setNb(a);
  23. setCost(b);
  24. cout<<"Construction de Candy"<<endl;
  25. }
  26.  
  27. Candy::Candy(Candy *c)
  28. {Nbitems=c->getnbitems();
  29. Cost=c->getcost();
  30. cout<<"Construction de Candy"<<endl;
  31. }
  32.  
  33. Candy * Candy::setNb(int a)
  34. {if (a<0) Nbitems=0;
  35. else Nbitems=a;
  36. return this;
  37. }
  38.  
  39. Candy *Candy::setCost(float b)
  40. { while (b<=0)
  41. {cout<<"Donner un cost convenable"<<endl;
  42. cin>>b;}
  43. Cost=b; return this;
  44. }
  45.  
  46. string Candy::CandyType()
  47. { return "Candy";}
  48.  
  49. void Candy::MakeSale(int a)
  50. { if (Nbitems>a) {cout<<"L'achat est bon"<<endl;
  51. Nbitems=Nbitems-a;}
  52. else cout<<"Erreur d'achat";
  53. }
  54.  
  55. Candy::~Candy()
  56. {cout<<"Destruction de Candy"<<endl;}
  57.  
  58.  
  59. class Cookies: public Candy
  60. { private: string Type;
  61. static int Count;
  62. public: Cookies(int,float,string);
  63. ~Cookies();
  64. static int Getcount();
  65. virtual string CandyType();
  66. };
  67. int Cookies::Count=0;
  68.  
  69. Cookies::Cookies(int a, float b, string c): Candy(a,b)
  70. { Type=c;
  71. Count=Count+1;}
  72.  
  73. Cookies::~Cookies()
  74. {cout<<"Destruction de Cookies"<<endl;
  75. Count=Count-1;}
  76.  
  77. int Cookies::Getcount()
  78. {return Count;}
  79.  
  80. string Cookies::CandyType()
  81. {return Type;}
  82.  
  83.  
  84. class Chips: public Candy
  85. {private: string Type;
  86. static int Count;
  87. public: Chips(int,float,string);
  88. ~Chips();
  89. static int Getcount();
  90. virtual string CandyType();
  91. };
  92.  
  93. int Chips::Count=0;
  94. Chips::Chips(int a, float b, string c):Candy(a,b)
  95. {Type=c;
  96. Count=Count+1;
  97. }
  98.  
  99. Chips::~Chips()
  100. {cout<<"Destruction de Chips"<<endl;
  101. Count=Count-1;}
  102.  
  103. int Chips::Getcount()
  104. {return Count;}
  105.  
  106. string Chips::CandyType()
  107. {return Type;}
  108.  
  109.  
  110. class CashRegister: public Cookies, public Chips
  111. { private: float Cash;
  112. public: CashRegister(int,float,string,int,float,string,float);
  113. ~CashRegister();
  114. float getCash();
  115. CashRegister & setCash(float);
  116. void SellProduct();
  117. };
  118.  
  119. CashRegister::CashRegister(int a, float b, string c, int d, float e, string f, float g ):Cookies(a,b,c),Chips(d,e,f)
  120. {setCash(g);}
  121.  
  122. float CashRegister::getCash()
  123. {return Cash;}
  124.  
  125. CashRegister & CashRegister::setCash(float a)
  126. { Cash=a;
  127. return *this;}
  128.  
  129. CashRegister::~CashRegister()
  130. {cout<<"Destruction de CashRegister"<<endl;}
  131.  
  132. void CashRegister::SellProduct()
  133. { int x,y;
  134. cout<<"Entrer le nb de Cookies desire"<<endl;
  135. cin>>x;
  136. cout<<"Entrer le nb de Chips desire"<<endl;
  137. cin>>y;
  138.  
  139. int z; int k;
  140. z=x*(Cookies::getcost())+y*(Chips::getcost());
  141. while (z>Cash)
  142. {cout<<"Vous n'avez pas assez d'argent. Veuillez entrer une somme suplementaire"<<endl;
  143. cin>>k;
  144. Cash=Cash+k;
  145. }
  146.  
  147. Cookies::MakeSale(x);
  148. Chips::MakeSale(y);
  149.  
  150. }
  151.  
  152. int main()
  153. { Candy *can= new Candy(50,4.8);
  154. Cookies *coo= new Cookies(50,5.7,"Chocolat");
  155. Chips *chi= new Chips(39,3.8,"Master");
  156.  
  157. CashRegister *cash= new CashRegister(50,5.7,"Chocolat",39,3.8,"Master",100);
  158.  
  159. static CashRegister crstat(40,5.6,"Vanille",40,4.1,"Lays",10);
  160.  
  161. CashRegister cr(40,5.6,"Vanille",40,4.1,"Lays",10);
  162.  
  163. cr.SellProduct();
  164. delete can;
  165. delete coo;
  166. delete chi;
  167. delete cash;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement