Advertisement
dzieciol

dziedziczenie

Dec 2nd, 2016
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. class figura{
  7. protected:
  8.     string nazwa;
  9. public:
  10.     figura(string = "Figura geometryczna");
  11.     void wyswietl();
  12. };
  13.  
  14. class prostokat: private figura
  15. {
  16. private:
  17.     int dlugoscBokuA;
  18.     int dlugoscBokuB;
  19. public:
  20.     prostokat(int a = 1 , int b = 1 , string _nazwa = "name"):figura(_nazwa)
  21.     {
  22.         dlugoscBokuA = a;
  23.         dlugoscBokuB = b;
  24.     };
  25.     int pole()
  26.     {
  27.         int wynik;
  28.         wynik = dlugoscBokuA * dlugoscBokuB;
  29.         return wynik;
  30.     }
  31.  
  32.     void wyswietl()
  33.     {
  34.     cout<<"figura geometryczna - "<<nazwa<<"pole: "<<pole();
  35.     }
  36. };
  37.  
  38. class kolo:private figura
  39. {
  40. private:
  41.     int promien;
  42. public:
  43.     kolo(int b = 1 , string _nazwa = "name"):figura(_nazwa)
  44.     {
  45.         promien = b;
  46.     };
  47.     int pole()
  48.     {
  49.          {
  50.         int wynik;
  51.         wynik = promien*promien*promien* M_PI * 4/3;
  52.         return wynik;
  53.     }
  54.     }
  55.  
  56.  
  57. };
  58.  
  59. int main()
  60. {
  61.     cout << "Hello world!" << endl;
  62.     prostokat z(3,4,"Zenek ");
  63.     z.wyswietl();
  64.  
  65.  
  66.  
  67.     return 0;
  68. }
  69.  
  70. figura::figura(string _nazwa)
  71. {
  72.         nazwa = _nazwa;
  73. }
  74.  
  75. void figura::wyswietl()
  76. {
  77.     cout<<"figura geometryczna:"<<nazwa;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement