что нужно добавить в программу, чтобы ко всему прочему выводилис на экран комплексные числа z=u+2*v+1, z+5.2?
111.h
Код | #include "iostream" #include "math.h" using namespace std; class Complex { double re, im; Complex() {}; Complex (double r) { re = r; im = 0; } Complex (double r, double i) { re = r; im = i; } Complex (Complex &c) { re = c.re; im = c.im; } ~Complex() {} double abs() { return sqrt(re * re - im * im); } Complex & operator = (Complex &c) { re = c.re; im = c.im; return (*this); } Complex Complex::operator + (Complex &c) { Complex temp; temp.re = re + c.re; temp.im = im + c.re; return temp; } Complex Complex::operator - (Complex &c) { Complex temp; temp.re = re - c.re; temp.im = im - c.re; return temp; } Complex Complex::operator * (Complex &c) { Complex temp; temp.re = re*c.re; temp.im = re*c.im; return temp; } Complex Complex::operator / (Complex &c) { Complex temp; double r = c.re * c.re + c.im * c.im; temp.re = (re * c.re + im * c.im) / r; temp.re = (im * c.re - re * c.im) / r; return temp; } friend ostream &operator<<(ostream &, Complex &); friend istream &operator>>(istream &, Complex &); }; ostream &operator<<(ostream &out, Complex &c) { out << "(" << c.re << ") + I (" << c.im << "\n"; return out; } istream &operator>>(istream &in, Complex &c) { in >> c.re >> c.im; return in; } class ComplexExt { public: friend ComplexExt operator + (Complex &a1, Complex &b1); friend ComplexExt operator - (Complex &a1, Complex &b1); friend ComplexExt operator * (Complex &a1, Complex &b1); friend ComplexExt operator / (Complex &a1, Complex &b1); friend ComplexExt operator & (Complex &a1, Complex &b1); friend ComplexExt operator &&(Complex &a1,Complex &b1); friend ComplexExt operator == (Complex &a1,Complex &b1); void ShowComplex(); public: ComplexExt (void); ComplexExt (double a1, double b1); ~ ComplexExt (void); int n; public: double re; double im; }; ComplexExt:: ComplexExt (void) { } ComplexExt:: ComplexExt (double a, double b) { re=a; im=b; } ComplexExt::~ ComplexExt (void) { } ComplexExt operator + (ComplexExt &a, ComplexExt &b){ double re = a.re + b.re; double im = a.im + b.im; cout << "Summa arif.forma: " << re << " + " << im << "i" << endl; double f1=sqrt(re*re+im*im); double f2=re/f1; double f3=im/f1; cout << "Trigonom summa" << endl; cout << f1 << "(cos(" << f2 << ") + isin(" << f3 << "))" << endl; ComplexExt t(re,im); return t; } ComplexExt operator - (ComplexExt &a, ComplexExt &b){ double re = a.re - b.re; double im = a.im - b.im; cout << "Raznost': " << re << " + " << im << "i" << endl; double f1=sqrt(re*re+im*im); double f2=re/f1; double f3=im/f1; cout << "Trigonom raznost'" << endl; cout << f1 << "(cos(" << f2 << ") + isin(" << f3 << "))" << endl; ComplexExt t(re,im); return t; } ComplexExt operator * (ComplexExt &a, ComplexExt &b){ double re = a.re*b.re - a.im*b.im; double im = a.im*b.re+a.re*b.im; cout << "Proizvedenie: " << re << " + " << im << "i" << endl; double f1=sqrt(re*re+im*im); double f2=re/f1; double f3=im/f1; cout << "Trigonom proiz." << endl; cout << f1 << "(cos(" << f2 << ") + isin(" << f3 << "))" << endl; ComplexExt t(re,im); return t; } ComplexExt operator / (ComplexExt &a, ComplexExt &b){ if(b.re*b.re+b.im*b.im==0) { cout <<"Delenie na 0"; } else{ double re=(a.re*b.re+a.im+b.im)/(b.re*b.re+b.im*b.im); double im=(a.im*b.re-a.re*b.im)/(b.re*b.re+b.im*b.im); cout << "Chasnoe: " << re << " + " << im << "i" << endl; double f1=sqrt(re*re+im*im); double f2=re/f1; double f3=im/f1; cout << "Trigonom chastnoe" << endl; cout << f1 << "(cos(" << f2 << ") + isin(" << f3 << "))" << endl; ComplexExt t(re, im); return t; } } ComplexExt operator &( ComplexExt &a, ComplexExt &b){ int n; cout << "Vvedite chislo stepeni:" << endl; cin >> n; double r=sqrt(a.re*a.re+a.im*a.im); double rn=pow(2,r); double f2=n*a.re/rn; double f3=n*a.im/rn; cout << "Trigonom form vozvedenie v stepen' a:" << endl; cout << rn << "(cos(" << f2 << ") + isin(" << f3 << "))" << endl; ComplexExt t(n,rn); return t; } ComplexExt operator &&( ComplexExt &a, ComplexExt &b){ int m; int k; cout << "Vvedite chislo ctepeni korny:" << endl; cin >> m; cout << "Vvedite nomer korny:" << endl; cin >> k; double r=sqrt(a.re*a.re+a.im*a.im); double rn=pow(2,r); double f1=(m*a.re/rn+2*3,14*k)/m; double f2=(m*a.im/rn+2*3.14*k)/m; cout << "Trigonom form vyshislenie korny a:" << endl; cout << rn << "(cos(" << f1 << ") + isin(" << f2 << "))" << endl; ComplexExt t(m,k); return t; } ComplexExt operator == (ComplexExt &a, ComplexExt &b){ double r=sqrt(a.re*a.re+a.im*a.im); double f2=a.re/r; cout << "Eksponenta a:" << endl; cout << r << "e^(i*" << f2 << ")" << endl; ComplexExt t(r,f2); return t; } void ComplexExt::ShowComplex(){ cout << "Vvedite chislo" <<endl; cin >> re; cin >> im; cout << "Arif. forma: " << re << " + " << im << "i" << endl; double z=sqrt(re*re+im*im); cout << "Modul' shisla:" << z << endl; cout << "Trigonom form" << endl; double f=re/z; double f1=im/z; cout << z << "(cos(" << f << ") + isin(" << f1 << "))" << endl; }
|
cpp
Код | #include "111.h" #include "conio.h" #include "iostream" #include "math.h" using namespace std; int main() { ComplexExt u; ComplexExt v; ComplexExt z; u.ShowComplex(); v.ShowComplex(); u+v; u-v; u*v; u/v; u&v; u&&v; u==v; getch(); return 0; }
|
|