Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Class design and implement.create a command line(swift) in which you should design and implement a math operation class for fraction calculation. The class name is

Class design and implement.create a command line(swift) 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) 2 | 9

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.

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago