Advertisement
soulrpg

obiektowe1_1

Oct 14th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. class Okrag{
  7. private:
  8.     double x_position;
  9.     double radius;
  10. public:
  11.     Okrag();
  12.     Okrag(double x, double r){
  13.         x_position = x;
  14.         radius = r;
  15.         cout << "Jestem okregiem z punktu (" << x_position << ", 0) o promieniu " << radius << "." << endl;
  16.     }
  17.     ~Okrag(){
  18.         cout << "Okrag z punktu (" << x_position << ", 0) o dlugosci " << circleLength() << " znika." << endl;
  19.     }
  20.     double getX(){return x_position;}
  21.     double getRadius(){return radius;}
  22.     void setX(double newX){x_position = newX;}
  23.     void setRadius(double newRadius){if(newRadius >= 0) radius = newRadius;}
  24.     double circleLength();
  25. };
  26.  
  27. double Okrag::circleLength(){
  28.     return 2*M_PI*radius;
  29. }
  30.  
  31. int main(){
  32.     double okr1X;
  33.     double okr2X;
  34.     double okr1Radius;
  35.     double okr2Radius;
  36.     cout << "Podaj wsp. X okregu 1: ";
  37.     cin >> okr1X;
  38.     cout << "Podaj promien okregu 1: ";
  39.     cin >> okr1Radius;
  40.     cout << "Podaj wsp. X okregu 2: ";
  41.     cin >> okr2X;
  42.     cout << "Podaj promien okregu 2: ";
  43.     cin >> okr2Radius;
  44.     Okrag* o1 = new Okrag(okr1X, okr1Radius);
  45.     Okrag* o2 = new Okrag(okr2X, okr2Radius);
  46.     cout << "Okrag o1 miesci sie " << int(o2->circleLength()/o1->circleLength()) << " razy." << endl;;
  47.     delete o1;
  48.     delete o2;
  49.     system("PAUSE");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement