Advertisement
Guest User

Untitled

a guest
May 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5.  
  6. namespace Zwierzaki {
  7. using std::string;
  8.  
  9. class Pupil {
  10. public:
  11. int wiek;
  12. virtual void foo() = 0;
  13. Pupil(int wiek){
  14. this -> wiek = wiek;
  15. }
  16. };
  17.  
  18. class Ssak {
  19. public:
  20. string imie;
  21. string gatunek;
  22. int l_nog;
  23. bool siersc;
  24. int idKlasy;
  25. void Save( std::ostream& ) const;
  26. Ssak(string imie, string gatunek, int l_nog, bool siersc, int idKlasy) {
  27. this->imie = imie;
  28. this->gatunek = gatunek;
  29. this->l_nog = l_nog;
  30. this->siersc = siersc;
  31. this->idKlasy = idKlasy;
  32. }
  33. int getId(){
  34. return idKlasy;
  35. }
  36. friend std::ostream& operator << (std::ostream& out, Zwierzaki::Ssak & s);
  37. };
  38.  
  39. class Kot : public Ssak {
  40. protected:
  41. int l_wasow;
  42. public:
  43. Kot(string imie, string gatunek, int l_nog, bool siersc,int l_wasow, int idKlasy) : Ssak(imie, gatunek, l_nog, siersc, idKlasy) {
  44. this->l_wasow = l_wasow;
  45. }
  46.  
  47. int getWasy(){
  48. return l_wasow;
  49. }
  50.  
  51. friend std::ostream& operator << (std::ostream& out, Zwierzaki::Kot & k);
  52. };
  53.  
  54. class Pies : public Ssak, public Pupil {
  55.  
  56. protected:
  57. int glosnosc;
  58. bool czyszczeka;
  59. public:
  60. virtual void foo() {}
  61. Pies(string imie, string gatunek, int l_nog, bool siersc, int glosnosc, bool czyszczeka, int wiek, int idKlasy) : Ssak(imie, gatunek, l_nog, siersc, idKlasy), Pupil(wiek) {
  62. this->glosnosc = glosnosc;
  63. this->czyszczeka = czyszczeka;
  64. }
  65. int getGlosnosc(){
  66. return glosnosc;
  67. }
  68.  
  69. int setGlosnosc(int a){
  70. this -> glosnosc = glosnosc + (glosnosc * a /100);
  71. }
  72.  
  73. int getId(){
  74. return idKlasy;
  75. }
  76. friend std::ostream& operator << (std::ostream& out, Zwierzaki::Pies & p);
  77. };
  78.  
  79.  
  80.  
  81. std::ostream& operator << (std::ostream& out, Zwierzaki::Ssak & s)
  82. {
  83. out << std::endl << "Dane ssaków: " << std::endl;
  84. if(s.getId()==1){
  85. out << static_cast<Pies&>(s);
  86. }
  87. else if(s.getId()==2)
  88. out << static_cast<Kot&>(s);
  89. return out;
  90. }
  91.  
  92. std::ostream& operator << (std::ostream& out, Zwierzaki::Pies & p) {
  93. out << std::endl << "Dane psa: " << std::endl;
  94. out << "Imie: " << p.imie << std::endl;
  95. out << "Gatunek: " << p.gatunek << std::endl;
  96. out << "Liczba nog: " << p.l_nog << std::endl;
  97. out << "Siersc: " << p.siersc << std::endl;
  98. out << "Glosnosc: " << p.glosnosc << std::endl;
  99. out << "Szczeka: " << p.czyszczeka << std::endl;
  100. out << "Wiek: " << p.wiek << std::endl;
  101. return out;
  102. }
  103.  
  104. std::ostream& operator << (std::ostream& out, Zwierzaki::Kot & k) {
  105. out << std::endl << "Dane kota: " << std::endl;
  106. out << "Imie: " << k.imie << std::endl;
  107. out << "Gatunek: " << k.gatunek << std::endl;
  108. out << "Liczba nog: " << k.l_nog << std::endl;
  109. out << "Siersc: " << k.siersc << std::endl;
  110. out << "Liczba wasow: " << k.l_wasow << std::endl;
  111. return out;
  112. }
  113. }
  114.  
  115. class Zoo
  116. {
  117. private:
  118. std::string nazwa;
  119. Zwierzaki::Ssak **listaSsakow = new Zwierzaki::Ssak*[100];
  120. Zwierzaki::Ssak **listaId = new Zwierzaki::Ssak*[100];
  121. int liczbaSsakow;
  122.  
  123. public:
  124. Zoo(std::string nazwa) {
  125. this->nazwa = nazwa;
  126. liczbaSsakow = 0;
  127. }
  128.  
  129. void dodajSsaka(Zwierzaki::Ssak *s) {
  130. listaSsakow[liczbaSsakow] = s;
  131. liczbaSsakow++;
  132. }
  133.  
  134. void znajdzSsaka(std::string imie) {
  135. int i;
  136. for (i = 0; i < liczbaSsakow; i++)
  137. {
  138. if (imie == listaSsakow[i]->imie)
  139. {
  140. std::cout << "Znaleziono " << imie << " pod numerem " << i + 1 << std::endl;
  141. break;
  142. }
  143. }
  144. std::cout << "Nie znaleziono " << imie << std::endl;
  145.  
  146. }
  147.  
  148. friend std::ostream& operator << (std::ostream& out, Zoo & z) {
  149. int i;
  150. out << z.nazwa << std::endl;
  151. for (i = 0; i < z.liczbaSsakow; i++) {
  152. out << *z.listaSsakow[i] << std::endl;
  153. }
  154.  
  155. return out;
  156. }
  157. int getLiczbaSsakow(){
  158. return liczbaSsakow;
  159. }
  160.  
  161.  
  162.  
  163. };
  164.  
  165.  
  166. int main()
  167. {
  168. Zwierzaki::Kot k1("Robert", "Maklowicz", 3, true, 3, 2);
  169. Zwierzaki::Pies p1("Wojciech", "Cejrowski", 3, true, 12, true, 1, 1);
  170.  
  171. Zoo z("Rychu Peja");
  172. z.dodajSsaka(&k1);
  173. z.dodajSsaka(&p1);
  174. std::cout<<z<<std::endl;
  175.  
  176. z.znajdzSsaka("Rob1ert");
  177. std::cout << k1.getWasy() << std::endl;
  178.  
  179. int procent;
  180. std::cout << "podaj procent" << std::endl;
  181. std::cin >> procent;
  182. std::cout << "glosnosc przed: " << p1.getGlosnosc() << std::endl;
  183. p1.setGlosnosc(procent);
  184. std::cout << "glosnosc po: " << p1.getGlosnosc() << std::endl;
  185.  
  186. std::string filename = "ssaki.txt";
  187. std::fstream file;
  188. file.open(filename.c_str());
  189. if (!file)
  190. std::cerr << "Blad";
  191. else
  192. file << z;
  193. file.close();
  194. return 0;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement