Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this the template Program: Fraction Enhance Your task in this programming assignment is to write a Python program that efficiently implements a fraction class. What

image text in transcribed
this the template
image text in transcribed
Program: Fraction Enhance Your task in this programming assignment is to write a Python program that efficiently implements a fraction class. What does efficiently mean? Well, think through the problem so that you do not have to unnecessarily perform operations as they can be costly). In addition, you should make use of any additional functions that reasonably encapsulate separate logical tasks. This is a part of good coding style You must provide address the following in the fraction class: A constructor that initializes fractions (with specified values for the numerator and denominator or 0/1 as default): Appropriate accessors and mutators for the instance variables: Proper automatic reducing/simplifying of fractions when necessary; Prevention of a 0 denominator; Overloading of the arithmetic operators on fractions (i.e., the ability to add, subtract, multiply. and divide fractions using the arithmetic operators +, - and/respectively); A method that returns the floating point representation of a fraction; and A method that specifies how fractions should be displayed (e.g., via print ()). A template is provided that includes a main part of the program intended to test your fraction class. Here's a sample run of a correctly implemented fraction class: f1: 0/1 (0.0) f2: 5/8 (0.625) f3: 3/4 (0.75) 14: 1/1 (1.0) fl: 5/4 (1.25) f2: 0/1 (0.0) f3: 25/16 (1.5625) f4: 2/275 (0.00727272727273) To help clarify, here are some specifics and/or constraints: (1) You must include a meaningful header, use good coding style, use meaningful variable names, and comment your source code where appropriate; (2) Your output should be exactly like the sample run shown above; (3) Therefore, you should not modify the main part of the program (at all); and (4) You must submit your source code as a single.py file. # the fraction class # ***DO NOT MODIFY OR REMOVE ANYTHING BELOW THIS POINT!*** # the main part of the program # create some fractions f1 = Fraction() f2 = Fraction (5, 8) f3 = Fraction(3, 4) f4 = Fraction(1, 0) # display them print("f1:", f1) print("f2:", f2) print("f3:", f3) print("f4:", f4) # play around f3.num 5 f3.den 8 fi f2 + f3 f4.den = 88 f2 = f1 - f1 f3 = fi * f1 f4 = f4 / f3 # display them again print() print("f1:", f1) print("f2:", f2) print("f3:", f3) print("f4:", f4)

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

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

What is the main advantage to this tactic?

Answered: 1 week ago

Question

Please answer this question

Answered: 1 week ago