Assignment_12 - Cout should show the fraction object. For...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science G175 - C++ Programming Assignment 12 Assignment_12.cpp (4 points) Write a class to handle fractions such as “1/3”. The class should have two private data members (ints) called numerator and denominator. Create set() and get() functions for the numerator and denominator. The numerator and denominator should be allowed to have negative values. The value of denominator should never equal zero (a zero value for the denominator is not acceptable, as it would make the program crash). To enforce this restriction, use a while loop or an if/else statement in any function that sets the value of the denominator. Overload the +, -, *, and / operators to perform addition, subtraction, multiplication and division of fraction objects. For example: 1/3 + 1/2 = 5/6 1/3 – 1/2 = –1/6 1/3 * 1/2 = 1/6 1/3 / 1/2 = 2/3 Also overload the << operator to work with “cout”.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Cout should show the fraction object. For example, this function should show 1/3 if the numerator = 1 and denominator = 3. The << operator should also reduce the fraction . For example, the fraction 2/6 should display as 1/3. The fraction 20/6 should display as 10/3. If the numerator or denominator (or both) are negative numbers, the << operator should display the fraction correctly. For example, if the fraction data is stored as -1/-3, cout should display 1/3, if the fraction data is 1/-3, cout should display -1/3. Write a program that demonstrates the use of each member function in the fraction class. In addition to this lab, also review the Word document Session 12 that has been posted to the website. Please, again, refer to Session 11 and to our textbook, parts of chapter Lesson 13 for additional information. Page 1 of 1...
View Full Document

This note was uploaded on 12/07/2010 for the course CS 175 taught by Professor Mike during the Spring '06 term at Golden West College.

Ask a homework question - tutors are online