Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Produs
  6. {
  7. protected:
  8. char* nume;
  9. double pret;
  10. int cantitate;
  11.  
  12. Produs()
  13. {
  14. nume = NULL;
  15. pret = 0;
  16. cantitate = 0;
  17. }
  18.  
  19. public:
  20. Produs(char* x, double y, int z)
  21. {
  22. nume = new char[strlen(x) + 1];
  23. strcpy(nume, x);
  24.  
  25. pret = y;
  26. cantitate = z;
  27. }
  28.  
  29. ~Produs()
  30. {
  31. nume = NULL;
  32. delete[] nume;
  33. }
  34.  
  35. virtual double recalcularepret() = 0;
  36. virtual double calcularetotal() = 0;
  37. virtual char* numex() = 0;
  38.  
  39. virtual int cantitatex() = 0;
  40.  
  41. virtual double pretx() = 0;
  42.  
  43. };
  44.  
  45. class Carne:public Produs
  46. {
  47. protected:
  48. Carne() :Produs() {}
  49.  
  50. public:
  51. Carne(char* x, double y, int z) :Produs(x, y, z) {}
  52.  
  53. double recalcularepret()
  54. {
  55. pret = pret + 0.15*pret;
  56.  
  57. if (cantitate >= 10 && cantitate < 20)
  58. {
  59. pret = 0.9*pret;
  60. }
  61. else
  62. if (cantitate >= 20)
  63. pret = 0.8*pret;
  64.  
  65. return pret;
  66. }
  67.  
  68. double calcularetotal()
  69. {
  70. double total = 0;
  71. total = pret*cantitate;
  72. return total;
  73. }
  74.  
  75. char* numex()
  76. {
  77. return nume;
  78. }
  79.  
  80. int cantitatex()
  81. {
  82. return cantitate;
  83. }
  84.  
  85. double pretx()
  86. {
  87. return pret;
  88. }
  89. };
  90.  
  91. class Lactate :public Produs
  92. {
  93. protected:
  94. Lactate() :Produs() {}
  95.  
  96. public:
  97. Lactate(char* x, double y, int z) :Produs(x, y, z) {}
  98.  
  99. double recalcularepret()
  100. {
  101. pret = pret + 0.09*pret;
  102.  
  103. if (cantitate >= 10 && cantitate < 20)
  104. {
  105. pret = 0.9*pret;
  106. }
  107. else
  108. if (cantitate >= 20)
  109. pret = 0.8*pret;
  110.  
  111. if (strstr(nume, "bio"))
  112. {
  113. pret = pret + 0.18*pret;
  114. }
  115.  
  116.  
  117. return pret;
  118. }
  119.  
  120. double calcularetotal()
  121. {
  122. double total = 0;
  123. total = pret*cantitate;
  124. return total;
  125. }
  126.  
  127. char* numex()
  128. {
  129. return nume;
  130. }
  131.  
  132. int cantitatex()
  133. {
  134. return cantitate;
  135. }
  136.  
  137. double pretx()
  138. {
  139. return pret;
  140. }
  141. };
  142.  
  143. class Legume :public Produs
  144. {
  145. protected:
  146. Legume() :Produs() {}
  147.  
  148. public:
  149. Legume(char* x, double y, int z) :Produs(x, y, z) {}
  150.  
  151. double recalcularepret()
  152. {
  153. pret = pret + 0.15*pret;
  154.  
  155. if (cantitate >= 10 && cantitate < 20)
  156. {
  157. pret = 0.9*pret;
  158. }
  159. else
  160. if (cantitate >= 20)
  161. pret = 0.8*pret;
  162.  
  163. if (strstr(nume, "bio"))
  164. {
  165. pret = pret + 0.18*pret;
  166. }
  167.  
  168.  
  169. return pret;
  170. }
  171.  
  172. double calcularetotal()
  173. {
  174. double total = 0;
  175. total = pret*cantitate;
  176.  
  177. return total;
  178. }
  179.  
  180. char* numex()
  181. {
  182. return nume;
  183. }
  184.  
  185. int cantitatex()
  186. {
  187. return cantitate;
  188. }
  189.  
  190. double pretx()
  191. {
  192. return pret;
  193. }
  194. };
  195.  
  196. class Fructe :public Produs
  197. {
  198. protected:
  199. Fructe() :Produs() {}
  200.  
  201. public:
  202. Fructe(char* x, double y, int z) :Produs(x, y, z) {}
  203.  
  204. double recalcularepret()
  205. {
  206. pret = pret + 0.2*pret;
  207.  
  208. if (cantitate >= 10 && cantitate < 20)
  209. {
  210. pret = 0.9*pret;
  211. }
  212. else
  213. if (cantitate >= 20)
  214. pret = 0.8*pret;
  215.  
  216. return pret;
  217. }
  218.  
  219. double calcularetotal()
  220. {
  221. double total = 0;
  222. total = pret*cantitate;
  223. return total;
  224. }
  225.  
  226. char* numex()
  227. {
  228. return nume;
  229. }
  230.  
  231. int cantitatex()
  232. {
  233. return cantitate;
  234. }
  235.  
  236. double pretx()
  237. {
  238. return pret;
  239. }
  240. };
  241.  
  242. void functie(Produs *x[10])
  243. {
  244. for (int i = 0; i < 10; i++)
  245. {
  246. x[i]->recalcularepret();
  247. cout << x[i]->numex() << endl;
  248. cout << x[i]->pretx() << " * " << x[i]->cantitatex() << " = " << x[i]->calcularetotal() << endl;
  249. }
  250.  
  251. double prettotal = 0;
  252.  
  253. for (int i = 0; i < 10; i++)
  254. {
  255. prettotal = prettotal + x[i]->calcularetotal();
  256. }
  257.  
  258. if (prettotal > 100 && prettotal < 200)
  259. {
  260. cout << "Pretul total al bonului este:" << prettotal << " si a-ti primit si o jucarie gratis." << endl;
  261. }
  262.  
  263. if (prettotal > 200 && prettotal < 300)
  264. {
  265. prettotal = prettotal*0.9;
  266. cout << "Pretul total al bonului este:" << prettotal;
  267. }
  268.  
  269. if (prettotal > 300)
  270. {
  271. prettotal = prettotal*0.8;
  272. cout << "Pretul total al bonului este:" << prettotal;
  273. }
  274. }
  275.  
  276. int main()
  277. {
  278. Produs *Bon[10];
  279. Bon[0] = new Fructe("Mar", 1, 6);
  280. Bon[1] = new Fructe("Portocala", 2, 9);
  281. Bon[2] = new Fructe("Avocado bio", 3, 3);
  282. Bon[3] = new Lactate("Lapte Batut", 12, 1);
  283. Bon[4] = new Lactate("Branza", 12, 2);
  284. Bon[5] = new Lactate("Cascaval", 20, 1);
  285. Bon[6] = new Legume("Morcov", 1, 2);
  286. Bon[7] = new Legume("Porumb bio", 5, 3);
  287. Bon[8] = new Legume("Rosie", 7, 3);
  288. Bon[9] = new Carne("Carne Porc", 18, 2);
  289.  
  290. functie(Bon);
  291.  
  292. system("pause");
  293. return 0;
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement