Last active
July 29, 2019 18:33
-
-
Save Hafiz-SE/81004108ceb1619cbd0d0592a71fa81a to your computer and use it in GitHub Desktop.
C3_Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// Assignment1 | |
// | |
// Created by Hafizur Rahman on 29/7/19. | |
// Copyright © 2019 Hafizur Rahman. All rights reserved. | |
// | |
import Foundation | |
func countPairs (first : [Int], last : [Int], sum: Int ) -> Int { | |
var temp : Int = 0; | |
for i in first { | |
for j in last{ | |
if ((i+j)==sum){ | |
temp+=1 | |
} | |
} | |
} | |
return temp; | |
} | |
let numberList1 = [1,2,3,4,5,6,7,8,9] | |
let numberList2 = [2,3] | |
let sumCheck : Int = 5 | |
let sumCount : Int = countPairs(first: numberList1, last: numberList2, sum: sumCheck) | |
print("Sum count = \(sumCount)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// Assignment1 | |
// | |
// Created by Hafizur Rahman on 29/7/19. | |
// Copyright © 2019 Hafizur Rahman. All rights reserved. | |
// | |
import Foundation | |
class Adder{ | |
var a,b :Int | |
init(){ | |
self.a = 0; | |
self.b = 0; | |
} | |
init(a1:Int, b1:Int) { | |
self.a = a1; | |
self.b = b1; | |
} | |
func add() -> Int { | |
return self.a+self.b | |
} | |
} | |
class Subtractor : Adder{ | |
override init(){ | |
super.init() | |
} | |
init(aSub:Int , bSub: Int){ | |
super.init(a1: aSub, b1: bSub) | |
} | |
func subtract() -> Int { | |
if (self.b>0){ | |
return self.a + (self.b * (-1)) | |
} | |
else { | |
return self.a + self.b | |
} | |
} | |
} | |
class Multiplier: Adder{ | |
override init(){ | |
super.init() | |
} | |
init(aMul:Int , bMul: Int){ | |
super.init(a1: aMul, b1: bMul) | |
} | |
func multiply() -> Int{ | |
var temp : Int = self.a; | |
for _ in 2...self.b { | |
temp = temp+self.a; | |
} | |
return temp; | |
} | |
} | |
let substractor = Subtractor(aSub:100,bSub:50); | |
print ("Substraction Result: \(substractor.subtract())"); | |
let multiplier = Multiplier(aMul: 2, bMul: 6); | |
print ("Multiplication Result: \(multiplier.multiply())") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment