Question: Write and add comments ro explain in C++ please! follow all the requirements below. Define a class for rational numbers. A rational number is a


Define a class for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, 21,43,264, and forth are all rational numbers. - Class name is Rational. - Represent rational numbers as two values of type int, one for the numerator and one for the denominator. Two constructors - Default constructor that initializes an object to 0 (that is, to 10 ) - Constructor with two parameters - Member functions for arithmetic operations (t,, *, /) - Member function for printing out the rational - Setters \& getters - Reduce the fraction addba+dc=bdad+bcsubstractbadc=bdadbc multiply badc=(bd)(ac) divide ba/dc=(bc)(ad) int nun1, denon1, nunz, denon2; cout e Enter nuserator and denoninator for r1;; cin >x nuni denonl; cout ee "Enter numerator and denoninator for I 2: : i cin nuaz denon2; Rational: ri(nunt, denon1); Aationat x (nun2, denon2); Rational sun =rl.add (r2) Ratiohal dif in i.subtract (r2); Do not change main function. Rational nut =r1 nultiply (r2); Rational div=r1, divide (r2); Create Rational class. cout e endt; cout e isum : "; sua, print (); cout ee bif if aif, difint (); cout es Hut i ; mul.print(); cout ee nodv; div, print () ; r1. setDenioninator (5); r1. setNunerator (7); r2. sotDenpninator (2); r2. setvunerator (6); cout e "ri denoninator : = es r1,getoenoninator( ) ee endi; cout ke " r1 nunerator is es r1, getNunerator () en end:; cout \&e - r2 denoninator i " \&4 r2. getpencainator C ee endl; cout es ir2 numeratar i i e r2. getNuneratorO \&e endi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
