Question
Add the following operations to the Fraction class (HINT: After you complete the __cmp__ function, the remaining functions can use the __cmp__, making them almost
Add the following operations to the Fraction class (HINT: After you complete the __cmp__ function, the remaining functions can use the __cmp__, making them almost trivial.):
__cmp__ - This function should take another fraction as the parameter and return: a negative value if the current fraction is less than the parameter fraction zero if the current fraction and the parameter fraction have the same value a positive value if the current fraction is greater than the parameter fraction
__eq__ - This function should take another fraction as a parameter and return True if the current fraction is equal to the the parameter fraction; otherwise False
__ne__ - This function should take another fraction as a parameter and return True if the current fraction is not equal to the the parameter fraction; otherwise False
__lt__ - This function should take another fraction as a parameter and return True if the current fraction is less than the parameter fraction; otherwise False
__le__ - This function should take another fraction as a parameter and return True if the current fraction is less than or equal to the parameter fraction; otherwise False __gt__ - This function should take another fraction as a parameter and return True if the current fraction is greater than the parameter fraction; otherwise False
__ge__ - This function should take another fraction as a parameter and return True if the current fraction is greater than or equal to the parameter fraction; otherwise False Modify the main program to test these new operations, including ==, !=, <, >, <=, >=.
Create a Abstract Data Type called Percentage which is derived from a Fraction
Add a __str__() operation that converts the fraction to display as a percentage.
For example, the fraction 4/5 should display as 80.0%.
Create a main program that creates a couple of percentages that add up to 100%.
Compute a weighted average of several made up test scores.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started