Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab practices defining and implementing class, and working on array of objects of the class type. Requirement Modify the Rational class from lab 6

This lab practices defining and implementing class, and working on array of objects of the class type. Requirement Modify the Rational class from lab 6 as follows: 1. add a set function that sets both numerator and denominator of the invoking object to the values provided in parameter: Rational a; a.set(1, 100); // this sets a to be 1/100 2. For all parameters that are of Rational type, use pass-by-reference (to avoid copying the whole object when passing parameters). If the function is not supposed to modify the parameter, use const before the parameter type. 3. Specify the sum function to be a friend function instead of member function (Keep in mind that wed use friend function when task being performed involves more than one object). The sum function will return the addition of two Rational numbers. 4. Follow the example of sum function to declare and implement a subtract function (as a friend function) which returns the subtraction of two rational numbers. 5. Follow the example of sum function to declare and implement a product function (as a friend function) which returns the product of two rational numbers. 6. Extra credit: declare and implement a private function called simplify that simplifies the invoking object is stored as 4/12, the function will simplify it to be 1/3. Hint: You will need to find the gcd(greatest common divisor) of the numerator and denominator, and then update them by dividing them by the gcd. The iterative version of implementation is given below:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

Explain Coulomb's law with an example

Answered: 1 week ago

Question

What is operating system?

Answered: 1 week ago

Question

What is Ohm's law and also tell about Snell's law?

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago