Смекни!
smekni.com

Реализация класса для работы с комплексными числами (стр. 3 из 3)

20

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;

Complex t(re,im);

return t;

}

Complex operator * (Complex &a, Complex &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;

Complex t(re,im);

return t;

}

Complex operator / (Complex &a, Complex &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;

Complex t(re,im);

return t;

}

}

Complex operator &(Complex &a, Complex &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;

Complex t(n,rn);

return t;

}

Complex operator &&(Complex &a,Complex &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);

21

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;

Complex t(m,k);

return t;

}

Complex operator == (Complex &a,Complex &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;

Complex t(r,f2);

return t;

}

void Complex::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;

}

#include "stdafx.h"

#include "Complex.h"

#include "conio.h"

#include "iostream"

#include "math.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

Complex a;

Complex b;

Complex ob;

a.ShowComplex();

b.ShowComplex();

a+b;

a-b;

a*b;

a/b;

a&b;

a&&b;

a==b;

getch();

return 0;

}

22

Приложение Б (Справочное)

Результаты тестирования

23



24

25