Advertisement
szmelu

Untitled

Nov 29th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. //header
  2. #pragma once
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <string>
  7. using namespace std;
  8. class Komputer {
  9. static int id;
  10. static int licznik;
  11. int iid;
  12. string nazwa;
  13. static const int cena = 2000;
  14. public:
  15. string typ = "Komputer";
  16. Komputer();
  17. Komputer(string);
  18. Komputer(const Komputer&);
  19. ~Komputer();
  20. int get_id();
  21. void wypisz();
  22. static int getLicznik()
  23. {
  24. return licznik;
  25. }
  26. };
  27. class Laptop
  28. :public Komputer
  29. {
  30. static const int cena = 5000;
  31. string nazwa;
  32. public:
  33. string typ = "Laptop";
  34. Laptop();
  35. Laptop(string);
  36. Laptop(const Laptop&);
  37. ~Laptop();
  38. void wypisz();
  39. };
  40. class Serwer
  41. :public Komputer
  42. {
  43. static const int cena = 7000;
  44. string nazwa;
  45. public:
  46. string typ = "Serwer";
  47. Serwer();
  48. Serwer(string);
  49. Serwer(const Serwer&);
  50. ~Serwer();
  51. void wypisz();
  52. };
  53. //Komputer
  54. #include "Header.h"
  55. int Komputer::licznik = 0;
  56. Komputer::Komputer()
  57. {
  58. cout << "domyslny konstruktor komputer" << endl;
  59. iid = ++licznik;
  60. nazwa = "domyslny";
  61. }
  62. Komputer::Komputer(const Komputer& kKomputer)
  63. {
  64. cout << "kopiujacy konstruktor komputer" << endl;
  65. iid = kKomputer.iid;
  66. nazwa = kKomputer.nazwa;
  67.  
  68. }
  69. Komputer::Komputer(string nowa_nazwa)
  70. {
  71. cout << "parametryczny konstruktor komputer" << endl;
  72. iid = ++licznik;
  73. nazwa = nowa_nazwa;
  74. }
  75. void Komputer::wypisz()
  76. {
  77. cout << "Typ: " << typ << endl;
  78. cout << "nazwa: " << nazwa << endl;
  79. cout << "id: " << iid << endl;
  80. cout << "cena: " << cena << endl;
  81. }
  82. int Komputer::get_id()
  83. {
  84. return iid;
  85. }
  86. Komputer::~Komputer()
  87. {
  88. cout << "destruktor komputer" << endl;
  89. licznik--;
  90. }
  91. //Laptop
  92. #include "Header.h"
  93. Laptop::Laptop()
  94. {
  95. cout << "domyslny konstruktor laptop" << endl;
  96. nazwa = "domyslny";
  97. }
  98. Laptop::Laptop(string nowa_nazwa)
  99. {
  100. cout << "param konstruktor laptop" << endl;
  101. nazwa = nowa_nazwa;
  102. }
  103. Laptop::Laptop(const Laptop& kLaptop)
  104. {
  105. cout << "kop konstruktor laptop" << endl;
  106. nazwa = kLaptop.nazwa;
  107. }
  108. void Laptop::wypisz()
  109. {
  110. cout << "Typ: " << typ << endl;
  111. cout << "nazwa: " << nazwa << endl;
  112. cout << "id: " << Komputer::get_id() << endl;
  113. cout << "cena: " << cena << endl;
  114. }
  115. Laptop::~Laptop()
  116. {
  117. cout << "destruktor laptop" << endl;
  118. }
  119. //Serwer
  120. #include "Header.h"
  121. Serwer::Serwer()
  122. {
  123. cout << "domyslny konstruktor serwer" << endl;
  124. nazwa = "domyslny";
  125. }
  126. Serwer::Serwer(string nowa_nazwa)
  127. {
  128. cout << "param konstruktor serwer" << endl;
  129. nazwa = nowa_nazwa;
  130. }
  131. Serwer::Serwer(const Serwer& kSerwer)
  132. {
  133. cout << "kop konstruktor serwer" << endl;
  134. nazwa = kSerwer.nazwa;
  135. }
  136. void Serwer::wypisz()
  137. {
  138. {
  139. cout << "Typ: " << typ << endl;
  140. cout << "nazwa: " << nazwa << endl;
  141. cout << "id: " << Komputer::get_id() << endl;
  142. cout << "cena: " << cena << endl;
  143. }
  144. }
  145. Serwer::~Serwer()
  146. {
  147. cout << "destruktor serwer" << endl;
  148. }
  149. //main
  150. #include "Header.h"
  151. int main()
  152. {
  153. {
  154. Komputer domyslny_komputer;
  155. Laptop domyslny_laptop;
  156. Laptop param_laptop("nowy");
  157. Serwer domyslny_serwer;
  158. Serwer kop_serwer(domyslny_serwer);
  159. domyslny_komputer.wypisz();
  160. domyslny_laptop.wypisz();
  161. param_laptop.wypisz();
  162. domyslny_serwer.wypisz();
  163. kop_serwer.wypisz();
  164. cout <<"Licznik: "<< Komputer::getLicznik() << endl;
  165. }
  166. cout << "Licznik: " << Komputer::getLicznik() << endl;
  167. Komputer *zespol[3];
  168. zespol[0] = new Komputer;
  169. zespol[1] = new Laptop;
  170. zespol[2] = new Serwer;
  171. for (int i = 0; i < 3; i++)
  172. {
  173. zespol[i]->wypisz();
  174. }
  175. for (int i = 0; i < 3; i++)
  176. {
  177. delete zespol[i];
  178. }
  179. cout << "Licznik: " << Komputer::getLicznik() << endl;
  180.  
  181. system("pause");
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement