1. Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to...


I'm stuck on this question and I don't know how I should be approaching this. What should I do?


1. Implement a Rational Number class with the following specifications.<br>Data members<br>a) numerator and denominator<br>Functions<br>a) Constructors:<br>1) default constructor<br>2) single parameter constructor to create numerator/1<br>3) dual parameter constructor to create numerator/denominator<br>4) Use constructor delegation across all constructors.<br>b) Accessors and Mutators for both data members.<br>c) Static recursive GCD function using Euclid's algorithm.<br>d) Static LCM function for two numbers.<br>e) Reduce function simplify a rational number.<br>This function modifies its calling object.<br>f) Your program should work with the supplied driver program.<br>Notes<br>LCM (Least Common Multiple)<br>This function returns the smallest multiple of a and b.<br>Step 1: Multiply a and b to find a common multiple.<br>Step 2: Divide the common multiple by the GCD of a and b.<br>Step 3: Return the result of Step 2.<br>Reduce:<br>This function reduces a fraction to simplest terms (i.e. 9/12 to 3/4).<br>Step 1: Find the GCD of the numerator and denominator.<br>Step 2: Divide the numerator by GCD and store as the new numerator.<br>Step 3: Divide the denominator by GCD and store as the new denominator.<br>Static Functions<br>Recall that static functions are class functions and not associated with<br>instances of the class (objects). In this class, the static functions GCD<br>and LCM should accept inputs any input pair (a and b) and return an answer<br>based upon that input pair. As such, these functions can be used by the<br>programmer upon Rational Number objects or random values for a and b.<br>

Extracted text: 1. Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to create numerator/1 3) dual parameter constructor to create numerator/denominator 4) Use constructor delegation across all constructors. b) Accessors and Mutators for both data members. c) Static recursive GCD function using Euclid's algorithm. d) Static LCM function for two numbers. e) Reduce function simplify a rational number. This function modifies its calling object. f) Your program should work with the supplied driver program. Notes LCM (Least Common Multiple) This function returns the smallest multiple of a and b. Step 1: Multiply a and b to find a common multiple. Step 2: Divide the common multiple by the GCD of a and b. Step 3: Return the result of Step 2. Reduce: This function reduces a fraction to simplest terms (i.e. 9/12 to 3/4). Step 1: Find the GCD of the numerator and denominator. Step 2: Divide the numerator by GCD and store as the new numerator. Step 3: Divide the denominator by GCD and store as the new denominator. Static Functions Recall that static functions are class functions and not associated with instances of the class (objects). In this class, the static functions GCD and LCM should accept inputs any input pair (a and b) and return an answer based upon that input pair. As such, these functions can be used by the programmer upon Rational Number objects or random values for a and b.
Example Driver Program<br>int main() {<br>cout <« endl;<br>// test constructors, accessors, mutators<br>cout <«

Extracted text: Example Driver Program int main() { cout <« endl;="" test="" constructors,="" accessors,="" mutators="" cout=""><« "default="" constructor:="" ";="" ratnum="" r1;="" cout="" «="" r1.getnum()=""><« "/"="" «="" r1.getden()="" «="" endl;="" cout=""><« "single="" parameter="" constructor:="" ";="" ratnum="" r2(2);="" cout="" «="" r2.getnum(="" )="">< "/"="" «="" r2.getden()="" «="" endl;="" cout=""><« "dual="" parameter="" constructor:="" ";="" ratnum="" r3(1,3);="" cout=""><« r3.getnum()=""><« "/"="" «="" r3.getden()="" «="" endl;="" cout=""><« "accessors="" mutators:="" ";="" r3.setnum(3);="" r3.setden(12);="" cout="" «="" r3.getnum(="" )="">< "/"="" «="" r3.getden()="" «="" endl;="" test="" gcd="" cout=""><« "\ngcd="" of="" the="" last="" fraction:="" "="" «="" ratnum::gcd(r3.getnum(),r3.getden())=""><« endl;="" cout=""><« "gcd="" of="" 40="" and="" 24:="" "="" «="" ratnum::gcd(40,24)="" «="" endl;="" test="" lcm="" cout="">< "\nlcm="" of="" the="" last="" fraction:="" "="" «="" ratnum::lcm(r3.getnum(),="" r3.getden())="" «="" endl;="" cout=""><« "lcm="" of="" 3="" and="" 5:="" "=""><« ratnum::lcm(3,5)=""><« endl;="" test="" reduce="" cout="">< "\nreducing="" the="" last="" fraction:="" ";="" r3.="" reduce();="" cout="" «="" r3.getnum(="" )=""><« "/" « r3.getden() « endl; cout « endl; return 0; "/"="" «="" r3.getden()="" «="" endl;="" cout="" «="" endl;="" return="">
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here