Here is my assignment:
"Define a class for rational numbers. A rational number is a number that can be expressed as the quotient of two integers. For example, ½, ¾, 64/2, and so forth are all rational numbers. (By ½ and so on we mean the every day fraction, not the integer division this expression would produce in a C++ program.) Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Call the class Rational. Include a constructor with two arguments that can be used to set the member variables of an object to any legitimate values. Also, include a constructor that has only a single parameter of type int; call this single parameter wholeNumber and define the constructor so that the object will be initialized to the rational number wholeNumber/1. Include a default constructor that initializes an object to 0 (that is, to 0/1). Overload the input and output operators >> and <<. Numbers are to be input and output in the form ½, 15/32, 300/401, and so forth. Note that the numerator, the denominator, or both may contain a minus sign, so -1/2, 15/-32, and -300/-401 are also possible inputs. Overload all the following operators so that they correctly apply to the type Rational: ==, <, <=, >,>=, +, -, *, and /. Write a test program to test your class. Hints: two rational numbers a/b and c/d are equal if a*d equals c*b. If b and d are positive rational numbers, a/b is less than c/d provided a*d is less than c*b. You should include a function to normalize the values stored so that after normalization the denominator is positive and the numerator and denominator are as small as possible. For example, after normalization, 4/-8 would be expressed as -1/2. "
I was wonder if I am off on the right track with the following class and declarations....?
//Paul Baker
//TRCC Intermediate C++
//Assignment 4, Rational Numbers
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
using namespace std;
#include <iostream>
class Rational
{
public:
Rational( int = 0, int = 1 );
Rational( const Rational& );
Rational& operator=( const Rational& );
int GCD();
void Simplify();
bool IsValid() const;
int Numerator() const;
int Denominator() const;
friend istream& operator>>( istream&, Rational& );
friend ostream& operator<<( ostream&, const Rational& );
private:
int Numerator_;
int Denominator_;
};
bool operator==( const Rational&, const Rational& );
bool operator!=( const Rational&, const Rational& );
bool operator< ( const Rational&, const Rational& );
bool operator<=( const Rational&, const Rational& );
bool operator> ( const Rational&, const Rational& );
bool operator>=( const Rational&, const Rational& );
Rational operator+( const Rational&, const Rational& );
Rational operator-( const Rational&, const Rational& );
Rational operator*( const Rational&, const Rational& );
Rational operator/( const Rational&, const Rational& );