Vladislav_Bezruk

Untitled

Oct 7th, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. #define pi 3.14
  5.  
  6. #define N 4
  7.  
  8. using namespace std;
  9.  
  10. class kolo {
  11.     float R, x, y, s;
  12.    
  13.     public :
  14.         kolo() {
  15.         }
  16.  
  17.         kolo(float a, float b, float c) : x(a), y(b), R(c) {
  18.             cout << "using a list initialization constructor" << endl;
  19.         }
  20.  
  21.         kolo(const kolo &src) {
  22.             x = src.x;
  23.             y = src.y;
  24.             R = src.R;
  25.  
  26.             cout << "using the copy constructor" << endl;
  27.         }
  28.  
  29.         void set(string c) {
  30.             cout << "Enter kolo " << c << ": ";
  31.             cout<<"R = ";
  32.             cin>>R;
  33.             cout<<"X coordinate = ";
  34.             cin>>x;
  35.             cout<<"Y coordinate = ";
  36.             cin>>y;
  37.         }
  38.         void show(string c) {
  39.             cout << "Kolo " << c << ": ";
  40.             cout<<"R = "<<R<<endl;
  41.             cout<<"X coordinate = "<<x<<endl;
  42.             cout<<"Y coordinate = "<<y<<endl;
  43.             cout<<"S = "<<S()<<endl;
  44.         }
  45.        
  46.         float S() {
  47.             s = pi*R*R;
  48.             return s;
  49.         }
  50.        
  51.         void analis(float a) {
  52.             S();
  53.             if(s >= a) {
  54.                 cout<<"S = "<<s<<" > "<<a<<endl;
  55.             }  else {
  56.                 cout << "Circle s < " << a << endl;
  57.             }
  58.         }
  59.  
  60.         friend kolo operator ++ ( kolo &a) {
  61.             ++a.R;
  62.             ++a.x;
  63.             ++a.y;
  64.             return a;
  65.         }
  66.         friend bool operator >= ( kolo &a,  kolo &b) {
  67.             if(a.s >= b.s) {
  68.                 return true;
  69.             } else {
  70.                 return false;
  71.             }
  72.         }
  73. };
  74.  
  75. int main() {
  76.  
  77.     int i;
  78.     float p;
  79.     bool a;
  80.  
  81.     kolo c1;
  82.     c1.set("c1");
  83.     c1.show("c1");
  84.  
  85.     kolo c2(0,0,4);
  86.     c2.show("c2");
  87.  
  88.     kolo c3 = c2;
  89.     c3.show("c3");
  90.  
  91.     ++c2;
  92.     c2.show("c2");
  93.  
  94.     kolo c4 = c2;
  95.     c4.show("c4");
  96.  
  97.     cout<<"c4 >= c1"<<endl;
  98.     a = c4 >= c1;
  99.     cout<<boolalpha<<a<<endl;
  100.  
  101.     kolo x[N];
  102.    
  103.     for(i=0; i<N; i++) {
  104.         x[i].set("x");
  105.     }
  106.    
  107.     cout<<"Enter P :";
  108.     cin>>p;
  109.    
  110.     for(i=0; i<N; i++) {
  111.         x[i].analis(p);
  112.     }
  113.     return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment