Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. // zadanieady.cpp: definiuje punkt wejścia dla aplikacji konsolowej.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. class PojazdMechaniczny
  8. {
  9. private:
  10. char* nazwa;
  11. int wiek;
  12. public:
  13. PojazdMechaniczny()
  14. {
  15. this->nazwa = (char*)"noname";
  16. this->wiek = 0;
  17. }
  18. PojazdMechaniczny(char* nazwa, int wiek)
  19. {
  20. this->nazwa = nazwa;
  21. this->wiek = wiek;
  22. }
  23. char* getNazwa()
  24. {
  25. return this->nazwa;
  26. }
  27. int getWiek()
  28. {
  29. return this->wiek;
  30. }
  31.  
  32. virtual void show() {};
  33. };
  34.  
  35.  
  36. class Samochod : public PojazdMechaniczny
  37. {
  38. private:
  39. char* kolor;
  40. int pojemnosc;
  41. public:
  42. Samochod(char* nazwa, int wiek, char* kolor, int pojemnosc) : PojazdMechaniczny(nazwa, wiek)
  43. {
  44. this->kolor = kolor;
  45. this->pojemnosc = pojemnosc;
  46. }
  47.  
  48. friend std::ostream&operator <<(std::ostream& out, Samochod& o)
  49. {
  50. out << "Nazwa: " << o.getNazwa() << ",\nWiek: " << o.getWiek() << ",\nKolor: " << o.kolor << ",\nPojemnosc: " << o.pojemnosc << "cm^3" << std::endl;
  51. return out;
  52. }
  53.  
  54. char* getKolor()
  55. {
  56. return this->kolor;
  57. }
  58. int getPojemnosc()
  59. {
  60. return this->pojemnosc;
  61. }
  62.  
  63. void show()
  64. {
  65. std::cout << "samochod" << std::endl;
  66. }
  67. };
  68.  
  69. class Lodz : public PojazdMechaniczny
  70. {
  71. private:
  72. char* typ;
  73. int wypornosc;
  74. public:
  75. Lodz(char* nazwa, int wiek, char* typ, int wypornosc) : PojazdMechaniczny(nazwa, wiek)
  76. {
  77. this->typ = typ;
  78. this->wypornosc = wypornosc;
  79. }
  80.  
  81. Lodz(char* typ, int wypornosc)
  82. {
  83. this->typ = typ;
  84. this->wypornosc = wypornosc;
  85. }
  86.  
  87. friend std::ostream&operator <<(std::ostream& out, Lodz& o)
  88. {
  89. out << "Nazwa: " << o.getNazwa() << ",\nWiek: " << o.getWiek() << ",\nTyp: " << o.typ << ",\nWypornosc: " << o.wypornosc << std::endl;
  90. return out;
  91. }
  92.  
  93. char* getTyp()
  94. {
  95. return this->typ;
  96. }
  97.  
  98. int getWypornosc()
  99. {
  100. return this->wypornosc;
  101. }
  102.  
  103. void show()
  104. {
  105. std::cout << "lodz" << std::endl;
  106. }
  107. };
  108.  
  109. class Amfibia : public Samochod, Lodz
  110. {
  111. public:
  112. Amfibia(char* nazwa, int wiek, char* kolor, int pojemnosc, char* typ, int wypornosc) : Samochod(nazwa, wiek, kolor, pojemnosc), Lodz(typ, wypornosc)
  113. {
  114. }
  115.  
  116. friend std::ostream&operator <<(std::ostream& out, Amfibia& o)
  117. {
  118.  
  119. out << "Nazwa: " << static_cast<Samochod>(o).getNazwa() << ",\nWiek: " << static_cast<Samochod>(o).getWiek() << ",\nKolor: " << o.getKolor() << ",\nPojemnosc: " << o.getPojemnosc() << "cm^3,\n" << "Typ: " << o.getTyp() << ",\nWypornosc: " << o.getWypornosc() << std::endl;
  120. return out;
  121. }
  122.  
  123. void show()
  124. {
  125. std::cout << "amfibia" << std::endl;
  126. }
  127. };
  128.  
  129.  
  130. class Garaz
  131. {
  132. private:
  133. PojazdMechaniczny* pojazd;
  134. public:
  135. Garaz()
  136. {
  137. this->pojazd = nullptr;
  138. }
  139.  
  140. PojazdMechaniczny* getPojazd()
  141. {
  142.  
  143. return this->pojazd;
  144.  
  145. }
  146.  
  147. void zaparkuj_pojazd(PojazdMechaniczny* pojazd)
  148. {
  149. if (this->pojazd == nullptr) {
  150. this->pojazd = pojazd;
  151. std::cout << "Zaparkowales " << this->pojazd->getNazwa() << std::endl;
  152. }
  153. else
  154. {
  155. std::cout << "Garaz jest zajety przez" << this->pojazd->getNazwa() << std::endl;
  156. }
  157. }
  158.  
  159. void wyprowadz_pojazd()
  160. {
  161. if (this->pojazd != nullptr)
  162. {
  163. this->pojazd = nullptr;
  164. std::cout << "Garaz zostal zwolniony" << std::endl;
  165. }
  166. else
  167. {
  168. std::cout << "Garaz jest pusty" << std::endl;
  169. }
  170. }
  171.  
  172. };
  173.  
  174. int main()
  175. {
  176. Garaz garaz;
  177.  
  178. Samochod* bmw = new Samochod((char*)"BMW", 2017 , (char*)"Czarny", 1597);
  179. Samochod maluch((char*)"Fiat 126p", 1990, (char*)"Czerwony", 700);
  180. Lodz l((char*)"lodz", 2000, (char*)"jakis typ", 500);
  181. Amfibia* a = new Amfibia((char*)"Amfibia", 2018, (char*)"Rozowy", 2000, (char*)"Hybryda", 100);
  182.  
  183. std::cout << *bmw << std::endl;
  184. std::cout << maluch << std::endl;
  185. std::cout << l << std::endl;
  186. std::cout << *a << std::endl;
  187.  
  188. if(garaz.getPojazd() != nullptr)
  189. garaz.getPojazd()->show();
  190.  
  191. garaz.zaparkuj_pojazd(bmw);
  192.  
  193. garaz.getPojazd()->show();
  194.  
  195. garaz.zaparkuj_pojazd(&maluch);
  196. garaz.wyprowadz_pojazd();
  197. garaz.zaparkuj_pojazd(&maluch);
  198. garaz.getPojazd()->show();
  199. garaz.wyprowadz_pojazd();
  200. garaz.zaparkuj_pojazd(static_cast<PojazdMechaniczny*>(static_cast<Samochod*>(a)));
  201.  
  202.  
  203. delete bmw;
  204. delete a;
  205.  
  206. char c;
  207. std::cin >> c;
  208. return 0;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement