// 复数运算(class) 加,减,乘,除跟输出有做overload
#include<iostream.h>
int Num=0,Den=0;
class rational{
friend ostream &operator<<(ostream &,const rational &); // 做输出overload
public:
rational(int n=2,int d=4){Num_a=n,Den_b=d;} //Constructor
//============加法==============================
rational operator+(const rational &b )
{
int num,den;
den=Den_b*b.Den_b; //通分
num=Num_a*b.Den_b+b.Num_a*Den_b; //分子相加
rational result(num,den); //建立result物件
return result; //传回结果
}
//===========减法=============================
rational operator-(const rational &b)
{
int num,den;
den=Den_b*b.Den_b; //通分
num=Num_a*b.Den_b-b.Num_a*Den_b; //分子相减
rational resu ..
访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容