Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please help me solve this fast } ...... more member TUHCIIOHS ll 2 parameter constructor Rat(int i, intj){ n=i; d=j; } ll other Rat functions
please help me solve this fast
} ...... more member TUHCIIOHS ll 2 parameter constructor Rat(int i, intj){ n=i; d=j; } ll other Rat functions as we saw in class The following demonstrates two ways that a member function could be called: 0 Explicitly on an object of the class using the "dot notation" . Implicitly as part of another member function then it called without the "clot" For example, consider the following member function: bool isZero(){ return n==0; ll returns true if n = = 0, false otherwise } 1. We can call it explicitly: Rat X(1,2), ; if ( x.isZero() ) II here isZero() is called explicitly on a Rat or we can call it implicitly as part of another member function or we can call it implicitly as part of another member function bool isNotZero(){ if ( isZero()) return true; else return false; } }; [lend Rat Here are the questions We would like to add a member function: bool operator==(Rat r) so that we can test whether or not two Rats are equal. 50 both of the following should return true, Rat X(1.3). y(1.3). 2(2.6) x==y; \"should return true x==z; // should return true You can assume that you have a member function void reduce() that will reduce a Rat to lowest terms. a. Write the operator ==() so that it works as described. (5 points) ANS: bool operator==(Rat r) b. In clear precise English, describe exactly how function reduce() could be implemented. Explain in detail why your method works. (5 points) c. Write member function reduce(). (10 points) ANS: void reduce(){ d. If we wanted to sort an array of Rats we could call the following function: void RatSort(Rat k, int size){ Rat t; for(int i=size-1; i>0; i--) for(int j=0; jk[j+ 1])Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started