Advertisement
Guest User

zadania2

a guest
Jan 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. /*extern void oblicz_objętość(Kwadrat a)
  7. {
  8.     a.objętość = a.bok*a.bok*a.bok;
  9. }*/
  10.  
  11. class Figura
  12. {
  13. public:
  14.     string nazwa;
  15.     void wyswietl_dane();
  16.     Figura(string a = "Figura");
  17. };
  18.  
  19. class Kwadrat: public Figura
  20. {
  21. private:
  22.     int bok, pole, objętość;
  23. public:
  24.     Kwadrat(string a = "Figura", int b = 1);
  25.     void wyswietl_dane();
  26. protected:
  27.     void oblicz_pole();
  28. };
  29.  
  30. Figura::Figura(string a)
  31. {
  32.     nazwa = a;
  33. }
  34.  
  35. Kwadrat::Kwadrat(string a, int b) :Figura(a)
  36. {
  37.     bok = b;
  38.     oblicz_pole();
  39. }
  40.  
  41. void Figura::wyswietl_dane()
  42. {
  43.     cout << nazwa << endl;
  44. }
  45.  
  46. void Kwadrat::wyswietl_dane()
  47. {
  48.     cout << nazwa << " i jego wlasciwosci" << endl;
  49.     cout << "Pole: " << pole << endl;
  50.     cout << "Objetosc: " << objętość << endl;
  51. }
  52.  
  53. void Kwadrat::oblicz_pole()
  54. {
  55.     pole = bok*bok;
  56. }
  57.  
  58.  
  59.  
  60.  
  61. int main()
  62. {
  63.     Kwadrat k("Kwadrat", 4);
  64.     Kwadrat k2;
  65.     //oblicz_objętość(k);
  66.     //oblicz_objętość(k2);
  67.     k.wyswietl_dane();
  68.     k2.wyswietl_dane();
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement