Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class FazzyNumber
- {
- double* e1, * x, * e2;
- public:
- FazzyNumber()
- {
- e1 = new double;
- x = new double;
- e2 = new double;
- cout << endl << "K" << endl;
- }
- FazzyNumber(double E1, double X, double E2)
- {
- e1 = new double(E1);
- x = new double(X);
- e2 = new double(E2);
- cout << endl << "K" << endl;
- }
- FazzyNumber(const FazzyNumber& obj)
- {
- x = new double;
- *x = *obj.x;
- e1 = new double;
- *e1 = *obj.e1;
- e2 = new double;
- *e2 = *obj.e2;
- cout << endl << "KK" << endl;
- }
- FazzyNumber operator+(const FazzyNumber& obj)
- {
- FazzyNumber res;
- *res.e1 = *x + *obj.x - *e1 - *obj.e1;
- *res.x = *x + *obj.x;
- *res.e2 = *x + *obj.x + *e2 + *obj.e2;
- return res;
- }
- FazzyNumber operator-(const FazzyNumber& obj)
- {
- FazzyNumber res;
- *res.e1 = *x - *obj.x - *e1 - *obj.e1;
- *res.x = *x - *obj.x;
- *res.e2 = *x - *obj.x + *e2 + *obj.e2;
- return res;
- }
- FazzyNumber operator*(const FazzyNumber& obj)
- {
- FazzyNumber res;
- *res.e1 = (*x) * (*obj.x) - (*obj.x) * (*e1) - (*x) * (*obj.e1) + (*e1) * (*obj.e1);
- *res.x = (*x) * (*obj.x);
- *res.e2 = (*x) * (*obj.x) + (*obj.x) * (*e2) + (*x) * (*obj.e2) + (*e2) * (*obj.e2);
- return res;
- }
- FazzyNumber operator/(const FazzyNumber& obj)
- {
- FazzyNumber res;
- *res.e1 = (*x - *e1) / (*obj.x + *obj.e2);
- *res.x = *x / *obj.x;
- *res.e2 = (*x + *e2) / (*obj.x - *obj.e1);
- return res;
- }
- bool operator==(const FazzyNumber& obj)
- {
- if (*e1 == *obj.e1 && *x == *obj.x && *e2 == *obj.e2)
- return true;
- else return false;
- }
- bool operator!=(const FazzyNumber& obj)
- {
- if (*e1 != *obj.e1 && *x != *obj.x && *e2 != *obj.e2)
- return true;
- else return false;
- }
- FazzyNumber& operator=(const FazzyNumber& obj)
- {
- *e1 = *obj.e1;
- *x = *obj.x;
- *e2 = *obj.e2;
- return *this;
- }
- friend ostream& operator<<(ostream& out, const FazzyNumber& obj);
- friend istream& operator>>(istream& in, const FazzyNumber& obj);
- ~FazzyNumber()
- {
- delete e1;
- delete x;
- delete e2;
- cout << endl << "D" << endl;
- }
- };
- ostream& operator<<(ostream& out, const FazzyNumber& obj)
- {
- out << "(" << *obj.e1 << "," << *obj.x << "," << *obj.e2 << ")";
- return out;
- }
- istream& operator>>(istream& in, const FazzyNumber& obj)
- {
- in >> *obj.e1 >> *obj.x >> *obj.e2;
- return in;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- double e1, x, e2;
- cout << "Введите значения е1, х, е2 для первого нечеткого числа: ";
- cin >> e1 >> x >> e2;
- FazzyNumber A(e1, x, e2);
- cout << "Введите значения е1, х, е2 для второго нечеткого числа: ";
- cin >> e1 >> x >> e2;
- FazzyNumber B(e1, x, e2);
- char F;
- do
- {
- char S;
- cout << "\n1 - Сумма.\n2 - Разность.\n3 - Умножение.\n4 - Деление.\n5 - Сравнить." << endl;
- cin >> S;
- switch (S)
- {
- case '1':
- cout << "Сумма: " << A + B << endl;
- break;
- case '2':
- cout << "Разность: " << A - B << endl;
- break;
- case '3':
- cout << "Умножение: " << A * B << endl;
- break;
- case '4':
- cout << "Деление: " << A / B << endl;
- break;
- case '5':
- if (A == B)
- cout << "Нечеткие числа равны." << endl;
- else cout << "Нечеткие числа не равны." << endl;
- break;
- }
- cout << "\n0 - Выход.\n1 - Продолжить." << endl;
- cin >> F;
- } while (F != '0');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement