Write a rational number class. Recall a rational number is a rational number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects with any legal values. You should provide the following a default constructor to initialize the data members: 1. A default constructor to make rational objects without any argument. The constructor sets the rational object's numerator to 0, and denominator to 1. 2. EXTRA CREDIT: implement two other constructors: one that takes just numerator and one that takes both as parameters. REMEMBER that fractions cannot have a denominator of 0. You should also provide the following member functions (no simplifying rationals until part2): 1. an input function that reads from standard input the value for current object. The input should be in the form of 2/3 or 27/51. 2. an output function that displays the current object in the terminal. The output should also be in the form of 2/3, i.e., numerator/denominator. 3. Two accessor (getter) functions that return the numerator and denominator respectively. 4. a Add function that takes two rational objects as parameters. It sets the invoking object to be the sum of the two given rational numbers like op1 + op2. 5. a Subtract function, which will set the invoking object to the difference of op1 - op2 6. a Multiply function, which will set the invoking object to the product of op1 * op2 7. a Divide function, which will set the invoking object to the quotient of op1 / op2.
Write a rational number class. Recall a rational number is a rational number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects with any legal values. You should provide the following a default constructor to initialize the data members: 1. A default constructor to make rational objects without any argument. The constructor sets the rational object's numerator to 0, and denominator to 1. 2. EXTRA CREDIT: implement two other constructors: one that takes just numerator and one that takes both as parameters. REMEMBER that fractions cannot have a denominator of 0. You should also provide the following member functions (no simplifying rationals until part2): 1. an input function that reads from standard input the value for current object. The input should be in the form of 2/3 or 27/51. 2. an output function that displays the current object in the terminal. The output should also be in the form of 2/3, i.e., numerator/denominator. 3. Two accessor (getter) functions that return the numerator and denominator respectively. 4. a Add function that takes two rational objects as parameters. It sets the invoking object to be the sum of the two given rational numbers like op1 + op2. 5. a Subtract function, which will set the invoking object to the difference of op1 - op2 6. a Multiply function, which will set the invoking object to the product of op1 * op2 7. a Divide function, which will set the invoking object to the quotient of op1 / op2.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Code in c++
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 18 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY