Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cmath>
- #define M_PI 3.14159265358979323846
- using namespace std;
- class CalcObject {
- protected:
- double calcPar;
- public:
- virtual void set() = 0;
- virtual void get() = 0;
- virtual void calc() = 0;
- virtual void getResult() = 0;
- };
- class Rozbriz : public CalcObject {
- private:
- double P, w, S_otv, m, R, g, del_S, H;
- public:
- Rozbriz() { P = w = S_otv = m = R = g = del_S = H = 0; }
- 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) {}
- Rozbriz(const Rozbriz& x) {
- P = x.P;
- w = x.w;
- S_otv = x.S_otv;
- m = x.m;
- R = x.R;
- g = x.g;
- del_S = x.del_S;
- H = x.H;
- }
- void set() {
- cout << "Enter info: " << endl;
- cout << "P = "; cin >> P;
- cout << "w = "; cin >> w;
- cout << "S_otv = "; cin >> S_otv;
- cout << "m = "; cin >> m;
- cout << "R = "; cin >> R;
- cout << "g = "; cin >> g;
- cout << "del_S = "; cin >> del_S;
- cout << "H = "; cin >> H;
- cout << endl;
- }
- void get() {
- cout << "Info " << endl;
- cout << "P = " << P;
- cout << "w = " << w;
- cout << "S_otv = " << S_otv;
- cout << "m = " << m;
- cout << "R = " << R;
- cout << "g = " << g;
- cout << "del_S = " << del_S;
- cout << "H = " << H;
- cout << endl;
- }
- void calc() {
- 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);
- }
- void getResult() {
- cout << "Calculeted parameter: " << calcPar << endl;
- }
- Rozbriz& operator = (const Rozbriz& x) {
- P = x.P;
- w = x.w;
- S_otv = x.S_otv;
- m = x.m;
- R = x.R;
- g = x.g;
- del_S = x.del_S;
- H = x.H;
- return *this;
- }
- bool operator == (const Rozbriz& x) { return calcPar == x.calcPar; }
- bool operator != (const Rozbriz& x) { return calcPar != x.calcPar; }
- bool operator > (const Rozbriz& x) { return calcPar > x.calcPar; }
- bool operator >= (const Rozbriz& x) { return calcPar >= x.calcPar; }
- bool operator < (const Rozbriz& x) { return calcPar < x.calcPar; }
- bool operator <= (const Rozbriz& x) { return calcPar <= x.calcPar; }
- friend ifstream& operator >> (ifstream& ifs, Rozbriz& x);
- friend ofstream& operator << (ofstream& ofs, Rozbriz& x);
- friend istream& operator >> (istream& is, Rozbriz& x);
- friend ostream& operator << (ostream & os, Rozbriz& x);
- };
- ifstream& operator >> (ifstream& ifs, Rozbriz& x) {
- ifs >> x.P >> x.w >> x.S_otv >> x.m >> x.R >> x.g >> x.del_S >> x.H;
- return ifs;
- }
- ofstream& operator << (ofstream& ofs, Rozbriz& x) {
- cout << "Info " << endl;
- cout << "P = " << x.P;
- cout << "w = " << x.w;
- cout << "S_otv = " << x.S_otv;
- cout << "m = " << x.m;
- cout << "R = " << x.R;
- cout << "g = " << x.g;
- cout << "del_S = " << x.del_S;
- cout << "H = " << x.H;
- cout << endl;
- return ofs;
- }
- istream& operator >> (istream& is, Rozbriz& x) {
- cout << "Info " << endl;
- cout << "P = "; is >> x.P;
- cout << "w = "; is >> x.w;
- cout << "S_otv = "; is >> x.S_otv;
- cout << "m = "; is >> x.m;
- cout << "R = "; is >> x.R;
- cout << "g = "; is >> x.g;
- cout << "del_S = "; is >> x.del_S;
- cout << "H = "; is >> x.H;
- cout << endl;
- return is;
- }
- ostream& operator << (ostream & os, Rozbriz& x) {
- os << "Info " << endl;
- os << "P = " << x.P << endl;
- os << "w = " << x.w << endl;
- os << "S_otv = " << x.S_otv << endl;
- os << "m = " << x.m << endl;
- os << "R = " << x.R << endl;
- os << "g = " << x.g << endl;
- os << "del_S = " << x.del_S << endl;
- os << "H = " << x.H << endl;
- os << endl;
- return os;
- }
- int main() {
- cout << "###Constructor test###" << endl;
- Rozbriz x;
- cout << "Default constructor: " << endl << x;
- Rozbriz y(1000, 100, 0.000001, 0.65, 0.15, 9.81, 0.0001, 0.3);
- y.calc();
- cout << "Init constructor: " << endl << y;
- Rozbriz z = y;
- cout << "Copy constructor: " << endl << z;
- cout << "###Functions test###" << endl << endl;
- cout << "Set function:" << endl;
- x.set();
- cout << "Get function:" << endl;
- x.get();
- x.calc();
- cout << "Result function:" << endl;
- x.getResult();
- cout << "###Operators test###" << endl << endl;
- cout << "x object:" << endl;
- x.get();
- cout << "y object:" << endl;
- y.get();
- cout << "Operator == between obj x & y" << endl;
- cout << "result = " << boolalpha << (x == y) << endl << endl;
- cout << "Operator != between obj x & y" << endl;
- cout << "result = " << boolalpha << (x != y) << endl << endl;
- cout << "Operator < between obj x & y" << endl;
- cout << "result = " << boolalpha << (x < y) << endl << endl;
- cout << "Operator <= between obj x & y" << endl;
- cout << "result = " << boolalpha << (x <= y) << endl << endl;
- cout << "Operator > between obj x & y" << endl;
- cout << "result = " << boolalpha << (x > y) << endl << endl;
- cout << "Operator >= between obj x & y" << endl;
- cout << "result = " << boolalpha << (x >= y) << endl << endl;
- cout << "Operator = between obj x & y" << endl;
- x = y;
- cout << "x object:" << endl;
- x.get();
- cout << "y object:" << endl;
- y.get();
- Rozbriz a;
- ifstream ifs("C:\\Users\\ekate\\source\\repos\\Course1\\in.txt");
- ofstream ofs("C:\\Users\\ekate\\source\\repos\\Course1\\out.txt");
- ifs >> a;
- a.calc();
- cout << a;
- ofs << a;
- ofs << a.calc();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement