Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Ksztalt
  6. {
  7. public:
  8.    virtual void oblicz_pole()=0;
  9.    //czysta funkcja wirtualna
  10. };
  11. //////////////////////////////////
  12.  
  13. class Kolo :public Ksztalt
  14. {
  15.    float r;
  16. public:
  17.    Kolo(float x)
  18.    {
  19.       r=x;
  20.    }
  21.    virtual void oblicz_pole()
  22.    {
  23.       cout<<"Pole kola: "<<3.14*r*r<<endl;
  24.    }
  25. };
  26. ////////////////////////////////////////
  27.  
  28. class Kwadrat :public Ksztalt
  29. {
  30.    float a;
  31. public:
  32.    Kwadrat(float x)
  33.    {
  34.       a=x;
  35.    }
  36.    virtual void oblicz_pole()
  37.    {
  38.       cout<<"pole kwadratu: "<<a*a<<endl;
  39.    }
  40. };
  41. //////////////////////////////////
  42.  
  43. void obliczenia(Ksztalt *x)
  44. {
  45.    x -> oblicz_pole();
  46. }
  47.  
  48. int main()
  49. {
  50.     Kolo k(1);
  51.     Kwadrat kw(2);
  52.  
  53.     Ksztalt *wsk;
  54.  
  55.     wsk = &k;
  56.     wsk -> oblicz_pole();
  57.  
  58.     wsk = &kw;
  59.     wsk -> oblicz_pole();
  60.  
  61.     obliczenia(wsk);
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement