#include<iostream>
using namespace std;
class fenshu{
public:
fenshu(){son=0;mom=0;} //构造函数
fenshu(double s,double m){son=s;mom=m;}
fenshu operator +(fenshu &f2); //运算符重载
fenshu operator -(fenshu &f2);
fenshu operator *(fenshu &f3);
fenshu operator /(fenshu &f4);
friend ostream& operator <<(ostream&,fenshu&); //对<< >>重载
friend istream& operator >>(istream&,fenshu&);
double yuefen(double,double); //约分函数
double guifan(double,double); //规范化函数
public:
double son;
double mom;
};
fenshu fenshu::operator + (fenshu &f2) //+重载
{return fenshu(son*f2.mom+f2.son*mom,mom*f2.mom);}
fenshu fenshu::operator - (fenshu &f2) //-重载
{return fenshu(son*f2.mom-f2.son*mom,mom*f2.mom);}
fenshu fenshu::operator * (fenshu &f2) //×重载
{return fenshu(son*f2.son,mom*f2.mom);}
fenshu fenshu::operator / (fenshu &f2) //除
{return fenshu(son*f2.mom,mom*f2.son);}
double fenshu::yuefen(double,double){
double a,b,t;
a=son;
b=mom;
do{
if(a>b)
{t=a-b;
a=t;};
if(b>a)
{t=b-a;
t=b;};
}while(a=b);
return(son/a,mom/b);
}
double fenshu::guifan(double,double){
double q,w;
q=son,w=mom;
if(q>0,w<0||q<0,w<0)
{q=-q;
w=-w;}
return(q,w);}
ostream& operator <<(ostream& output,fenshu&f)
{output<<"("<<f.son<<"/"<<f.mom<<")";
return output;}
istream& operator >>(istream& input,fenshu&f)
{cout<<"请输入分数的分子分母:";
input>>f.son>>f.mom;
return input;
}
int main(){
fenshu f1,f2,f3;
int x;
cin>>f1>>f2;
cout<<"您需要进行的操作是(1+,2-,3*,4/)"<<endl;
cin>>x;
if(x=1)
{ f3=f1+f2;
f3.yuefen;
f3.guifan;
}
if(x=2)
{ f3=f1-f2;
f3.yuefen;
f3.guifan;
}
if(x=3)
{ f3=f1*f2;
f3.yuefen;
f3.guifan;
}
if(x=4)
{ f3=f1/f2;
f3.yuefen;
f3.guifan;}
cout<<f3;
return 0;
}
std:: 这个怎么加?在哪?
std:: friend ostream& operator <<(ostream&,fenshu&);是这样写吗?
在实现的时候。 std:: ostream& operator using namespace std::改为#ingclude
虽然好多了,但还是编译不行,还是有error C2593: 'operator >>。能帮忙解决下这个吗?
追答我的编译器上没问题啊。。。你用的什么编译器??我看看
追问vc6.0
追答我用的minGw上面没有错误,,要不然远程下我看看
本回答被提问者和网友采纳求高手帮忙挑下c++程序错误,程序如下 error C2593: 'operator >>。顺便...
你再试试 ===>在重载operrator<<和>>前加上std::或者#ingclude<iostream> using namespace std::改为#ingclude<iostream.h>
...is ambiguoe error C2593: 'operator >>' is ambiguous
class storehouse{ int mutex; int count; int max; void save(){ int changed=false; while(changed==false){ changed=true; enter(mutex); if(count<max)count++; else changed=false; leave(mutex); sleep(0); } } void sell(){ ...
error C2593: 'operator >>' is ambiguous 是什么原因啊vc6.0的_百 ...
操作符 >> 的定义不明确或有歧义 你看下是不是重载时出问题了