Mail Archives: djgpp/1997/10/30/22:02:24
| From:  | nick <nick14 AT erols DOT com>
 | 
| Newsgroups:  | comp.os.msdos.djgpp
 | 
| Subject:  | I need help with a fraction class
 | 
| Date:  | Thu, 30 Oct 1997 21:33:47 -0800
 | 
| Organization:  | Erol's Internet Services
 | 
| Lines:  | 129
 | 
| Message-ID:  | <34596DBB.6281@erols.com>
 | 
| NNTP-Posting-Host:  | phd-as16s13.erols.com
 | 
| Mime-Version:  | 1.0
 | 
| To:  | djgpp AT delorie DOT com
 | 
| DJ-Gateway:  | from newsgroup comp.os.msdos.djgpp
 | 
This is a multi-part message in MIME format.
--------------590D7AE91634
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I've been working on this for a while and I was hoping someone could 
explain these errors.
--------------590D7AE91634
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="FRACTION.H"
#include "bool.h"
class fractype{
public:
    void write() const;
    float floatequiv();
    void simplify();
    fractype operator*(fractype frac2) const;
    boolean operator==(fractype frac2) const;
    fractype (int initnumer, int initdenom);
private:
    int numer;
    int denom;
};
--------------590D7AE91634
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="FRACTION.CPP"
#include <iostream.h>
#include <stdlib.h>
#include "fraction.h"
int GreatestCommonDivisor( int,int);
fractype::fractype(int initnumer, int initdenom)
{
numer=initnumer;
denom=initdenom;
}
void fraction::write() const;
{
cout<<numer<<'/'<<denom;
}
float fractype::floatequiv() 
{
return float(numer) / float(denom);
}
void fractype::simplify()
{
int gcd;
int absnumer= abs(numer);
if (numer==0 || absnumer==1 || denom==1)
  {
  return;
  }
gcd=GreatestCommonDivisor(absnumer, denom);
if (gcd>1) {
   numer /= gcd;
   denom /=gcd;
  }
}
fractype fractype::operator*(fractype frac2) const
{
int resultnumer = numer * frac2.numer;
int resultdenom = denom * frac2.denom;
fractype resultfrac(resultnumer, resultdenom);
resultfrac.simplify();
return resultfrac;
}
boolean fractype::operator==(fractype frac2) const
{
return (numer==frac2.numer) && (denom==frac2.denom);
}
int GreatestCommonDivisor(int a, int b)
{
int temp = a % b;
while (temp>0) {
a=b;
b=temp;
temp=a%b;
}
return b;
}
--------------590D7AE91634
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="GCC.LOG"
Reading specs from c:/djgpp/lib\specs
gcc version 2.7.2.1
 c:/djgpp/bin\cpp.exe -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=7 -Dunix -Di386 -DGO32 -DMSDOS -DDJGPP=2 -DDJGPP_MINOR=1 -D__unix__ -D__i386__ -D__GO32__ -D__MSDOS__ -D__DJGPP__=2 -D__DJGPP_MINOR__=1 -D__unix -D__i386 -D__GO32 -D__MSDOS -D__DJGPP=2 -D__DJGPP_MINOR=1 fraction.cpp c:/djgpp/tmp\ccbaaaaa
GNU CPP version 2.7.2.1 (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
 c:/djgpp/lang/cxx
 c:/djgpp/include
 c:/djgpp/contrib/grx20/include
 /usr/local/lib/g++-include
 /usr/local/include
 /usr/local/go32/include
 /usr/local/lib/gcc-lib/go32/2.7.2.1/include
 /usr/include
End of search list.
 c:/djgpp/bin\cc1plus.exe c:/djgpp/tmp\ccbaaaaa -quiet -dumpbase fraction.cc -version -o c:/djgpp/tmp\cccaaaaa
GNU C++ version 2.7.2.1 (80386, BSD syntax) compiled by GNU C version 2.7.2.1.
In file included from fraction.cpp:3:
fraction.h:9: syntax error before `operator'
fraction.cpp:13: parse error before `::'
fraction.cpp:50: parse error before `::'
fraction.cpp:51: no `int fractype::operator ==(class fractype) const' member function declared in class `fractype'
--------------590D7AE91634--
- Raw text -