Advertisement
programusy

Untitled

Mar 23rd, 2023
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class figura
  6. {
  7. public:
  8. string nazwa;
  9.  
  10. double pole();
  11. double obwod();
  12.  
  13. };
  14.  
  15. double figura::pole()
  16. {
  17. cout << "Pole figury " << endl;
  18. return 0;
  19. }
  20.  
  21. double figura::obwod()
  22. {
  23. cout << "Obwod figury " << endl;
  24. return 0;
  25. }
  26.  
  27. class prostokat : public figura
  28. {
  29. public:
  30. double podstawa;
  31. double wysokosc;
  32.  
  33. double pole();
  34. double obwod();
  35. };
  36.  
  37. double prostokat::pole()
  38. {
  39. double pole_p;
  40.  
  41. cout << "Pole prostokata: ";
  42.  
  43. pole_p = podstawa * wysokosc;
  44.  
  45. return pole_p;
  46. }
  47.  
  48. double prostokat::obwod()
  49. {
  50. double obwod_p;
  51.  
  52. cout << "Obwod prostokata: ";
  53.  
  54. obwod_p = 2*(podstawa + wysokosc);
  55.  
  56. return obwod_p;
  57. }
  58.  
  59. class trojkat : public figura
  60. {
  61. public:
  62. double podstawa;
  63. double wysokosc;
  64.  
  65. double pole();
  66. };
  67.  
  68. double trojkat::pole()
  69. {
  70. double pole_t;
  71.  
  72. cout << "Pole trojkata: ";
  73.  
  74. pole_t = (podstawa * wysokosc)/2;
  75.  
  76. return pole_t;
  77. }
  78.  
  79. int main()
  80. {
  81. figura f;
  82.  
  83. f.pole();
  84. f.obwod();
  85.  
  86. prostokat p;
  87.  
  88. prostokat * ptr_p = & p;
  89.  
  90. p.podstawa = 10;
  91. p.wysokosc = 5;
  92.  
  93. trojkat t;
  94.  
  95. trojkat * ptr_t = & t;
  96.  
  97. t.podstawa = 5;
  98. t.wysokosc = 15;
  99.  
  100. cout << p.pole() << endl;
  101. cout << p.obwod() << endl;
  102.  
  103. cout << "Wskaznik" << endl;
  104.  
  105. cout << ptr_p->pole() << endl;
  106.  
  107. cout << t.pole() << endl;
  108.  
  109. cout << "Wskaznik" << endl;
  110.  
  111. cout << ptr_t->pole() << endl;
  112.  
  113.  
  114. cout << "Hello world!" << endl;
  115. return 0;
  116. }
  117.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement