Answer in Swift language please: Urgent Class design and implementation. create a command line in which you should design and implement a math operation class for fraction calculation. The class name is MOpt, which should include numerator and denominator and support the functions: add, subtract, multiply, and divide. You should also implement the operation reduce, where all the operations performed (+, -, *, /) must be reduced to the simplest form before being returned. Your class should perform the following math operations: 1/4 + 3/4 = 4/4 = 1 1/4 – 3/4 = -1/2 (not -2/4 using operation reduce) 3/4 – 1/4 = 1/2 (not 2/4) 1/2 * 2/5 = 1/5 (not 2/10) 1/4 / 1/2 = 1/2 (not 2/4) Your code should look like this: let m1 = MOpt(1, 4) let m2 = MOpt(3, 4) let m3 = MOpt(1, 2) let m4 = MOpt(2, 5) let m5 = m1.add(m2) let m6 = m1.subtract(m2) let m7 = m2.subtract(m1) let m8 = m3.multiply(m4) let m9 = m1.divide(m3) The toString() method should be create to print out the fraction number, for example, m1.toString() should output 1/4 string.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 5PE: Using classes, design an online address book to keep track of the names, addresses, phone numbers,...
icon
Related questions
Question

Answer in Swift language please: Urgent

Class design and implementation. create a command line in which you should design and implement a math operation class for fraction calculation. The class name is MOpt, which should include numerator and denominator and support the functions: add, subtract, multiply, and divide.

You should also implement the operation reduce, where all the operations performed (+, -, *, /) must be reduced to the simplest form before being returned.

Your class should perform the following math operations: 1/4 + 3/4 = 4/4 = 1

1/4 – 3/4 = -1/2 (not -2/4 using operation reduce)

3/4 – 1/4 = 1/2 (not 2/4)

1/2 * 2/5 = 1/5 (not 2/10)

1/4 / 1/2 = 1/2 (not 2/4)

Your code should look like this:

let m1 = MOpt(1, 4)

let m2 = MOpt(3, 4)

let m3 = MOpt(1, 2)

let m4 = MOpt(2, 5)

let m5 = m1.add(m2)

let m6 = m1.subtract(m2)

let m7 = m2.subtract(m1)

let m8 = m3.multiply(m4)

let m9 = m1.divide(m3)

The toString() method should be create to print out the fraction number, for example, m1.toString() should output 1/4 string.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning