COP 4655 Midterm Review

0.0(0)
studied byStudied by 3 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:36 AM on 2/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

33 Terms

1
New cards

Which code creates an inheritance such the class Plant is a super class of the Class Tree

class Tree: Plant

3 multiple choice options

2
New cards

What is not an appropriate way to call this function:

func setACTemperature{_ unit: Int,

_currentTemp: Double,

thermostatValue: Double = 77.5) -> Bool{...}

_=setACTemperature(3, currentTemp: 92.2, thermostate: 82.2)

3
New cards

What is the correct swift code for the following expression:

result = log10(4) + e^3 + ln(8)

var result = log10(4.0 + exp(3.0) + log(8.0)

4
New cards

Which keyword is used to declare a constant in swift:

let

5
New cards

If you have the following code below, what swift code can you put out on line 7 that would print out the values of g and h on the output console:

var g:Int = 5

var h:Double = 4.2

print(" g:\(g) \t\t\h:\(h) ")

3 multiple choice options

6
New cards

Which is the swift code that creates an array that stores 10 zeros

let arrayOfZeros = [Int](repeating: 0, count: 10)

7
New cards

What is the output of this code:

var nums3D = [ [ [10, 21, 3], [1, 5, 9] ], [ [3, 8, 13], [7, 18, 33] ], [ [20, 60, 88], [33, 74, 12] ] ]

print ("nums3D[0][2] = \(nums3D[0][2])')

nums3D[0][2] = [ [20, 60, 88], [33, 74, 12] ]

8
New cards

What is the output of this code:

var nums3D = [ [ [10, 21, 3], [1, 5, 9] ], [ [3, 8, 13], [7, 18, 33] ], [ [20, 60, 88], [33, 74, 12] ] ]

print ("nums3D[0][2][1][0] = \(nums3D[0][2][1][0])")

nums3D[0][2][1][0] = 33

9
New cards

What is the output of this code:

var nums2D = [ [ [10, 21, 3], [1, 5, 9] ], [ [3, 8, 13] ]

print ("nums2D[1][1] = \(nums2D[1][1])")

nums2D[1][1] = 5

10
New cards

what is the output of this code:

var names = ["Oliver", "Hazel", "Felix", "Alexander", "Luna", "Claire", "Jane", "Luke", "Edwards"]

print("names[2...<4] = \(names[2...<4])")

names[2...<4] = ["Felix', "Alexander"]

11
New cards

What is the output of this code:

var numbers = [2.3, 37, 27.2, -4.2, 2, 100, -462, 84.2, -482.4, 1, 1, -3, 7]

var mapNumbers = numbers.map{ $0 + 10 }

print("mapNumbers = \(mapNumbers)")

print()

mapNumbers = [12.3, 47.0, 37.2, 5.8, 12.0, 110.0, -452.0, 94.2, -472.4, 11.0, 11.0, 7.0, 17.0]

3 multiple choice options

12
New cards

What is the output of this code:

var nums = [10, 21, 3, 43, 83, 382]

nums.removeLast()

nums.removeFirst()

nums.remove(at: 2)

nums.append(6)

nums.append(23)

nums.remove(at: 2)

nums.remove(at: 7)

nums.removeLast()

nums.removeLast()

print("nums = \(nums)")

error in code

13
New cards

What is the output of this code:

var testMessage2: String

testMessage2 = nil

var textMessage: String = "Hi"

if textMessage != nil {

print("textMessage = \(textMessage)")

} else {

print("textMessage = nil")

}

error in code

14
New cards

In swift how do you declare a tuple where the entire tuple is an optional with the following entries:

city that is a String

zipCode that is an integer

address that is a string

var data1: (city: String, zipCode: Int, address: String)?

3 multiple choice options

15
New cards

In swift how do you declare a tuple when the entire tuple has the following entries:

city that is a string optional

zipCode that is an integer optional

address that is a string

var data2: (city: String?, zipCode: Int?, address: String)

16
New cards

What is the output of line 9:

1

2var defaultValue = "John Doe"

3 var employee1Name: String?

4 var employee2Name: String?

5

6 employee1Name = "Albert Einstein"

7

8 var name1 = employee1Name ?? defaultValue

9 print("Name of employee1: \t \(name1)")

10

11 var name2 = employee2Name ?? defaultValue

12 print("Name of employee2: \t \(name2)")

Name of employee1: Albert Einstein

3 multiple choice options

17
New cards

What is the output of the code below:

var value1: Int?

var value2: String?

var value3: Double?

value1 = 3

value2 = "New York"

if let tmp1 = value1, let tmp2 = value2, let tmp3 = value3 {

print("OK")

} else {

print("Bad")

}

Bad

18
New cards

Declare a function named printSomeText that has a local variable named text and is of type String. In addition the function returns void

func printSomeText(text: String) { }

19
New cards

What is the output when line 14 executes:

var firstValue = 100

var secondValue = 200

func match(firstInput: inout Int, secondInput: inout Int) -> Void {

let tmp = firstInput

firstInput = secondInput

secondInput = tmp

}

match(firstInput: &firstValue, secondInput: &secondValue)

print("firstValue = \(firstValue), secondValue = \(secondValue)")

firstValue = 200

20
New cards

Declare a function named optionsToChoose that has a local variable named dressing with a default value of Oil and is of type String. In addition the function returns void

func optionsToChoose( dressing: String = "Oil") -> Void { }

21
New cards

What code must you write in place of REPLACE_HERE to discard the return value from the function call doubleCounter(counter:100)

func doubleCounter(counter: Int) -> Int {

print("Running doubleCounter with input \(counter)")

return 2 * counter

}

REPLACE_HERE = doubleCounter(counter: 100)

_ (underscore)

3 multiple choice options

22
New cards

What is the appropriate way to call this function:

1 func calculateFuelMixture(temperature: Double = 82.3,

2 atmosphericPressure: Double = 29.9,

3 timing: Int = 7,

4 fuelType: String = "VP-T4") -> Void { }

calculateFuelMixture(temperature: 45.2, atmosphericPressure: 35.3, timing: "7")

3 multiple choice options

23
New cards

Declare a function with the following requirements:

return type: Void

name of function: cookOtherRecipe

first parameter: type String and has name dish with no external name

second parameter: type Int and has name temp with external name withTemp

third parameter: type String and has name duration with external name for

fourth parameter: type String and has name time with external name at

func cookOtherRecipe(dish: String, withTemp temp: Int, for duration: String, at time: String) { }

24
New cards

let -

defines a constant, multiple constants can be defined with one let separated by commas

25
New cards

var -

defines Int, Double, and String variables

26
New cards

_ (underscore) -

Tells the compiler you know of the return type but don't want to use it

27
New cards

Boolean -

A statement that is equal to either TRUE or FALSE

28
New cards

? (question mark) -

Used to declare the type as an option, meaning it can either hold a value of that type or return a nil value

29
New cards

What is the output of this code:

let studentID = 123456 let exam3Grade = 63

switch exam3Grade{

case 90...100:

print("Letter grade is A")

case 80..<90:

print("Letter grade is B")

case 70..<80:

print("Letter grade is C")

case 60...65 where studentID == 123456 :

print("student had additional points")

print("Letter grade is C")

case 60..<70 where studentID == 555555:

print("Letter grade is C")

case 60..<70:

print("Letter grade is D")

default:

print("Letter grade is F") }

// end switch

student had additional points

Letter grade is C

30
New cards

What is the output of this code:

let studentID = 123456

let exam3Grade = 63

switch exam3Grade{

case 90...100:

print("Letter grade is A")

case 80..<90:

print("Letter grade is B")

case 70..<80:

print("Letter grade is C")

case 60..<70:

print("Letter grade is D")

case 60..<70 where studentID == 555555:

print("Letter grade is C")

case 60...65 where studentID == 123456 :

print("student had additional points")

print("Letter grade is C")

default:

print("Letter grade is F") }

//end switch

letter grade is D

3 multiple choice options

31
New cards

What are the levels of access control in swift:

Open, Public, Internal, Fileprivate, Private

32
New cards

How would you call the function on line 6:

var firstValue = 100

var secondValue = 200

func match(firstInput: inout Int, secondInputL inout Int) -> Void {

let tmp = firstInput

firstInput = secondInput

secondInput = tmp

}

match(firstInput: &firstValue, secondInput: &secondValue

33
New cards

What is the correct swift code that calculates the circumference of a circle:

let diameter = 25.3

var circumference = diameter * Double.pi