Question

Build a basic calculator app in swift. Calculator must be able to add, subtract, multiply, divide,...

Build a basic calculator app in swift.

Calculator must be able to add, subtract, multiply, divide, and compute sine, cosine, and tangent functions.

The core calculator arithmetic logic should be written as an objective c framework that is used in the swift app.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

i have maded this in past so you have to copy/paste this code from here and you will find your working calculator with your all needs fulfilled ..............

make file with name SciCalc.swift under folder model

and copy paste code---->

import Foundation

enum SciCalcOperation {

case logrithm

case sindegree

case cosdegree

case tandegree

init?(from buttonTitle: String) {

switch buttonTitle {

case "Sin": self = .sindegree

case "Cos": self = .cosdegree

case "Tan": self = .tandegree

case "Log": self = .logrithm

default: return nil

}

}

func apply(to left: Double) -> Double {

switch self {

case .sindegree:

return sin(left * .pi / 180)

case .cosdegree:

return cos(left * .pi / 180)

case .tandegree:

return tan(left * .pi / 180)

case .logrithm:

return Darwin.log(left) / Darwin.log(10)

}

}

}

enum CalculatorOperation {

case add

case subtract

case multiply

case divide

init?(from buttonTitle: String) {

switch buttonTitle {

case "+": self = .add

case "-": self = .subtract

case "*": self = .multiply

case "/": self = .divide

default: return nil

}

}

func apply(to left: Double, and right: Double) -> Double {

switch self {

case .add:

let sum = left + right

return Double(sum)

case .subtract:

let difference = left - right

return Double(difference)

case .multiply:

let product = left * right

return Double(product)

case .divide:

let divison = left / right

return Double(divison)

}

}

}


DON'T FORGET TO UPVOTE THIS ANSWER

Add a comment
Know the answer?
Add Answer to:
Build a basic calculator app in swift. Calculator must be able to add, subtract, multiply, divide,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT