我这个问题讨论想要发很久了,苦于老是发不上来所以一直没能发
源代码kai已经修改过的没有什么问题
但是请看清我的问题
#include <iostream>
#include <cstdlib>
using namespace std;
template<class T>
class MyComplex
{
private:
T real;
T image;
public:
MyComplex()
{
real = 0;
image = 0;
}
MyComplex(T r,T i)
{
real=r;
image=i;
}
T getReal(){return real;}
T getImage(){return image;}
friend MyComplex<T> operator+(const MyComplex<T> & a, const MyComplex<T> & b)
{
T r = a.real + b.real;
T i = a.image + b.image;
MyComplex<T> temp(r, i);
return temp;
}
friend MyComplex<T> operator-(const MyComplex<T> & a, const MyComplex<T> & b)
{
T r = a.real - b.real;
T i = a.image - b.image;
MyComplex<T> temp(r, i);
return temp;
}
friend MyComplex<T> operator*(const MyComplex<T> & a, const MyComplex<T> & b)
{
T r = a.real*b.real-a.image*b.image;
T i = a.real*b.image+a.image*b.real;
MyComplex<T> temp(r, i);
return temp;
}
friend MyComplex<T> operator/(const MyComplex<T> & a, const MyComplex<T> & b)
{
T r = (a.real*b.real+a.image*b.image)/(b.real*b.real+b.image*b.image);
T i = (b.real*a.image-a.real*b.image)/(b.real*b.real+b.image*b.image);
MyComplex<T> temp(r, i);
return temp;
}
friend ostream & operator<<(ostream & output, const MyComplex<T> & c)
{
if(c.image > 0)
output<<c.real<<"+"<<c.image<<"i";
else if(c.image == 0)
output<<c.real;
else if(c.image < 0)
output<<c.image<<c.image<<"i";
return output;
}
};
int main()
{
MyComplex <double> a(12.3, -12.5);
MyComplex <double> b(1.0, 2.0);
MyComplex <double> c1 = a + b;
MyComplex <double> c2 = a - b;
MyComplex <double> c3 = a * b;
MyComplex <double> c4 = a / b;
cout<<a<<endl;
cout<<b<<endl;
cout<<c1<<endl;
cout<<c2<<endl;
cout<<c3<<endl;
cout<<c4<<endl;
system("pause");
return 0;
}
我的问题是
1。要将其分为三个部分分别实现。头文件,类的实现,测试
也就是complex.h complex.cpp main.cpp
知道我的意思吧
2。就是 如何将其加入一个mfc的类向导使我当前的类能够使用这个类