In this supplement exercise please create a class called RationalNumber for performing arithmetic operations with exact fractions. To achieve this please use integer variables to represent the data of the class the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values, in case no initializers are provided (please review previous supplement exercise for default constructor mechanism) and should store the fraction in reduced form. For instance, 2/4 should be ½. For the method part there have to be; • Adding two RationalNumber and the result should be stored in reduced form. • Subtracting two RatonalNumber and the result should be stored in reduced form. • Multiplying two RationalNumber and the result should be in reduced form. • Dividing two RationalNumber and the result should be in reduced form • Printing RationalNumber in the form A/B, where A is the numerator and the B is denominator. • Printing RationalNumber in the form of floating-point format. Hint: In order to see the reduced form of the RationalNumber you can use greatest common divisor algorithm (generally known as Euclidian Algorithm) to apply numerator and denominator parts of the Rational.

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...
icon
Related questions
Question

Python code

In this supplement exercise please create a class called RationalNumber for performing
arithmetic operations with exact fractions.
To achieve this please use integer variables to represent the data of the class the numerator
and the denominator. Provide a constructor that enables an object of this class to be initialized
when it is declared. The constructor should contain default values, in case no initializers are
provided (please review previous supplement exercise for default constructor mechanism) and
should store the fraction in reduced form. For instance, 2/4 should be ½.
For the method part there have to be;
• Adding two RationalNumber and the result should be stored in reduced form.
• Subtracting two RatonalNumber and the result should be stored in reduced form.
• Multiplying two RationalNumber and the result should be in reduced form.
• Dividing two RationalNumber and the result should be in reduced form
• Printing RationalNumber in the form A/B, where A is the numerator and the B is
denominator.
• Printing RationalNumber in the form of floating-point format.
Hint: In order to see the reduced form of the RationalNumber you can use greatest common
divisor algorithm (generally known as Euclidian Algorithm) to apply numerator and denominator
parts of the Rational.
Pseudo Code of the Algorithm
1. Step: Let a, b be the two numbers
2. Step: a mod b=R
3. Step: Let a =b and b = R
4. Step: Repeat Steps 2 and 3 until a mod b is greater than 0
5. Step: GCD =b
6. Step: Finish
Transcribed Image Text:In this supplement exercise please create a class called RationalNumber for performing arithmetic operations with exact fractions. To achieve this please use integer variables to represent the data of the class the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values, in case no initializers are provided (please review previous supplement exercise for default constructor mechanism) and should store the fraction in reduced form. For instance, 2/4 should be ½. For the method part there have to be; • Adding two RationalNumber and the result should be stored in reduced form. • Subtracting two RatonalNumber and the result should be stored in reduced form. • Multiplying two RationalNumber and the result should be in reduced form. • Dividing two RationalNumber and the result should be in reduced form • Printing RationalNumber in the form A/B, where A is the numerator and the B is denominator. • Printing RationalNumber in the form of floating-point format. Hint: In order to see the reduced form of the RationalNumber you can use greatest common divisor algorithm (generally known as Euclidian Algorithm) to apply numerator and denominator parts of the Rational. Pseudo Code of the Algorithm 1. Step: Let a, b be the two numbers 2. Step: a mod b=R 3. Step: Let a =b and b = R 4. Step: Repeat Steps 2 and 3 until a mod b is greater than 0 5. Step: GCD =b 6. Step: Finish
Sample run of the test class of RationalNumberDriver.py
this is the default rational number:
0/1
this is the first rational number:
2/3
this is the second rational number:
1/5
this is the default rational number in floating-point format:
0.0
this is the first rational number in floating-point format:
0.6666666666666666
this is the second rational number in floating-point format:
0.2
Sum is:
13/15
Difference is:
7/15
Multiplication is:
2/15
Division is:
10/3
Transcribed Image Text:Sample run of the test class of RationalNumberDriver.py this is the default rational number: 0/1 this is the first rational number: 2/3 this is the second rational number: 1/5 this is the default rational number in floating-point format: 0.0 this is the first rational number in floating-point format: 0.6666666666666666 this is the second rational number in floating-point format: 0.2 Sum is: 13/15 Difference is: 7/15 Multiplication is: 2/15 Division is: 10/3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY