{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment_12

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

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

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”.
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern