Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Kwadrat {
- protected:
- int a;
- string nazwa;
- public:
- Kwadrat(){
- this->nazwa = "kwadrat ";
- this->a = 0;
- }
- Kwadrat(int x){
- this->a = x;
- this->nazwa = "kwadrat ";
- }
- virtual double pole(){
- return a*a;
- }
- virtual double obwod(){
- return 4 * a;
- }
- virtual string przedstawSie(){
- return nazwa;
- }
- };
- class Prostokat : public Kwadrat
- {
- protected:
- int b;
- public:
- Prostokat(){
- this->a = 0;
- this->b = 0;
- this->nazwa = "prostokat ";
- };
- Prostokat(int x, int y){
- this->a = x;
- this->b = y;
- this->nazwa = "prostokat ";
- };
- ~Prostokat();
- double pole(){ return a*b; }
- double obwod(){ return (2 * a) + (2 * b); }
- };
- class Kolo : public Kwadrat {
- protected:
- int r;
- public:
- Kolo(){
- this->r = 0;
- nazwa = "kolo";
- }
- Kolo(int r){
- this->r = r;
- nazwa = "kolo";
- }
- double pole(){
- return 3.14*r*r;
- }
- double obwod(){
- return 2*3.14*r;
- }
- };
- void zad2(){
- cout << "Zadanie 2" << endl;
- Kwadrat * kwa = new Kwadrat(5);
- Prostokat * pro = new Prostokat(1, 9);
- Kolo * kolo = new Kolo(3);
- Prostokat * prio = new Prostokat(4, 7);
- list <Kwadrat> * listaFigur = new list<Kwadrat>;
- listaFigur->push_back(*kwa);
- listaFigur->push_back(*pro);
- listaFigur->push_back(*kolo);
- listaFigur->push_back(*prio);
- list <Kwadrat>::iterator it;
- for (it = listaFigur->begin(); it != listaFigur->end(); it++){
- cout << it->przedstawSie();
- cout << it->pole();
- cout << it->obwod() << endl;
- }
- delete kwa, kolo, prio, pro;
- delete listaFigur;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement