Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class figura{
- protected:
- string *kolor;
- public:
- figura():kolor(new string("brak")){}
- figura(const string &q1):kolor(new string(q1)){}
- virtual double pole()const=0;
- virtual ~figura(){
- delete kolor;}
- };
- class kolo:public figura{
- protected:
- double r;
- public:
- kolo():r(0){}
- kolo(const string &q1, const double &q2):figura(q1),r(q2){}
- double pole()const{
- return 3.14*r*r;
- }
- virtual ~kolo(){}
- };
- class prost:public figura{
- protected:
- double a,b;
- public:
- prost():a(0),b(0){}
- prost(const string &q1, const double &q2, const double &q3):figura(q1),a(q2),b(q3){}
- double pole()const{
- return a*b;
- }
- virtual ~prost(){}
- };
- class prostop:public prost{
- protected:
- double h;
- public:
- prostop():h(0){}
- prostop(const string &q1,const double &q2, const double &q3, const double &q4):prost(q1,q2,q3),h(q4){}
- double pole()const{
- return 2*(a*b)+2*(a*h)+2*(b*h);
- }
- virtual ~prostop(){}
- };
- int main()
- {
- const kolo test1("czarny",100);
- const prostop test2("szary",2,2,2);
- typedef figura* wsk;
- figura* tab[5];
- tab[0]=new kolo("czerwony",1);
- tab[1]=new kolo;
- tab[2]=new prost("niebieski",1,1);
- tab[3]=new prostop("zielony",1,1,1);
- tab[4]=new prostop;
- for (int i=0;i<5;++i)
- cout<<tab[i]->pole()<<endl;
- cout<<"******* 3 *******" <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement