operator overloading and inheritance problem

I have already write a fraction class,then I want to write a integer class,I hope I didn't need to write all the operator overloading function again(duplicatedefinition).
But I have some trouble doing that,could you help me correct my program,thank you very much.
Can I just let the denominator=1,then numerator will the same as an integer.
#include<iostream>
using namespace std;

class fraction
{
int fmu,fzi;//fmu is denominator,fzi is numerator
public:
fraction(){}
fraction(int fz,int fm=1)
{
fmu=fm;
fzi=fz;
}
void get(int &z,int &m);
void tongfen(int &z1,int &m1,int &z2,int &m2);
fraction yuefen(int &fz,int &fm);
fraction daoshu(int &fz,int &fm);

fraction operator+(const fraction&);
fraction operator-(const fraction&);
fraction operator*(const fraction&);
fraction operator/(const fraction&);
//fraction operator>(const fraction&);
//fraction operator<(const fraction&);

friend int operator ==(const fraction&,const fraction&);
friend int operator !=(const fraction&,const fraction&);
friend int operator >=(const fraction&,const fraction&);
friend int operator <=(const fraction&,const fraction&);

void print();
};

void fraction::tongfen(int &z1,int &m1,int &z2,int &m2)
{
int fm,fz;
fm=m1*m2;
fz=z1*z2;
fraction::yuefen(fz,fm);/////
}

fraction fraction::yuefen(int &fz,int &fm)
{
int a=fm,b=fz;
int r=a%b;
while(r!=0)
{
a=b;
b=r;
r=a%b;
}
r=b;
b=fz/r;
a=fm/r;
fraction yue(b,a);
return yue;
}

fraction fraction::daoshu(int &fz,int &fm)
{
return fraction(fm,fz);
}

fraction fraction::operator*(const fraction& c)
{
int z=c.fzi*fzi;
int m=c.fmu*fmu;
fraction x=yuefen(z,m);
return x;
}

fraction fraction::operator /(const fraction& c)
{
int z=c.fmu*fzi;
int m=c.fzi*fmu;
fraction x=yuefen(z,m);
return x;
}

fraction fraction::operator +(const fraction& c)
{
int z=(c.fzi*fmu+fzi*c.fmu);
int m=(c.fmu*fmu);
fraction x=yuefen(z,m);
return x;
}

fraction fraction::operator -(const fraction& c)
{
int z=(fzi*c.fmu-c.fzi*fmu);
int m=(c.fmu*fmu);
fraction x=yuefen(z,m);

return x;
}

void fraction::print()
{
cout<<fzi<<"/"<<fmu<<endl;
}

class integer:public fraction//(int fz,int fm/* =1 */)
{
int i;
//const int j=1;
public:
integer(){}
integer(int z,int m=1)
{
i=z;
}
//int digit_number();
void print();
};

void integer::print()
{
cout<<i<<endl;
}

void main()
{
int x,y;
cin>>x>>y;
integer in1(x),in2(y);
integer ina,inb,inc,ind;
ina=in1+in2;
ina.print();

int a,b,c,d;
cin>>a>>b>>c>>d;
fraction f1(a,b),f2(c,d);
fraction fa,fb,fc,fd;
fa=f1+f2;
fa.print();
fb=f1-f2;
fb.print();
fc=f1*f2;
fc.print();
fd=f1/f2;
fd.print();
}
no reply...~~~>_<~~~
Maybe if you asked an actual question or told us what the problem was we'd be more inclined to help.
Topic archived. No new replies allowed.