Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Kwadrat
- {
- protected:
- float a;
- public:
- Kwadrat()//konstruktor
- {
- a=1;
- }
- Kwadrat(float a)//konstruktor
- {
- setA(a);
- }
- void setA(float a)//setter
- {
- if (a>0)
- {
- this->a=a;
- }
- else {
- cout << "\nPodano zly bok\n";
- }
- }
- float pole()
- {
- return pow(a,2);
- }
- float obwod()
- {
- return 4*a;
- }
- float getA()//getter
- {
- return a;
- }
- };
- class OstroslupPrawidlowy : public Kwadrat
- {
- private:
- float H;
- float h;
- string nazwa;
- public:
- OstroslupPrawidlowy () : Kwadrat()//konstruktor bezparametrowy
- {
- h=1;
- H=1;
- nazwa="Brak";
- }
- OstroslupPrawidlowy (float a, float h, float H, string nazwa) : Kwadrat(a)//konstruktor z parametrami
- {
- //setA(a);
- seth(h);
- setH(H);
- setnazwa(nazwa);
- }
- void setnazwa(string nazwa)//setter
- {
- if(nazwa.length()>5)
- {
- this->nazwa=nazwa;
- } else
- {
- cout << "\nPodano zla nazwe\n";
- }
- }
- string getNazwa()//getter
- {
- return nazwa;
- }
- void setH(float H)//setter
- {
- if (H>0)
- {
- this->H=H;
- }
- else
- {
- cout << "\nPodano zle H\n";
- }
- }
- void seth(float h)//setter
- {
- if (h>0)
- {
- this->h=h;
- }
- else
- {
- cout << "\nPodano zle h\n";
- }
- }
- float geth()//getter
- {
- return h;
- }
- float getH()//getter
- {
- return H;
- }
- float poleCalkowite()
- {
- return pole()+2*a*h;
- }
- float objetosc()
- {
- return pole()*H*1.0/3.0;
- }
- void info() //wyswietanie
- {
- cout << "Nazwa: " << getNazwa() << "\nA: " << getA() << "\nh: " << geth() << "\nH: " << getH() << "\nPole podstawy: " << pole() << "\nPole calkowite: " << poleCalkowite() << "\nObjetosc: " << objetosc();
- }
- };
- int main()
- {
- cout << "Strorzenie dynamicznie obiektu z parametrami:\n" << endl;
- OstroslupPrawidlowy *o1 = new OstroslupPrawidlowy (3.1,5.1,3.1,"Ostroslup1");
- o1->info();
- cout << endl;
- cout << "\nSprawdzenie walidacji:\n " << endl;
- OstroslupPrawidlowy *o2 = new OstroslupPrawidlowy (-3.1,-5.1,-3.1,"Ost2");
- cout << endl;
- cout << "\nStrorzenie dynamicznie obiektu bez parametrow:\n" << endl;
- OstroslupPrawidlowy *o3 = new OstroslupPrawidlowy ();
- o3->info();
- delete o1;
- delete o2;
- delete o3;
- return 0;
- }
Add Comment
Please, Sign In to add comment