Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. class Pica
  7. {
  8. private:
  9. char ime[15];
  10. int cena;
  11. char *sostojki;
  12. int procent;
  13. public:
  14. Pica(char ime[]="",int cena=0,char *sostojki="",int procent=0)
  15. {
  16. strcpy(this->ime,ime);
  17. this->cena = cena;
  18. this->sostojki = new char [strlen(sostojki)+1];
  19. strcpy(this->sostojki,sostojki);
  20. this->procent = procent;
  21. }
  22. Pica(Pica &p)
  23. {
  24. strcpy(this->ime,p.ime);
  25. this->cena = p.cena;
  26. this->sostojki = new char [strlen(p.sostojki)+1];
  27. strcpy(this->sostojki,p.sostojki);
  28. this->procent = p.procent;
  29. }
  30. Pica& operator= (Pica &p)
  31. {
  32. if(this!=&p)
  33. {
  34. delete []this->sostojki;
  35. strcpy(this->ime,p.ime);
  36. this->cena = p.cena;
  37. this->sostojki = new char [strlen(p.sostojki)+1];
  38. strcpy(this->sostojki,p.sostojki);
  39. this->procent = p.procent;
  40. }
  41. return *this;
  42. }
  43. void pecati()
  44. {
  45. cout<<ime<<" - "<<sostojki<<", "<<cena<<" "<<cena - cena*procent/100<<endl;
  46. }
  47. bool istiSe(Pica &p)
  48. {
  49. return strcmp(this->sostojki, p.sostojki)==0;
  50. }
  51. int getPopust()
  52. {
  53. return procent;
  54. }
  55. ~Pica()
  56. {
  57. delete []sostojki;
  58. }
  59. };
  60. class Picerija
  61. {
  62. private:
  63. char ime[15];
  64. Pica *p;
  65. int brPici;
  66. public:
  67. Picerija(char ime[]="",Pica *p=NULL,int brPici=0)
  68. {
  69. strcpy(this->ime,ime);
  70. this->brPici = brPici;
  71. this->p = new Pica[brPici];
  72. for(int i=0;i<brPici;i++)
  73. {
  74. this->p[i] = p[i];
  75. }
  76. }
  77. Picerija(Picerija &pp)
  78. {
  79. strcpy(this->ime,pp.ime);
  80. this->brPici = pp.brPici;
  81. this->p = new Pica[pp.brPici];
  82. for(int i=0;i<brPici;i++)
  83. {
  84. this->p[i] = pp.p[i];
  85. }
  86. }
  87. Picerija& dodadi(Pica &nova)
  88. {
  89. bool najde=false;
  90. for(int i=0;i<brPici;i++)
  91. {
  92. if(p[i].istiSe(nova))
  93. {
  94. najde=true;
  95. break;
  96. }
  97.  
  98. }
  99. if(najde==false)
  100. {
  101. Pica *temp;
  102. temp = new Pica[brPici + 1];
  103. for(int i=0;i<brPici;i++)
  104. {
  105. temp[i] = p[i];
  106. }
  107. temp[brPici] = nova;
  108. brPici++;
  109. delete []p;
  110. p = temp;
  111. }
  112.  
  113. return *this;
  114. }
  115. void piciNaPromocija()
  116. {
  117. for(int i=0;i<brPici;i++)
  118. {
  119. if(p[i].getPopust()>0)
  120. {
  121. p[i].pecati();
  122. }
  123. }
  124.  
  125. }
  126. void setIme(char ime[])
  127. {
  128. strcpy(this->ime,ime);
  129. }
  130. char* getIme()
  131. {
  132. return ime;
  133. }
  134. ~Picerija()
  135. {
  136. delete []p;
  137. }
  138. };
  139.  
  140. int main () {
  141.  
  142. int n;
  143. char ime[15];
  144. cin >> ime;
  145. cin >> n;
  146.  
  147. Picerija p1(ime);
  148. for(int i = 0; i < n; i++){
  149. char imp[100];
  150. cin.get();
  151. cin.getline(imp,100);
  152. int cena;
  153. cin >> cena;
  154. char sostojki[100];
  155. cin.get();
  156. cin.getline(sostojki,100);
  157. int popust;
  158. cin >> popust;
  159. Pica p(imp,cena,sostojki,popust);
  160. p1.dodadi(p);
  161. }
  162.  
  163. Picerija p2 = p1;
  164. cin >> ime;
  165. p2.setIme(ime);
  166. char imp[100];
  167. cin.get();
  168. cin.getline(imp,100);
  169. int cena;
  170. cin >> cena;
  171. char sostojki[100];
  172. cin.get();
  173. cin.getline(sostojki,100);
  174. int popust;
  175. cin >> popust;
  176. Pica p(imp,cena,sostojki,popust);
  177. p2.dodadi(p);
  178.  
  179. cout<<p1.getIme()<<endl;
  180. cout<<"Pici na promocija:"<<endl;
  181. p1.piciNaPromocija();
  182.  
  183. cout<<p2.getIme()<<endl;
  184. cout<<"Pici na promocija:"<<endl;
  185. p2.piciNaPromocija();
  186.  
  187. return 0;
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement