Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python 3 to solve the whole question Instructions: The purpose of this assignment is to learn how to make a class in Python

Please use python 3 to solve the whole question image text in transcribed
Instructions: The purpose of this assignment is to learn how to make a class in Python 1. Create a class named rational which will represent a new data type cor- responding to rational numbers. A rational number ?sa fraction where the mumerator and denominator are both integers. Your constructor should create the following variables: - n and d corresponding to the numerator and denominator of the rational mumbers. Default values are n 0, and d 1 And the following functions (or methods) num which returns the numerator of the fraction - denom which returns the denominator of the fraction - convert which returns a double representing the fraction (ie. 3/4 becomes 0.75) - gef which returns the greatest commmon factor of n and d. (Be careful not to change the values of n and d) - reduce which reduces the fraction to its lowest terms (using the ged function above) This function changes the value of n and d Overload the following methods: str. to display the rational number as a fraction to the monitor A fraction like a/1 should be displayed as a, and a fraction like 0/b should be displayed as 0. .-.add -_cub.??nul div_ should be overloaded to perform the appropriate operations (+,-,on rational numbers. When caleulating the new rational number, reduced it to lowest terms (6/8 should become 3/4). These functions sbould work when doing the operation between rational numbers and integers as wl. Also do the raddrsubrrdiv functions . eqneltleg-ge,should be overloaded to perform the appropriate equalities/unequalities/inequalities between rational numbers (!<.>) Bonus: Write a program that uses the rational number class described in problem 2 (whether or not you completed it successfully), for the expansion of the number a described earlier in the semester Ask the user how many terms the user would like to calculate, then display the proper reduced fraction representing the calculation For example, if the user wants 4 terms: 4 4 4430 earn this boaus, whether or not your rational class works correctly. I am only interested in the what you would do if you hada perfectly working rational class. It won't run unless your rational class is defined properly, so testing might be an issue. For full credit, use the rational class as mach as possible (all calculations done with fractions and little or no calculations done between regular pythoa types)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

=+5. How do proposal writers use an RFP? [LO-7]

Answered: 1 week ago

Question

=+2 Identify six guidelines for drafting effective website content

Answered: 1 week ago