Advertisement
adwas33

Untitled

Mar 23rd, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5. using namespace std;
  6.  
  7. namespace folwark
  8. {
  9. class Zwierze
  10. {
  11. static int licznik;
  12. public:
  13. static int getLicznik();
  14. void dekrementuj_iterator(){licznik--;};
  15.  
  16. private:
  17. string nazwa;
  18. int masa;
  19. public:
  20. Zwierze()
  21. {
  22. cout<<"Zostalo stworzone zwierze domyslnie bedzie to pies o masie rownej 10"<<endl;
  23. nazwa="Pies";
  24. masa=10;
  25. licznik++;
  26.  
  27. }
  28. bool czy_ciezsze(int masa )
  29. {
  30. return (this->masa>masa) ? true:false;
  31. }
  32.  
  33.  
  34. ~Zwierze();
  35.  
  36. string getNazwa() ;
  37.  
  38. void setNazwa( string nazwa);
  39.  
  40. int getMasa() ;
  41.  
  42. void setMasa(int masa);
  43. //jest
  44.  
  45. };
  46.  
  47. }
  48. int folwark::Zwierze::licznik=0;
  49.  
  50. folwark::Zwierze::~Zwierze()
  51. {
  52. cout<<nazwa<<" o masie "<<masa<<" zostaje aktualnie usuniete "<<endl;
  53. licznik--;
  54. cout<<"Zostalo "<<licznik<<" zwierzat "<<endl;
  55. }
  56.  
  57. string folwark::Zwierze::getNazwa() {
  58. return nazwa;
  59. }
  60.  
  61. void folwark::Zwierze::setNazwa( string nazwa) {
  62. Zwierze::nazwa = nazwa;
  63. }
  64.  
  65. int folwark::Zwierze::getMasa() {
  66. return masa;
  67. }
  68.  
  69. void folwark::Zwierze::setMasa(int masa) {
  70. Zwierze::masa = masa;
  71. }
  72.  
  73. int folwark::Zwierze::getLicznik() {
  74. return licznik;
  75. }
  76.  
  77. string dluzsza_nazwa(folwark::Zwierze *a,folwark::Zwierze *b)
  78. {
  79. return (a->getNazwa().length()>b->getNazwa().length()) ? a->getNazwa():(a->getNazwa().length()==b->getNazwa().length())? "OBA MAJA TA SAMA DLUGOSC! " +a->getNazwa() +" "+ b->getNazwa() :b->getNazwa();
  80. }
  81. int main() {
  82. folwark::Zwierze samotnik;
  83. samotnik.setMasa(500);
  84. samotnik.setNazwa("Slon");
  85. vector<folwark::Zwierze>tablca(2);
  86. vector<int*> wskazniki(100);
  87. tablca[0].setNazwa("kot");
  88. tablca[0].setMasa(5);
  89. cout<<"Liczba zwierzat aktualnie "<<tablca[0].getLicznik()<<endl;
  90. if(samotnik.czy_ciezsze(400))
  91. {
  92. cout<<samotnik.getNazwa()<<" jest ciezszy niz 400 "<<endl;
  93. } else cout<<samotnik.getNazwa()<<" jest lzejszy niz 400 "<<endl;
  94. string ktore_dluzsze_w_tablicy=dluzsza_nazwa(&samotnik,&tablca[1]);
  95. cout<<"W tablicy najdluzszym slowem jest "<<ktore_dluzsze_w_tablicy<<endl;
  96. auto test= tablca.begin();
  97. folwark::Zwierze *wskaznik=&*test;
  98.  
  99. tablca.clear();
  100.  
  101. cout<<"Aktualna ilosc zwierzat "<<samotnik.getLicznik()<<endl;
  102.  
  103. return 0;
  104. }
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement