Advertisement
DacCum

ООП лаб 3

Sep 17th, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>  
  2. #include <cmath>  
  3.  
  4. #define PI 3.1413
  5.  
  6. using namespace std;
  7.  
  8. class formula {
  9.     public:
  10.         double x,
  11.                y,
  12.                z,
  13.                res;
  14.         bool flag;  
  15.          
  16.         void vvod() {  
  17.             flag = 0;
  18.             cout << "Enter x = ";
  19.             cin >> x;  
  20.             cout << "Enter y = ";
  21.             cin >> y;  
  22.             cout << "Enter z = ";
  23.             cin >> z;  
  24.         }  
  25.      
  26.         void run() {
  27.             if(((fabs(x - y)) * z + x * x) == 0){
  28.                 flag = 1;
  29.                 return;
  30.             }
  31.                
  32.             double acot_x = PI/2. - atan(x);
  33.             res = (5. * acot_x) -
  34.             ((1./4) * acos(x)) *
  35.             ((x + (3. * (fabs(x - y))) + x * x) /
  36.             ((fabs(x - y)) * z + x * x));
  37.         }
  38.          
  39.         void vivod() {  
  40.             if(flag == 1)
  41.                 cout << "Error: denominator = 0" << endl;  
  42.             else
  43.                 cout << "Result = " << res << endl;
  44.         }
  45. };  
  46.        
  47. int main() {  
  48.        
  49.     formula f1;
  50.     f1.vvod();
  51.     f1.run();
  52.     f1.vivod();
  53.    
  54.     formula *pf2 = new formula;
  55.     pf2->vvod();
  56.     pf2->run();
  57.     pf2->vivod();
  58.    
  59.    
  60.    
  61.     return 0;  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement