CST1620 C# / C++
Programming
Lab Week 8
Exercises |
Exercise 9/10.1
Proper Rational Calculations (20 points) In this exercise your are going to build upon Exercise 8.1 that you completed last week. Last week you created a class named Rational for performing arithmetic with fractions. You provided public member functions (methods) that performed each of the following tasks:
You provided a private member function named Reduce. This code was reused from your exercise 6.2. You provided get accessors to be able to retrieve the numerator and denominator variables. And you wrote a main Windows GUI program (Ex8_1) to test your class. This week for exercise 9/10.1 you are to create a new class named ProperRational that inherits from your previously made class named Rational. So in other words you are making a subclass named ProperRational from a base class named Rational. This new class is to extend the functionality of Rational class by providing the ability to store all rationals properly by using whole numbers if necessary and where no numerator shall be larger than the denominator. Also the negative sign needs to be applied to the whole number, if there is a non zero whole number. If the whole number is zero, then the negative sign shall be applied to the numerator. The only changes that you should need to make with your class Rational will be to make a couple of the class variables protected and the method Reduce protected. The rest of the class should be untouched. For your new class ProperRational, you need to provide public member functions (methods) that performed each of the following tasks:
Provided a private member function named Reduce. In all of the above methods, call upon the base class methods to perform the bulk of the work. Provide a get accessor to be able to retrieve the whole variable. Operator overloading is quite common in C++. Therefore, to gain experience with the concept, I want you to overload the +, -, *, and / operators and demonstrate that your operator overloads work in your main program. Write a main Windows GUI program (Ex910_1) to test your class. To get you started, I am providing much of the ProperRational class for you in this file. So pretty much all is left is for you to complete the member functions. The add function has been done for you already. Also notice I made some private helper functions to take care of the signs. Here is my code for my main windows GUI to test the class. Result (Save to your local machine and run) |