CSCI 152 Program 6: Overloading Operator Functions in Fraction Class, Exams of Computer Science

The requirements for program 6 in csci 152, where students are tasked with rewriting arithmetic and comparison methods as overloaded operators for a fraction class. The document also includes instructions for changing the fraction.h declarations and implementations in fraction.cpp, as well as rewriting the fractiontestdriver. An extra credit opportunity is provided for removing the print() member function and overloading the stream insertion operator instead.

Typology: Exams

Pre 2010

Uploaded on 08/16/2009

koofers-user-z49
koofers-user-z49 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 152 Program 6
Spring 2005 Due: Friday, 6 May
Emphasis on: Overloading Operator Functions
For program 6, you are to revisit program 5 where we created a Fraction class. The fraction
class contained methods for performing arithmetic operations such as add, sub, mult and
div. The fraction class also contained comparison operators such as equal, greaterthan and
lessthan. For program 6, you are to rewrite these methods as overloaded operator
methods. Change the definition of Fraction.h to user overloaded operators and also change
implementations of these member funcitons in Fraction.cpp to reflect the changes. You
should also rewrite the FractionTestDriver to demonstrate the use of the overloaded
operators on the Fraction class.
Program 6 Requirements:
1) Rewrite the arithmetic class methods add, sub, mult and div using overloaded
operators
2) Rewrite the comparison operators equal, greaterthan and lessthan also as
overloaded operators
3) You must change the Fraction.h declarations as well as the implementations of the
new overloaded operators in Fraction.cpp
4) Rewrite the FractionTestDriver to use and test the overloaded arithmetic and
comparison operators.
Extra Credit:
The print class method, as written in program 5, writes a representation of the fraction on
cout standard output stream. It is conventional not to have classes send output directly to
streams, but leave input and output up to the client/user program. For 10 extra credit
points, remove the print() member function and instead provide and overloaded <<
(insertion) member function that will insert a representation of the fraction into a stream.
Se the book chapter 15, pg 822 for an example of overloading the stream insertion
operator.

Partial preview of the text

Download CSCI 152 Program 6: Overloading Operator Functions in Fraction Class and more Exams Computer Science in PDF only on Docsity!

CSCI 152 Program 6 Spring 2005 Due: Friday, 6 May

Emphasis on: Overloading Operator Functions

For program 6, you are to revisit program 5 where we created a Fraction class. The fraction class contained methods for performing arithmetic operations such as add, sub, mult and div. The fraction class also contained comparison operators such as equal, greaterthan and lessthan. For program 6, you are to rewrite these methods as overloaded operator methods. Change the definition of Fraction.h to user overloaded operators and also change implementations of these member funcitons in Fraction.cpp to reflect the changes. You should also rewrite the FractionTestDriver to demonstrate the use of the overloaded operators on the Fraction class.

Program 6 Requirements:

  1. Rewrite the arithmetic class methods add, sub, mult and div using overloaded operators
  2. Rewrite the comparison operators equal, greaterthan and lessthan also as overloaded operators
  3. You must change the Fraction.h declarations as well as the implementations of the new overloaded operators in Fraction.cpp
  4. Rewrite the FractionTestDriver to use and test the overloaded arithmetic and comparison operators.

Extra Credit:

The print class method, as written in program 5, writes a representation of the fraction on cout standard output stream. It is conventional not to have classes send output directly to streams, but leave input and output up to the client/user program. For 10 extra credit points, remove the print() member function and instead provide and overloaded << (insertion) member function that will insert a representation of the fraction into a stream. Se the book chapter 15, pg 822 for an example of overloading the stream insertion operator.