Advertisement
Vladislav_Bezruk

Untitled

Nov 20th, 2021
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.35 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<cmath>
  4.  
  5. #define M_PI 3.14159265358979323846
  6.  
  7. using namespace std;
  8.  
  9. class CalcObject {
  10. protected:
  11.     double calcPar;
  12. public:
  13.     virtual void set() = 0;
  14.     virtual void get() = 0;
  15.     virtual void calc() = 0;
  16.     virtual void getResult() = 0;
  17. };
  18. class Rozbriz : public CalcObject {
  19. private:
  20.     double P, w, S_otv, m, R, g, del_S, H;
  21. public:
  22.     Rozbriz() { P = w = S_otv = m = R = g = del_S = H = 0; }
  23.     Rozbriz(double _P, double _w, double _S_otv, double _m, double _R, double _g, double _del_S, double _H) :P(_P), w(_w), S_otv(_S_otv), m(_m), R(_R), g(_g), del_S(_del_S), H(_H) {}
  24.     Rozbriz(const Rozbriz& x) {
  25.         P = x.P;
  26.         w = x.w;
  27.         S_otv = x.S_otv;
  28.         m = x.m;
  29.         R = x.R;
  30.         g = x.g;
  31.         del_S = x.del_S;
  32.         H = x.H;
  33.     }
  34.     void set() {
  35.         cout << "Enter info: " << endl;
  36.         cout << "P = ";     cin >> P;
  37.         cout << "w = ";     cin >> w;
  38.         cout << "S_otv = "; cin >> S_otv;
  39.         cout << "m = ";     cin >> m;
  40.         cout << "R = ";     cin >> R;
  41.         cout << "g = ";     cin >> g;
  42.         cout << "del_S = "; cin >> del_S;
  43.         cout << "H = ";     cin >> H;
  44.         cout << endl;
  45.     }
  46.     void get() {
  47.         cout << "Info " << endl;
  48.         cout << "P = " << P;
  49.         cout << "w = " << w;
  50.         cout << "S_otv = " << S_otv;
  51.         cout << "m = " << m;
  52.         cout << "R = " << R;
  53.         cout << "g = " << g;
  54.         cout << "del_S = " << del_S;
  55.         cout << "H = " << H;
  56.         cout << endl;
  57.     }
  58.     void calc() {
  59.         calcPar = 2. / 3 * ((M_PI * P * pow(w, 2) * S_otv * m * pow(R, 3)) / (g * del_S)) * pow(pow(w, 2) * pow(R, 2) + 2 * g * H, 3. / 2);
  60.  
  61.     }
  62.     void getResult() {
  63.         cout << "Calculeted parameter: " << calcPar << endl;
  64.     }
  65.     Rozbriz& operator = (const Rozbriz& x) {
  66.         P = x.P;
  67.         w = x.w;
  68.         S_otv = x.S_otv;
  69.         m = x.m;
  70.         R = x.R;
  71.         g = x.g;
  72.         del_S = x.del_S;
  73.         H = x.H;
  74.         return *this;
  75.     }
  76.     bool operator == (const Rozbriz& x) { return calcPar == x.calcPar; }
  77.     bool operator != (const Rozbriz& x) { return calcPar != x.calcPar; }
  78.     bool operator > (const Rozbriz& x) { return calcPar > x.calcPar; }
  79.     bool operator >= (const Rozbriz& x) { return calcPar >= x.calcPar; }
  80.     bool operator < (const Rozbriz& x) { return calcPar < x.calcPar; }
  81.     bool operator <= (const Rozbriz& x) { return calcPar <= x.calcPar; }
  82.  
  83.     friend ifstream& operator >> (ifstream& ifs, Rozbriz& x);
  84.     friend ofstream& operator << (ofstream& ofs, Rozbriz& x);
  85.     friend istream& operator >> (istream& is, Rozbriz& x);
  86.     friend ostream& operator << (ostream & os, Rozbriz& x);
  87. };
  88.  
  89.     ifstream& operator >> (ifstream& ifs, Rozbriz& x) {
  90.         ifs >> x.P >> x.w >> x.S_otv >> x.m >> x.R >> x.g >> x.del_S >> x.H;
  91.         return ifs;
  92.     }
  93.    
  94.     ofstream& operator << (ofstream& ofs, Rozbriz& x) {
  95.         cout << "Info " << endl;
  96.         cout << "P = " << x.P;
  97.         cout << "w = " << x.w;
  98.         cout << "S_otv = " << x.S_otv;
  99.         cout << "m = " << x.m;
  100.         cout << "R = " << x.R;
  101.         cout << "g = " << x.g;
  102.         cout << "del_S = " << x.del_S;
  103.         cout << "H = " << x.H;
  104.         cout << endl;
  105.         return ofs;
  106.     }
  107.    
  108.     istream& operator >> (istream& is, Rozbriz& x) {
  109.  
  110.         cout << "Info " << endl;
  111.         cout << "P = ";     is >> x.P;
  112.         cout << "w = ";     is >> x.w;
  113.         cout << "S_otv = "; is >> x.S_otv;
  114.         cout << "m = ";     is >> x.m;
  115.         cout << "R = ";     is >> x.R;
  116.         cout << "g = ";     is >> x.g;
  117.         cout << "del_S = "; is >> x.del_S;
  118.         cout << "H = ";     is >> x.H;
  119.         cout << endl;
  120.         return is;
  121.     }
  122.  
  123.     ostream& operator << (ostream & os, Rozbriz& x) {
  124.         os << "Info " << endl;
  125.         os << "P = " << x.P << endl;
  126.         os << "w = " << x.w << endl;
  127.         os << "S_otv = " << x.S_otv << endl;
  128.         os << "m = " << x.m << endl;
  129.         os << "R = " << x.R << endl;
  130.         os << "g = " << x.g << endl;
  131.         os << "del_S = " << x.del_S << endl;
  132.         os << "H = " << x.H << endl;
  133.         os << endl;
  134.         return os;
  135.     }
  136.  
  137.    
  138.     int main() {
  139.         cout << "###Constructor test###" << endl;
  140.         Rozbriz x;
  141.         cout << "Default constructor: " << endl << x;
  142.         Rozbriz y(1000, 100, 0.000001, 0.65, 0.15, 9.81, 0.0001, 0.3);
  143.         y.calc();
  144.         cout << "Init constructor: " << endl << y;
  145.         Rozbriz z = y;
  146.         cout << "Copy constructor: " << endl << z;
  147.         cout << "###Functions test###" << endl << endl;
  148.         cout << "Set function:" << endl;
  149.         x.set();
  150.         cout << "Get function:" << endl;
  151.         x.get();
  152.         x.calc();
  153.         cout << "Result function:" << endl;
  154.         x.getResult();
  155.         cout << "###Operators test###" << endl << endl;
  156.         cout << "x object:" << endl;
  157.         x.get();
  158.         cout << "y object:" << endl;
  159.         y.get();
  160.         cout << "Operator == between obj x & y" << endl;
  161.         cout << "result = " << boolalpha << (x == y) << endl << endl;
  162.         cout << "Operator != between obj x & y" << endl;
  163.         cout << "result = " << boolalpha << (x != y) << endl << endl;
  164.  
  165.         cout << "Operator < between obj x & y" << endl;
  166.         cout << "result = " << boolalpha << (x < y) << endl << endl;
  167.  
  168.         cout << "Operator <= between obj x & y" << endl;
  169.         cout << "result = " << boolalpha << (x <= y) << endl << endl;
  170.         cout << "Operator > between obj x & y" << endl;
  171.         cout << "result = " << boolalpha << (x > y) << endl << endl;
  172.  
  173.         cout << "Operator >= between obj x & y" << endl;
  174.         cout << "result = " << boolalpha << (x >= y) << endl << endl;
  175.  
  176.         cout << "Operator = between obj x & y" << endl;
  177.         x = y;
  178.         cout << "x object:" << endl;
  179.         x.get();
  180.         cout << "y object:" << endl;
  181.         y.get();
  182.         Rozbriz a;
  183.         ifstream ifs("C:\\Users\\ekate\\source\\repos\\Course1\\in.txt");
  184.         ofstream ofs("C:\\Users\\ekate\\source\\repos\\Course1\\out.txt");
  185.         ifs >> a;
  186.         a.calc();
  187.         cout << a;
  188.         ofs << a;
  189.         ofs << a.calc();
  190.  
  191.         return 0;
  192.     }
  193.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement