标题:[讨论]有问题讨论
取消只看楼主
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
 问题点数:0 回复次数:2 
[讨论]有问题讨论

我这个问题讨论想要发很久了,苦于老是发不上来所以一直没能发
源代码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的类向导使我当前的类能够使用这个类

搜索更多相关主题的帖子: 源代码 MyComplex real image include 
2006-03-05 09:29
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
得分:0 

这么说的话是不是说得类的定义与实现是不是一定要放在一个文件里呢?
那我的问题就是如何创建自己的编译库 mentioned by knocker;
那么那种iostream.h是怎么实现的呢?
有这么一个问题,我们的老师一直提倡我们将定义与实现分开最后居然办不到,我想这不太对
我想知道为什么?


http://kongfuziandlife. http://codeanddesign.
2006-03-05 19:33
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
得分:0 
thanks to kai
for detailed instructions

http://kongfuziandlife. http://codeanddesign.
2006-03-06 10:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-48486-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.451437 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved