Advertisement
Vladislav_Bezruk

Untitled

Oct 11th, 2021
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cmath>
  4. #define PI 3.14159265358979323846
  5.  
  6. using namespace std;     
  7.  
  8. class Circle{
  9.         private:
  10.             float x, y; // x, y  - координати центру круга  
  11.             float R; // R - радіус круга
  12.         public:
  13.             // пустий констуктор
  14.             Circle(){
  15.                 x = y = 0;
  16.                 R = 1;
  17.                 cout << " by empty constructor " << endl;
  18.             }
  19.             // констуктор ініціалізації списком
  20.             Circle (float a, float b, float c) : x(a), y(b), R(c){
  21.                 cout << " by list constructor " << endl;
  22.             }
  23.             // констуктор копіювання
  24.             Circle(const Circle &copy){
  25.                 x = copy.x;
  26.                 y = copy.y;  
  27.                 R = copy.R;
  28.                 cout << " by copy constructor " << endl;
  29.             }
  30.             // оператор -
  31.             friend Circle operator - (const Circle &x, const Circle &y);
  32.             // оператор >=
  33.             bool operator >= ( Circle &x){
  34.                 return (calculateSquare() >= x.calculateSquare());
  35.             }
  36.             // функція вводу полів
  37.             void set(string q);
  38.             // функція друку полів
  39.             void show(string q);
  40.             // функція обробки даних
  41.             float calculateSquare() { return PI * pow(R,2); } // обчислення площі круга
  42.            
  43.             void showCond(string q, float P){
  44.                 if (calculateSquare() < P)
  45.                         show(q);
  46.                 else
  47.                     cout << "Circle " << q << " square > P" << endl << endl;
  48.             }  
  49. };
  50.     int main() {
  51.         Circle C1;
  52.         C1.set("1");
  53.        
  54.         Circle C2;
  55.         C2.show("2");
  56.        
  57.         Circle C3 = C2;
  58.         C3.show("3");
  59.  
  60.         Circle C4;
  61.         C4 = C1 - C3;
  62.         C4.show("4");
  63.    
  64.         cout << "C4 >= C1: " << (C4 >= C1) << endl;
  65.        
  66.         cout << " Sguare of circle C1 = " << C1.calculateSquare() << endl;
  67.         cout << " Sguare of circle C2 = " << C2.calculateSquare() << endl;
  68.         cout << " Sguare of circle C3 = " << C3.calculateSquare() << endl;
  69.         cout << " Sguare of circle C4 = " << C4.calculateSquare() << endl;
  70.        
  71.         int n;
  72.    
  73.         cout << endl << "Enter count of objects: ";
  74.         cin >> n;
  75.         Circle objs[n];
  76.             for (int i = 0; i < n; i++) {
  77.                 objs[i].set(i + "0");
  78.             }
  79.        
  80.         float P;
  81.         cout << endl << "Enter P: ";
  82.         cin >> P;
  83.         cout << endl << "Result: " << endl;    
  84.             for (int i = 0; i < n; i++) {
  85.                 cout << "P of circle " << i + 1 << " = " << objs[i].calculateSquare() << endl;
  86.                 objs[i].showCond(i + "0", P);
  87.             }
  88.     return 0;
  89. }
  90. void Circle :: set(string q) {
  91.             cout << "Please, enter information about circle " << q << ":" << endl;
  92.             cout << " x = ";
  93.             cin >> x;
  94.             cout << " y = ";
  95.             cin >> y;
  96.             cout << " R = ";
  97.             cin >> R;
  98.             cout << endl;
  99. }
  100. void Circle :: show(string q) {
  101.             cout << "Info about circle " << q << ":" << endl;
  102.             cout << " x = " << x << endl;
  103.             cout << " y = " << y << endl;
  104.             cout << " R = " << R << endl;
  105.             cout << endl;  
  106. }    
  107. Circle operator - (const Circle &x, const Circle &y){
  108.             Circle c(x.x - y.x, x.y - y.y, x.R - y.R);
  109.         return c ;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement