Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python, create an abstract data type called Fraction (using a class). The Fraction should have: Data: A numerator (integer) A denominator (integer) Operations: A

Using Python, create an abstract data type called Fraction (using a class). The Fraction should have:

Data:

A numerator (integer)

A denominator (integer)

Operations:

A constructor (takes a numerator and denominator as parameters)

A __str__ function that returns a string representation of the Fraction

An __add__ function (overloads "+") that returns a new fraction that is the addition of self and its parameter fraction

A __sub__ function (overloads "-") that returns a new fraction that has the value of the current minus the parameter fraction

A __mul__ function (overloads "*") that returns a new fraction that is the multiplication of the current fraction and the parameter fraction

A __truediv__ function (overloads "/") that returns a new fraction that is the division of the current fraction with the parameter fraction

All of the operations should use the greatest common denominator function (below) to reduce the fraction as much as possible.

Create a greatest common denominator (gcd) function that returns the greatest common denominator two integers (parameters) (algorithm given on p. 41 of the textbook)

Test your program with a variety of fractions (positive and negative).

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_2

Step: 3

blur-text-image_3

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

2. What are the arguments against globalization?

Answered: 1 week ago

Question

U11 Informing Industry: Publicizing Contract Actions 317

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago

Question

What are some of the possible scenes from our future?

Answered: 1 week ago