Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Разработать класс «комплексное число», конструктор(ы) для
- инициализации, перегруженные операторы << и >> потокового ввода/вывода,
- перегруженную операцию * умножения двух комплексных чисел как метода
- (функцию-член класса), перегруженную операцию ~ получения комплексно-
- сопряженного числа как метода (функцию-друг класса). В функции main
- организовать тестирование всех возможностей разработанного класса.*/
- #include <iostream>
- using namespace std;
- class Complex
- {
- private:
- float re, im;
- public:
- Complex(float Re, float Im) { re = Re, im = Im; }
- Complex() { re = 0., im = 0.; }
- friend istream& operator >> (istream& s, Complex& C);
- friend ostream& operator << (ostream& s, Complex C);
- Complex operator + (Complex A) { Complex B; B.re = re + A.re; B.im = im + A.re; return B; }
- friend Complex operator~ (Complex A) { A.im = -A.im; return A; }
- };
- istream& operator >> (istream& s, Complex& C) { return s >> C.re >> C.im; }
- ostream& operator << (ostream& s, Complex C) { return s << "(" << C.re << "," << C.im << "i" << ")" << endl; }
- int main()
- {
- Complex A(1, 1), B, C, D;
- cout << A;
- cin >> B;
- cout << B;
- C = A + B;
- D = ~B;
- cout << C << D;
- cout << (~A);
- cout << A;
- return 0;
- }
Add Comment
Please, Sign In to add comment