Question: A rational number ( i . e . , fraction ) class has two private data members: double numerator, denominator; The class supports basic arithmetic

A rational number (i.e., fraction) class has two private data members:
double numerator, denominator;
The class supports basic arithmetic operations on fractions. Specifically, it includes the following implementation for an overloaded addition operator...
Rational operator +(Rational const & r){
Rational result;
result.numerator = numerator*r.denominator + denominator*r.numerator;
result.denominator = denominator*r.denominator;
return result;
}
What happens when the return statement is executed in the function?
Group of answer choices
The return will execute but the return value is undefined because the Rational object only has scope within the overloaded function and the return is by reference
The class' copy constructor is called to make a copy of the Rational object result and return it by value
Code will not compile because the Rational object result cannot be accessed outside of the overloaded function
The return fails because the Rational object result only has scope within the overload + operator function and cannot be returned

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!