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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply