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 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;
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 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;
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
I'm stuck on this question and I don't know how I should be approaching this. What should I do?
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education