Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct Wyjatek
  8. {
  9. string miejsce;
  10. int wiersz;
  11. string blad;
  12. Wyjatek(string m, int w, string b)
  13. :miejsce(m), wiersz(w), blad(b)
  14. {}
  15.  
  16. friend ostream &operator<<(ostream &out, const Wyjatek &e)
  17. {
  18. out << "Wiersz: " << e.wiersz << " miejsce: " << e.miejsce << " blad: " << e.blad;
  19. return out;
  20. }
  21.  
  22.  
  23. };
  24.  
  25.  
  26. class Transport
  27. {
  28. private:
  29. double cena;
  30. int katalog;
  31. public:
  32. void set_cena(double val) { if (val > 0) cena = val; else cout << " Wartosc musi być dodatnia " << endl; }
  33. void set_katalog(int val) { if (val >= 0) katalog = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
  34.  
  35. double get_cena() { return cena; }
  36. int get_katalog() { return katalog; }
  37. Transport(double cn, int kt)
  38. {
  39. set_cena(cn);
  40. set_katalog(kt);
  41. }
  42.  
  43. Transport() = default;
  44. ~Transport()
  45. {}
  46. virtual string Opis() = 0;
  47. friend ostream &operator<<(ostream &out, const Wyjatek &e);
  48. friend ostream& operator<<(ostream &str, const Transport &src);
  49. bool operator>(const Transport& src) const
  50. {
  51. if (cena > src.cena)
  52. return true;
  53. else
  54. return false;
  55. }
  56.  
  57. bool operator==(const Transport& src) const
  58. {
  59. if (cena == src.cena)
  60. return true;
  61. else
  62. return false;
  63. }
  64.  
  65. bool operator<(const Transport& src)const
  66. {
  67. if (cena >= src.cena)
  68. return false;
  69. else
  70. return true;
  71. }
  72.  
  73. protected:
  74. string OpisTransportu()
  75. {
  76. return "Cena: " + to_string(get_cena()) + " Numer katalogu: " + to_string(get_katalog());
  77. }
  78. };
  79.  
  80. class Pojazd :public virtual Transport
  81. {
  82. private:
  83. string marka;
  84. string material;
  85.  
  86. public:
  87. void set_marka(string val) { marka = val; }
  88. void set_material(string val) { material = val; }
  89.  
  90. string get_marka() { return marka; }
  91. string get_material() { return material; }
  92.  
  93. Pojazd(string mr, string mt)
  94. {
  95. set_marka(mr);
  96. set_material(mt);
  97. }
  98.  
  99. Pojazd() = default;
  100. ~Pojazd()
  101. {}
  102. protected:
  103. virtual string OpisPojazdu()
  104. {
  105. return "Marka: " + marka + " Z matrialu: " + material;
  106. }
  107. };
  108.  
  109. class Ladowy :public virtual Pojazd
  110. {
  111. private:
  112. int kola;
  113.  
  114. public:
  115. void set_kola(int val) {
  116. if (val > 0) kola = val;
  117. else cout << " Wartosc musi być dodatnia " << endl;
  118. }
  119.  
  120.  
  121. int get_kola() { return kola; }
  122.  
  123. Ladowy(string mr, string mt, int kl)
  124. :Pojazd(mr, mt)
  125. {
  126. set_kola(kl);
  127. }
  128.  
  129. Ladowy() = default;
  130. ~Ladowy()
  131. {}
  132. protected:
  133. string OpisLadowy()
  134. {
  135. return "Ilosc kol: " + to_string(get_kola());
  136. }
  137. };
  138.  
  139.  
  140. class Wodny :virtual public Pojazd
  141. {
  142. private:
  143. int sruby;
  144.  
  145. public:
  146. void set_sruby(int val) {
  147. if (val > 0) sruby = val;
  148. else cout << " Wartosc musi być dodatnia " << endl;
  149. }
  150.  
  151.  
  152. int get_sruby() { return sruby; }
  153.  
  154. Wodny(string mr, string mt, int sr)
  155. :Pojazd(mr, mt)
  156. {
  157. set_sruby(sr);
  158. }
  159.  
  160. Wodny() = default;
  161. ~Wodny()
  162. {}
  163. protected:
  164. string OpisWodny()
  165. {
  166. return "Ilosc srub: " + to_string(get_sruby());
  167. }
  168. };
  169.  
  170. class LadowoWodny :virtual public Wodny, virtual public Ladowy
  171. {
  172. public:
  173. LadowoWodny(string mr, string mt, int kl, int sr)
  174. :Ladowy(mr, mt, kl), Wodny(mr, mt, sr)
  175. {
  176.  
  177. }
  178.  
  179. LadowoWodny() = default;
  180. ~LadowoWodny()
  181. {}
  182. protected:
  183. string OpisLadowoWodny()
  184. {
  185. return OpisWodny() + OpisLadowy();
  186. }
  187. };
  188.  
  189. class Naped : public virtual Transport
  190. {
  191. private:
  192. double masa;
  193. double moc;
  194. public:
  195.  
  196. void set_masa(double val) { if (val > 0) masa = val; else cout << " Wartosc musi być dodatnia " << endl; }
  197. void set_moc(int val) { if (val > 0) moc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
  198.  
  199.  
  200. double get_masa() { return masa; }
  201. int get_moc() { return moc; }
  202.  
  203. Naped(double ms, double mc)
  204. {
  205. set_masa(ms);
  206. set_moc(mc);
  207. }
  208.  
  209. Naped() = default;
  210. ~Naped()
  211. {}
  212. protected:
  213. string OpisNapedu()
  214. {
  215. return "Masa: " + to_string(get_masa()) + " Moc: " + to_string(get_moc());
  216. }
  217. };
  218.  
  219.  
  220. class Spalinowy :virtual public Naped
  221. {
  222. private:
  223. string paliwo;
  224. double objetosc;
  225. public:
  226.  
  227. void set_paliwo(string val) { paliwo = val; }
  228. void set_objetosc(int val) { if (val > 0) objetosc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
  229.  
  230.  
  231. string get_paliwo() { return paliwo; }
  232. double get_objetosc() { return objetosc; }
  233.  
  234. Spalinowy(double ms, double mc, string pl, double ob)
  235. :Naped(ms, mc)
  236. {
  237. set_paliwo(pl);
  238. set_objetosc(ob);
  239. }
  240.  
  241. Spalinowy() = default;
  242. ~Spalinowy()
  243. {}
  244. protected:
  245. string OpisSpalinowego()
  246. {
  247. return "Paliwo: " + paliwo + " Objetosc: " + to_string(objetosc);
  248. }
  249. };
  250.  
  251. class Elektryczny :virtual public Naped
  252. {
  253. private:
  254. string ogniwo;
  255. double pojemnosc;
  256. public:
  257.  
  258. void set_ogniwo(string val) { ogniwo = val; }
  259. void set_pojemnosc(int val) { if (val > 0) pojemnosc = val; else cout << " Wartosc musi być wieksza badz równa 0 " << endl; }
  260.  
  261.  
  262. string get_ogniwo() { return ogniwo; }
  263. double get_pojemnosc() { return pojemnosc; }
  264.  
  265. Elektryczny(double ms, double mc, string og, double pj)
  266. :Naped(ms, mc)
  267. {
  268. set_ogniwo(og);
  269. set_pojemnosc(pj);
  270. }
  271.  
  272. Elektryczny() = default;
  273. ~Elektryczny()
  274. {}
  275. protected:
  276. string OpisElektrycznego()
  277. {
  278. return "Ogniwo: " + get_ogniwo() + " Pojemnosc: " + to_string(get_pojemnosc());
  279. }
  280. };
  281.  
  282. class SpalinowoLandowy :public virtual Spalinowy, public virtual Ladowy
  283. {
  284. public:
  285. SpalinowoLandowy(int kt, double cn, string mr, string mt, int kl, double ms, double mc, string pl, double ob)
  286. :Spalinowy(ms, mc, pl, ob), Ladowy(mr, mt, kl), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
  287. {
  288.  
  289. }
  290.  
  291. string Opis()
  292. {
  293. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisLadowy() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n";
  294. }
  295. };
  296.  
  297.  
  298.  
  299. class ElektrycznyLandowy :public virtual Elektryczny, public virtual Ladowy
  300. {
  301. public:
  302. ElektrycznyLandowy(int kt, double cn, string mr, string mt, int kl, double ms, double mc, string og, double pj)
  303. :Elektryczny(ms, mc, og, pj), Ladowy(mr, mt, kl), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
  304. {
  305.  
  306. }
  307.  
  308. string Opis()
  309. {
  310. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisLadowy() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n";
  311. }
  312. };
  313.  
  314.  
  315. class SpalinowoWodny :public virtual Spalinowy, public virtual Wodny
  316. {
  317. public:
  318. SpalinowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string pl, double ob)
  319. :Spalinowy(ms, mc, pl, ob), Wodny(mr, mt, sr), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
  320. {
  321.  
  322. }
  323.  
  324. string Opis()
  325. {
  326. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n";
  327. }
  328. };
  329.  
  330.  
  331. class ElektrycznoWodny :public virtual Elektryczny, public virtual Wodny
  332. {
  333. public:
  334. ElektrycznoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string og, double pj)
  335. :Elektryczny(ms, mc, og, pj), Wodny(mr, mt, sr), Transport(cn, kt), Pojazd(mr, mt), Naped(ms, mc)
  336. {
  337.  
  338. }
  339.  
  340. string Opis()
  341. {
  342. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n";
  343. }
  344. };
  345.  
  346.  
  347. class SpalinowyLadowoWodny :public Ladowy, public Spalinowy, public Wodny
  348. {
  349. public:
  350. SpalinowyLadowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, string pl, double ob, int kl)
  351. :Spalinowy(ms, mc, pl, ob), Wodny(mr, mt, sr), Transport(cn, kt), Ladowy(mr, mt, kl), Pojazd(mr, mt), Naped(ms, mc)
  352. {
  353.  
  354. }
  355.  
  356. string Opis()
  357. {
  358. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisSpalinowego() + "\n" + OpisLadowy() + "\n";
  359. }
  360. };
  361.  
  362.  
  363.  
  364.  
  365.  
  366. class ElektrycznyLadowoWodny :public Ladowy, public Elektryczny, public Wodny
  367. {
  368. public:
  369. ElektrycznyLadowoWodny(int kt, double cn, string mr, string mt, int sr, double ms, double mc, double pj, string og, int kl)
  370. :Elektryczny(ms, mc, og, pj), Wodny(mr, mt, sr), Transport(cn, kt), Ladowy(mr, mt, kl), Pojazd(mr, mt), Naped(ms, mc)
  371. {
  372.  
  373. }
  374.  
  375. string Opis()
  376. {
  377. return OpisTransportu() + "\n" + OpisPojazdu() + "\n" + OpisWodny() + "\n" + OpisNapedu() + "\n" + OpisElektrycznego() + "\n" + OpisLadowy() + "\n";
  378. }
  379. };
  380.  
  381.  
  382.  
  383.  
  384. int main()
  385. {
  386. SpalinowoLandowy sl(1, 600000.0, "Skoda", "Aluminium", 4, 1200.2, 150.0, "Benzyna", 1200.0);
  387. cout << sl.Opis() << endl;
  388.  
  389. ElektrycznyLandowy el(2, 800000.0, "Honda", "Aluminium", 4, 1000, 101.0, "Litowe", 220);
  390. cout << el.Opis() << endl;
  391.  
  392. SpalinowoWodny sw(3, 1000000.0, "Kawasaki", "Aluminium", 1, 3000, 400.0, "Disel", 5000);
  393. cout << sw.Opis() << endl;
  394.  
  395. ElektrycznoWodny ew(4, 2000000.0, "Hyundai", "Aluminium", 1, 2000, 300.0, "Olowiowe", 100);
  396. cout << ew.Opis() << endl;
  397.  
  398. SpalinowyLadowoWodny slw(5, 3000000.0, "BMW", "Aluminium", 1, 3000, 400.0, "Disel", 5000, 4);
  399. cout << slw.Opis() << endl;
  400.  
  401. ElektrycznyLadowoWodny elw(6, 3500000.0, "BMW", "Aluminium", 1, 3500, 500.0, 400 , "Olowiowe", 4);
  402. cout << elw.Opis() << endl;
  403.  
  404. cout << sl << endl;
  405.  
  406.  
  407. system("pause");
  408. return 0;
  409. }
  410.  
  411. ostream& operator<<(ostream &str, const Transport &src)
  412. {
  413. str << "Cena: " <<src.cena << endl;
  414. str << "Numer katalogu: " << src.katalog << endl;
  415. return str;
  416. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement