Page 1 of 1

1.write a class RationalCpp that contains numerator and denominator as private attributes.RationalCpp should have three

Posted: Sat May 14, 2022 8:22 pm
by answerhappygod
1.write a class RationalCpp that contains numerator and denominator as private attributes.RationalCpp should have three public constructors
RationalCpp():initialize the fraction with 0/1.
RationalCpp(int n):intialize the fraction with n/1.
RationalCpp(int n,int d): intialize the fraction with n/d.
2. write the following function that create RationalC:
RationalC create_rational():initialize the fraction with 0/1.
RationalC create_rational(int n):intialize the fraction with n/1.
RationalC create_rational(int n,int d): intialize the fraction with n/d.
Extend RationalCpp with the void reduce(),which completely reduces the instance on which it is called using gcd.
How can you deal sensibly with a negative numerator or denominator? Explain your approach?
4. Now modify the functions / methods and constructors that you have defined in (1)and (2) so that fractions are always irreducible.use the fraction /method that you have defined in (3) for this purpose.
why is it impossible to ensure that this invariant is always maintained in RationalC?