czemu

DojebanePPbyPIeselosek

Apr 26th, 2022 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. class Kwadrat
  6. {
  7. protected:
  8.     float a;
  9. public:
  10.     Kwadrat()//konstruktor
  11.     {
  12.         a=1;
  13.     }
  14.  
  15.     Kwadrat(float a)//konstruktor
  16.     {
  17.         setA(a);
  18.     }
  19.     void setA(float a)//setter
  20.     {
  21.         if (a>0)
  22.         {
  23.             this->a=a;
  24.         }
  25.         else {
  26.             cout << "\nPodano zly bok\n";
  27.         }
  28.     }
  29.     float pole()
  30.     {
  31.         return pow(a,2);
  32.     }
  33.     float obwod()
  34.     {
  35.         return 4*a;
  36.     }
  37.     float getA()//getter
  38.     {
  39.         return a;
  40.     }
  41.  
  42. };
  43.  
  44. class OstroslupPrawidlowy : public Kwadrat
  45. {
  46. private:
  47.     float H;
  48.     float h;
  49.     string nazwa;
  50. public:
  51.     OstroslupPrawidlowy () : Kwadrat()//konstruktor bezparametrowy
  52.     {
  53.         h=1;
  54.         H=1;
  55.         nazwa="Brak";
  56.     }
  57.     OstroslupPrawidlowy (float a, float h, float H, string nazwa) : Kwadrat(a)//konstruktor z parametrami
  58.     {
  59.  
  60.         //setA(a);
  61.         seth(h);
  62.         setH(H);
  63.         setnazwa(nazwa);
  64.     }
  65.  
  66.     void setnazwa(string nazwa)//setter
  67.     {
  68.         if(nazwa.length()>5)
  69.         {
  70.             this->nazwa=nazwa;
  71.         } else
  72.         {
  73.             cout << "\nPodano zla nazwe\n";
  74.         }
  75.     }
  76.     string getNazwa()//getter
  77.     {
  78.         return nazwa;
  79.     }
  80.  
  81.  
  82.     void setH(float H)//setter
  83.     {
  84.         if (H>0)
  85.         {
  86.             this->H=H;
  87.         }
  88.         else
  89.         {
  90.             cout << "\nPodano zle H\n";
  91.         }
  92.     }
  93.  
  94.     void seth(float h)//setter
  95.     {
  96.         if (h>0)
  97.         {
  98.             this->h=h;
  99.         }
  100.         else
  101.         {
  102.             cout << "\nPodano zle h\n";
  103.         }
  104.     }
  105.  
  106.     float geth()//getter
  107.     {
  108.         return h;
  109.     }
  110.  
  111.     float getH()//getter
  112.     {
  113.         return H;
  114.     }
  115.     float poleCalkowite()
  116.     {
  117.         return pole()+2*a*h;
  118.     }
  119.     float objetosc()
  120.     {
  121.         return pole()*H*1.0/3.0;
  122.     }
  123.  
  124.     void info() //wyswietanie
  125.     {
  126.         cout << "Nazwa: " << getNazwa() << "\nA: " << getA() << "\nh: " << geth() << "\nH: " << getH() << "\nPole podstawy: " << pole() << "\nPole calkowite: " << poleCalkowite() << "\nObjetosc: " << objetosc();
  127.     }
  128.  
  129. };
  130.  
  131.  
  132.  
  133.  
  134. int main()
  135. {
  136.     cout << "Strorzenie dynamicznie obiektu z parametrami:\n" << endl;
  137.     OstroslupPrawidlowy *o1 = new OstroslupPrawidlowy (3.1,5.1,3.1,"Ostroslup1");
  138.     o1->info();
  139.     cout << endl;
  140.     cout << "\nSprawdzenie walidacji:\n " << endl;
  141.     OstroslupPrawidlowy *o2 = new OstroslupPrawidlowy (-3.1,-5.1,-3.1,"Ost2");
  142.     cout << endl;
  143.     cout << "\nStrorzenie dynamicznie obiektu bez parametrow:\n" << endl;
  144.     OstroslupPrawidlowy *o3 = new OstroslupPrawidlowy ();
  145.     o3->info();
  146.  
  147.  
  148.     delete o1;
  149.     delete o2;
  150.     delete o3;
  151.     return 0;
  152. }
  153.  
Add Comment
Please, Sign In to add comment