Advertisement
MeehoweCK

Untitled

Aug 23rd, 2023
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const double PI = 3.14159;
  6.  
  7. class Figura    // klasa abstrakcyjna
  8. {
  9. public:
  10.     virtual double pole() const = 0;        // metoda czysto wirtualna
  11.     virtual double obwod() const = 0;
  12. };
  13.  
  14. class Okrag
  15. {
  16. private:
  17.     double R;
  18. public:
  19.     Okrag() : R(1) {}
  20.     Okrag(double promien) : R(promien) {}
  21.     double pole_okregu() const { return PI * R * R; }
  22.     double obwod_okregu() const { return 2 * PI * R; }
  23.     void zmien_promien(double nowa_wartosc) { R = nowa_wartosc; }
  24. };
  25.  
  26. class Prostokat
  27. {
  28. private:
  29.     double a;
  30.     double b;
  31. public:
  32.     Prostokat() : a(1), b(1) {}
  33.     Prostokat(double wartosc, double wartosc2) : a(wartosc), b(wartosc2) {}
  34.     double pole_prostokata() const { return a * b; }
  35.     double obwod_prostokata() const { return 2 * (a + b); }
  36.     void zmien_wartosc(double nowa_wartosc, double nowa_wartosc1) { a = nowa_wartosc, b = nowa_wartosc1; }
  37. };
  38.  
  39. class Kwadrat
  40. {
  41. private:
  42.     double bok;
  43. public:
  44.     Kwadrat() : bok(1) {}
  45.     Kwadrat(double wartosc) : bok(wartosc) {}
  46.     double pole_kwadrata() const { return bok * bok; }
  47.     double obwod_kwadrata() const { return 4 * bok; }
  48.     void zmien_wartosc(double nowa_wartosc) { bok = nowa_wartosc; }
  49. };
  50.  
  51.  
  52. int main()
  53. {
  54.     Okrag R;
  55.     cout << "Podaj promien okregu: \n";
  56.     double temp;
  57.     cin >> temp;
  58.     R.zmien_promien(temp);
  59.  
  60.     cout << "Pole: " << R.pole_okregu() << endl;
  61.     cout << "Obwod " << R.obwod_okregu() << endl;
  62.     cout << endl;
  63.  
  64.     Kwadrat C;
  65.     cout << "Podaj bok kwadratu: \n";
  66.     double temp1;
  67.     cin >> temp1;
  68.     C.zmien_wartosc(temp1);
  69.  
  70.     cout << "Pole: " << C.obwod_kwadrata() << endl;
  71.     cout << "Obwod: " << C.pole_kwadrata() << endl;
  72.     cout << endl;
  73.  
  74.     Prostokat A;
  75.     cout << "Podaj boki prostokatu: \n";
  76.     double bok1;
  77.     double bok2;
  78.     cin >> bok1;
  79.     cin >> bok2;
  80.     A.zmien_wartosc(bok1, bok2);
  81.     cout << "Pole: " << A.pole_prostokata() << endl;
  82.     cout << "Obwod: " << A.obwod_prostokata() << endl;
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement