home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_01
/
1001096a
< prev
next >
Wrap
Text File
|
1991-11-17
|
779b
|
46 lines
Listing 4
//
// rational.cpp
//
#include "rational.h"
rational rational::operator+(rational r)
{
rational result;
result.num = num * r.denom + r.num * denom;
result.denom = denom * r.denom;
return result;
}
rational rational::operator-(rational r)
{
rational result;
result.num = num * r.denom - r.num * denom;
result.denom = denom * r.denom;
return result;
}
rational rational::operator*(rational r)
{
rational result;
result.num = num * r.num;
result.denom = denom * r.denom;
return result;
}
rational rational::operator/(rational r)
{
rational result;
result.num = num * r.denom;
result.denom = denom * r.num;
return result;
}
void rational::put(FILE *f)
{
fprintf(f, "(%ld/%ld)", num, denom);
}