Question: Please use python programming language. Attach a picture with it. 12. Create a class named rational which will represent a new data type cor- responding

Please use python programming language. Attach a picture with it. 12. Createa class named rational which will represent a new data type cor-Please use python programming language. Attach a picture with it.

12. Create a class named rational which will represent a new data type cor- responding to rational numbers. A rational number is a fraction where the numerator and denominator are both integers. Your constructor should create the following variables: n and d corresponding to the numerator and denominator of the rational numbers. Default values are n 0, and d 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 (i.e. 3/4 becomes 0.75) gcf which returns the greatest common factor of n and d. (Be careful not to change the values of n and - reduce which reduces the fraction to its lowest terms (using the ged function above). This function changes the value of n and d appropriately. 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_,-sub-,-mul.-,-.truediv_ should be overloaded to per- form the appropriate operations (+, -, *, /) on rational numbers When calculating the new rational number, reduced it to lowest terms (6/8 should become 3/4) _-, --ge--, should be overloaded to perform the appropriate equalities/unequalities/inequalities between eq--, _.ne_, _lt_, -le rational numbers (-, !-, , >

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!