Advertisement
Sanlover

Untitled

Dec 9th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class FazzyNumber
  5. {
  6. double* e1, * x, * e2;
  7.  
  8. public:
  9. FazzyNumber()
  10. {
  11. e1 = new double;
  12. x = new double;
  13. e2 = new double;
  14. cout << endl << "K" << endl;
  15. }
  16. FazzyNumber(double E1, double X, double E2)
  17. {
  18. e1 = new double(E1);
  19. x = new double(X);
  20. e2 = new double(E2);
  21. cout << endl << "K" << endl;
  22. }
  23. FazzyNumber(const FazzyNumber& obj)
  24. {
  25. x = new double;
  26. *x = *obj.x;
  27.  
  28. e1 = new double;
  29. *e1 = *obj.e1;
  30.  
  31. e2 = new double;
  32. *e2 = *obj.e2;
  33.  
  34. cout << endl << "KK" << endl;
  35. }
  36.  
  37. FazzyNumber operator+(const FazzyNumber& obj)
  38. {
  39. FazzyNumber res;
  40. *res.e1 = *x + *obj.x - *e1 - *obj.e1;
  41. *res.x = *x + *obj.x;
  42. *res.e2 = *x + *obj.x + *e2 + *obj.e2;
  43. return res;
  44. }
  45.  
  46. FazzyNumber operator-(const FazzyNumber& obj)
  47. {
  48. FazzyNumber res;
  49. *res.e1 = *x - *obj.x - *e1 - *obj.e1;
  50. *res.x = *x - *obj.x;
  51. *res.e2 = *x - *obj.x + *e2 + *obj.e2;
  52. return res;
  53. }
  54.  
  55. FazzyNumber operator*(const FazzyNumber& obj)
  56. {
  57. FazzyNumber res;
  58. *res.e1 = (*x) * (*obj.x) - (*obj.x) * (*e1) - (*x) * (*obj.e1) + (*e1) * (*obj.e1);
  59. *res.x = (*x) * (*obj.x);
  60. *res.e2 = (*x) * (*obj.x) + (*obj.x) * (*e2) + (*x) * (*obj.e2) + (*e2) * (*obj.e2);
  61. return res;
  62. }
  63.  
  64. FazzyNumber operator/(const FazzyNumber& obj)
  65. {
  66. FazzyNumber res;
  67. *res.e1 = (*x - *e1) / (*obj.x + *obj.e2);
  68. *res.x = *x / *obj.x;
  69. *res.e2 = (*x + *e2) / (*obj.x - *obj.e1);
  70. return res;
  71. }
  72.  
  73. bool operator==(const FazzyNumber& obj)
  74. {
  75. if (*e1 == *obj.e1 && *x == *obj.x && *e2 == *obj.e2)
  76. return true;
  77. else return false;
  78. }
  79.  
  80. bool operator!=(const FazzyNumber& obj)
  81. {
  82. if (*e1 != *obj.e1 && *x != *obj.x && *e2 != *obj.e2)
  83. return true;
  84. else return false;
  85. }
  86.  
  87. FazzyNumber& operator=(const FazzyNumber& obj)
  88. {
  89. *e1 = *obj.e1;
  90. *x = *obj.x;
  91. *e2 = *obj.e2;
  92. return *this;
  93. }
  94.  
  95. friend ostream& operator<<(ostream& out, const FazzyNumber& obj);
  96. friend istream& operator>>(istream& in, const FazzyNumber& obj);
  97.  
  98. ~FazzyNumber()
  99. {
  100. delete e1;
  101. delete x;
  102. delete e2;
  103. cout << endl << "D" << endl;
  104. }
  105. };
  106.  
  107. ostream& operator<<(ostream& out, const FazzyNumber& obj)
  108. {
  109. out << "(" << *obj.e1 << "," << *obj.x << "," << *obj.e2 << ")";
  110. return out;
  111. }
  112.  
  113. istream& operator>>(istream& in, const FazzyNumber& obj)
  114. {
  115. in >> *obj.e1 >> *obj.x >> *obj.e2;
  116. return in;
  117. }
  118.  
  119. int main()
  120. {
  121. setlocale(LC_ALL, "rus");
  122.  
  123. double e1, x, e2;
  124.  
  125. cout << "Введите значения е1, х, е2 для первого нечеткого числа: ";
  126. cin >> e1 >> x >> e2;
  127. FazzyNumber A(e1, x, e2);
  128.  
  129. cout << "Введите значения е1, х, е2 для второго нечеткого числа: ";
  130. cin >> e1 >> x >> e2;
  131. FazzyNumber B(e1, x, e2);
  132.  
  133. char F;
  134.  
  135. do
  136. {
  137. char S;
  138.  
  139. cout << "\n1 - Сумма.\n2 - Разность.\n3 - Умножение.\n4 - Деление.\n5 - Сравнить." << endl;
  140. cin >> S;
  141. switch (S)
  142. {
  143. case '1':
  144. cout << "Сумма: " << A + B << endl;
  145. break;
  146. case '2':
  147. cout << "Разность: " << A - B << endl;
  148. break;
  149. case '3':
  150. cout << "Умножение: " << A * B << endl;
  151. break;
  152. case '4':
  153. cout << "Деление: " << A / B << endl;
  154. break;
  155. case '5':
  156. if (A == B)
  157. cout << "Нечеткие числа равны." << endl;
  158. else cout << "Нечеткие числа не равны." << endl;
  159. break;
  160. }
  161. cout << "\n0 - Выход.\n1 - Продолжить." << endl;
  162. cin >> F;
  163.  
  164. } while (F != '0');
  165.  
  166. return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement