Question: 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

please help me solve this fast } ...... more member TUHCIIOHS ll2 parameter constructor Rat(int i, intj){ n=i; d=j; } ll other Ratfunctions as we saw in class The following demonstrates two ways thata member function could be called: 0 Explicitly on an object ofthe class using the "dot notation" . Implicitly as part of another

} ...... 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])0; i--) for(int j=0; j k[j+ 1]) t=k[j]; k[j]=k[j+1]; k[j+1]=t; }; which does a bubble sort on the array. Recall that since the compiler, out of the box, has no idea what Rats are, it doesn't know how to decide if one Rat is smaller than another. So, in order for this sort to work, we would have to have a member function which overloaded the > operator. It would be called operator>(..something goes here..). d1. Explain clearly exactly how this member function is implemented. (5 points)d1. Explain clearly exactly how this member function is implemented. (5 points) d2. Write this member function. Note: be careful of the return type. (10 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!