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
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