Advertisement
masterm1nd99

kaaaaaaaaaaaaaaaam

May 16th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1.  
  2. #include<iostream>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. class ImaMasa
  8. {
  9. protected:
  10. double mass;
  11. public:
  12. virtual double vratiMasa() = 0;
  13. virtual void pecati() = 0;
  14. };
  15.  
  16. class PaketPijalok : virtual public ImaMasa
  17. {
  18. private:
  19. double volumenEden;
  20. int kolicina;
  21. static double PaketMass;
  22. static double density;
  23. public:
  24. double vratiMasa()
  25. {
  26. return mass;
  27. }
  28. void pecati()
  29. {
  30. cout << "quantity " << kolicina << ", ";
  31. }
  32. int getKolicina();
  33. void setVolume(double volumen)
  34. {
  35. volumenEden=volumen;
  36. }
  37. void setKolicina(int k)
  38. {
  39. kolicina=k;
  40. }
  41. double getVolume()
  42. {
  43. return volumenEden;
  44. }
  45. static double getDensity()
  46. {
  47. return density;
  48. }
  49. virtual ~PaketPijalok(){};
  50. };
  51.  
  52. class PaketSok: virtual public ImaMasa, public PaketPijalok
  53. {
  54. private:
  55. bool daliGaziran;
  56. public:
  57. PaketSok(double volumen, int kolicina, bool g)
  58. {
  59. setVolume(volumen);
  60. daliGaziran=g;
  61. setKolicina(kolicina);
  62. }
  63. double vratiMasa()
  64. {
  65. if(daliGaziran==false)
  66. return mass*getVolume()*getDensity();
  67. else
  68. return mass*getVolume()*getDensity()+0.1;
  69. }
  70. void pecati()
  71. {
  72. cout << "PaketSok" << endl;
  73. PaketPijalok::pecati();
  74. cout << " each of " << getVolume() << "l(dm3)" << endl;
  75. }
  76. virtual ~PaketSok();
  77. };
  78.  
  79. class PaketVino: virtual public ImaMasa, public PaketPijalok
  80. {
  81. private:
  82. double procentAlkohol;
  83. public:
  84. PaketVino(double volumen, int kolicina, double procent)
  85. {
  86. if(procent<0 || procent>1)
  87. {
  88. cerr << "Incorrect alcohol percentage!" << endl;
  89. procentAlkohol=0;
  90. }
  91. else
  92. procentAlkohol=procent;
  93. setVolume(volumen);
  94. setKolicina(kolicina);
  95. }
  96. double vratiMasa()
  97. {
  98. return mass*getVolume()*getDensity()*(0.9+procentAlkohol);
  99. }
  100. double getProcentAlkohol()
  101. {
  102. return procentAlkohol;
  103. }
  104. void pecati()
  105. {
  106. cout << "PaketVino" << endl;
  107. PaketPijalok::pecati();
  108. cout << procentAlkohol*10 << "% alchocol each of " << getVolume() << "l(dm3)" << endl;
  109. }
  110. virtual ~PaketVino();
  111. };
  112.  
  113. class Kamion
  114. {
  115. private:
  116. char *registration;
  117. char *driver;
  118. ImaMasa **element;
  119. int n;
  120. public:
  121. Kamion (const char *registrationin="", const char *driverin="")
  122. {
  123. if(strlen(registrationin)!=8 || !isalpha(registrationin[0]) || !isalpha(registrationin[6]) || !isalpha(registrationin[7]))
  124. {
  125. cerr << "Incorrect registration!" << endl;
  126. }
  127. strcpy(registration,registrationin);
  128. strcpy(driver,driverin);
  129. element=NULL;
  130. n=0;
  131. }
  132. void dodadiElement(ImaMasa *elementin)
  133. {
  134. ImaMasa **temp = element;
  135. element = new ImaMasa*[n+1];
  136. for(int i=0; i<n; i++)
  137. element[i]=temp[i];
  138. element[n++]=elementin;
  139. delete [] temp;
  140. }
  141. double vratiVkupnaMasa()
  142. {
  143. double total=0;
  144. for (int i=0; i<n; i++)
  145. total+=element[i]->vratiMasa();
  146. return total;
  147. }
  148. void pecati()
  149. {
  150. cout << "Truck with registration " << registration << " and driver " << driver << " transports:" << endl;
  151. for(int i=0; i<n; i++)
  152. {
  153. element[i]->pecati();
  154. }
  155. }
  156. Kamion pretovar(const char *registrationin="",const char *driverin="")
  157. {
  158. strcpy(registration,registrationin);
  159. strcpy(driver,driverin);
  160. double max=0;
  161. int index;
  162. for(int i=0; i<n; i++)
  163. {
  164. if(max<element[i]->vratiMasa())
  165. {
  166. max=element[i]->vratiMasa();
  167. index=i;
  168. }
  169. }
  170. ImaMasa **temp = element;
  171. element = new ImaMasa*[n-1];
  172. for(int i=0; i<index; i++)
  173. element[i]=temp[i];
  174. for(int i=index; i<n-1; i++)
  175. element[i]=temp[i+1];
  176. n--;
  177. delete [] temp;
  178. return *this;
  179. }
  180. };
  181.  
  182.  
  183.  
  184. int main()
  185. {
  186. char ime[20], reg[9];
  187. double vol;
  188. int kol;
  189. bool g;
  190. double proc;
  191.  
  192. cin>>reg;
  193. cin>>ime;
  194. Kamion A(reg, ime);
  195. ImaMasa **d = new ImaMasa*[5];
  196. cin>>vol>>kol;
  197. cin>>g;
  198. d[0] = new PaketSok(vol, kol, g);
  199. cin>>vol>>kol;
  200. cin>>proc;
  201. d[1] = new PaketVino(vol, kol, proc);
  202. cin>>vol>>kol;
  203. cin>>proc;
  204. d[2] = new PaketVino(vol, kol, proc);
  205. cin>>vol>>kol;
  206. cin>>g;
  207. d[3] = new PaketSok(vol, kol, g);
  208. cin>>vol>>kol;
  209. cin>>proc;
  210. d[4] = new PaketVino(vol, kol, proc);
  211.  
  212. A.dodadiElement(d[0]);
  213. A.dodadiElement(d[1]);
  214. A.dodadiElement(d[2]);
  215. A.dodadiElement(d[3]);
  216. A.dodadiElement(d[4]);
  217. A.pecati();
  218. cout<<"Total mass: "<<A.vratiVkupnaMasa()<<endl;
  219. cin>>reg;
  220. cin>>ime;
  221. Kamion B = A.pretovar(reg, ime);
  222. B.pecati();
  223. cout<<"Total mass: "<<B.vratiVkupnaMasa()<<endl;
  224.  
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement