分数相加的程序改错
#include<iostream>using namespace std;
class number
{
public:
void set_value();
int jia_value();
int jian_value();
void cheng_value();
void chu_value();
private:
int n1;
int m1;
private:
int n2;
int m2;
};
//set
void number::set_value()
{ int n1,m1,m2,n2,q1,q2;
cout<<"please put in n1 and m1 ";
cin>>n1;
cin>>m1;
q1=n1/m1;
cout<<"please put in n2 and m2 ";
cin>>n2;
cin>>m2;
q2=n2/m2;
}
//jia
int number::jia_value()
{ int h(int,float);
int t,r,a;
float A;
if(m1==m2)
cout<<(n1+n2)<<"/"<<m2<<endl;
if(m1!=m2)
{ int hcf(int m1,int m2);
int lcd(int m2,int m1,int h);
}
cout<<n1*((m1*m2/h)/n2)+n2*((m1*m2/h)/n1)<<"/"<<(m1*m2/h)<<endl;
}
//jian
int number::jian_value()
{
int h(int ,int );
int t,r,A,a;
if(m1==m2)
cout<<n1-n2<<"/"<<m2<<endl;
if(m1!=m2)
{ int hcf(int m1,int m2);
int lcd(int m2,int m1,int h);
}
cout<<n1*((m1*m2/h)/n2)+n2*((m1*m2/h)/n1)<<"/"<<(m1*m2/h)<<endl;
}
//cheng
void cheng_value()
{int m1,m2,n1,n2;
cout<<(n1*n2)<<"/"<<(m1*m2);
}
//chu
void chu_value()
{int m1,m2,n1,n2;
cout<<(n1*m2)<<"/"<<(m1*n2)<<endl;
}
int hcf(int m1,int m2)
{int t,r;
if(m1>m2)
{t=m2;m2=m1;m1=t;}
while((r=m2%m1)!=0)
{
m2=m1;
m1=r;
}
return(m1);
}
int lcd(int m2,int m1,int h)
{return(m1*m2/h);}
//main
int main()
{number num;
int T;
int hcf(int m1,int m2);
int lcd(int m2,int m1,int h);
num.set_value();
cout<<"Would you want add?put in 1,please. jian,put in 2. cheng,put in 3. chu,put in 4.";
cin>>T;
if(T==1)
num.jia_value();
if(T==2)
num.jian_value();
if (T==3)
num.cheng_value();
if(T==4)
num.chu_value();
return 0;
}