Question: This is in the Swift Programming Language Design and implement a Fraction class that supports the following: Numerator and Denominator Operations add, subtract, multiply, and

This is in the Swift Programming Language

Design and implement a Fraction class that supports the following: Numerator and Denominator Operations add, subtract, multiply, and divide. Operation reduce, where all the operations performed (+,-,*,/) must be reduced to the simplest form before being returned.

To test the Fraction class, be sure to at least perform the following:

1/2 + 1/4 = 3/4

1/2 - 1/3 = 1/6

1/2 * 1/3 = 1/6

1/2 / 1/3 = 3/2

Namely, your code should look like this:

let f1 = Fraction(1,2)

let f2 = Fraction(1,4)

let f3 = f1.add(f2)

print("The addition of ... is:")

print(f3.reduce()) // calling reduce is unnecessary here since each operation is already doing the reduce.

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!