previous | start | next

A Class for a Fraction Type

#ifndef FRACTION_H
#define FRACTION_H

#include <iostream>
#include <string>

using namespace std;

class Fraction
{
  int n; // numerator
  int d; // denominator
public:
  Fraction();  // n = 0, d = 1
  Fraction(int nval, int dval);

  Fraction  operator+(const Fraction& f) const;
  Fraction  operator-(const Fraction& f) const;
  Fraction  operator*(const Fraction& f) const;
  Fraction  operator/(const Fraction& f) const;

  int getNumerator() const;
  int getDenominator() const;

  void reduce();
};
#endif

What's going on with all those const qualifiers?



previous | start | next