Fraction Library
A C++ Fraction library.

Fraction.cpp File Reference

This file implementes the interface of the Fraction class. More...

#include "Fraction.h"
#include <cmath>
#include <string>

Go to the source code of this file.

Defines

#define ACCLIMIT   100000000
 Determines the accuracy when converting a decimal number into a fraction.

Functions

bool operator== (const Fraction &left, const Fraction &right)
bool operator!= (const Fraction &left, const Fraction &right)
bool operator< (const Fraction &left, const Fraction &right)
bool operator<= (const Fraction &left, const Fraction &right)
bool operator> (const Fraction &left, const Fraction &right)
bool operator>= (const Fraction &left, const Fraction &right)
Fraction operator+ (const Fraction &left, const Fraction &right)
Fraction operator- (const Fraction &left, const Fraction &right)
Fraction operator* (const Fraction &left, const Fraction &right)
Fraction operator/ (const Fraction &left, const Fraction &right)
ostream & operator<< (ostream &out, const Fraction &fraction)
istream & operator>> (istream &in, Fraction &fraction)

Detailed Description

This file implementes the interface of the Fraction class.

Private and protected members of the class are also implemented in this file.

Definition in file Fraction.cpp.


Define Documentation

#define ACCLIMIT   100000000

Determines the accuracy when converting a decimal number into a fraction.

Currently, conversion is accurate to 3-4 decimal places.

Increase number to increase accuracy. However, if it becomes too large, conversion operation will fail due to how numbers are represented in memory in c++.

Definition at line 22 of file Fraction.cpp.


Function Documentation

bool operator!= ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if the two fraction objects aren't equal. False otherwise.

Definition at line 328 of file Fraction.cpp.

Fraction operator* ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction on the left of the operator
rightFraction on the right of the operator
Returns:
Returns the reduced product of the two fractions.

Definition at line 370 of file Fraction.cpp.

Fraction operator+ ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction on the left of the operator
rightFraction on the right of the operator
Returns:
Returns the reduced sum of the two fractions.

Definition at line 358 of file Fraction.cpp.

Fraction operator- ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction on the left of the operator
rightFraction on the right of the operator
Returns:
Returns the reduced difference of the two fractions.

Definition at line 364 of file Fraction.cpp.

Fraction operator/ ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction on the left of the operator
rightFraction on the right of the operator
Returns:
Returns the reduced quotient of the two fractions.

Definition at line 376 of file Fraction.cpp.

bool operator< ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if left fraction is less than right fraction. False otherwise.

Definition at line 334 of file Fraction.cpp.

ostream& operator<< ( ostream &  out,
const Fraction fraction 
)
Parameters:
outoutput stream (operation assumes stream is already setup (ie. connected to file, screen etc.)
fractionFraction object to output.
Returns:
Returns reference to output stream so that for instance, cout << x << y is possible.

Definition at line 384 of file Fraction.cpp.

bool operator<= ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if left fraction is less than or equal to right fraction. False otherwise.

Definition at line 340 of file Fraction.cpp.

bool operator== ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if the two fraction objects are equal. False otherwise.

Definition at line 322 of file Fraction.cpp.

bool operator> ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if left fraction is greater than right fraction. False otherwise.

Definition at line 346 of file Fraction.cpp.

bool operator>= ( const Fraction left,
const Fraction right 
)
Parameters:
leftFraction object to the left of the operator.
rightFraction object to the right of the operator.
Returns:
Returns true if left fraction is greater than or equal to right fraction. False otherwise.

Definition at line 352 of file Fraction.cpp.

istream& operator>> ( istream &  in,
Fraction fraction 
)
Parameters:
ininput stream (operation assumes stream is already setup (ie. connected to file, screen etc.)
fractionThe input from stream is assigned to this fraction object.
Returns:
Returns reference to input stream so that for instance, cin >> x >> y is possible.

Definition at line 399 of file Fraction.cpp.