Text: |
ФІО = Горбаченко для Бунтова
Запитання:/*
Переписал для тебя как НЕ ПРОЕКТ. Все работает. Проверь правильность деления.
*/
#include <cstdlib>
#include <iostream>
using namespace std;
class Complex
{
private:
double real;
double image;
public:
Complex :: Complex () {}
Complex :: Complex (double r) { real = r; image = 0; }
Complex :: Complex(double r, double i) { real = r, image = i; }
void Complex :: Enter(){
cout<<"Enter real = "; cin>>real;
cout<<"Enter image = "; cin>>image;
}
void Complex :: Show(){
cout<<" Real = "<<real<<" ; image = "<<image<<endl;
}
Complex Complex :: operator / (Complex z){
Complex temp;
double a=real,b=image,c=z.real,d=z.image;
temp.real=(a*c+b*d)/(c*c+d*d);
temp.image=(b*c+a*d)/(c*c+d*d);
return temp;
}
Complex Complex :: operator + (Complex b){
Complex temp;
temp.real=real+b.real;
temp.image=image+b.image;
return temp;
}
Complex Complex :: operator - (Complex b){
Complex temp;
temp.real=real-b.real;
temp.image=image-b.image;
return temp;
}
Complex Complex :: operator * (Complex b){
Complex temp;
temp.real=real*b.real-image*b.image;
temp.image=real*b.image+image*b.real;
return temp;
}
};
int main(int argc, char *argv[])
{
Complex c1, c2, c3;
c1.Enter();
c2.Enter();
c1.Show();
c2.Show();
cout<<endl;
cout<<endl;
c3=c1+c2;
c3.Show();
c3=c1-c2;
c3.Show();
c3=c1*c2;
c3.Show();
c3=c1/c2;
c3.Show();
system("PAUSE");
return EXIT_SUCCESS;
}
====================================
|