1/32
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Which code creates an inheritance such the class Plant is a super class of the Class Tree
class Tree: Plant
3 multiple choice options
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)
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)
Which keyword is used to declare a constant in swift:
let
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
Which is the swift code that creates an array that stores 10 zeros
let arrayOfZeros = [Int](repeating: 0, count: 10)
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] ]
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
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
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"]
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
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
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
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
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)
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
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
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) { }
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
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 { }
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
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
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) { }
let -
defines a constant, multiple constants can be defined with one let separated by commas
var -
defines Int, Double, and String variables
_ (underscore) -
Tells the compiler you know of the return type but don't want to use it
Boolean -
A statement that is equal to either TRUE or FALSE
? (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
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
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
What are the levels of access control in swift:
Open, Public, Internal, Fileprivate, Private
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
What is the correct swift code that calculates the circumference of a circle:
let diameter = 25.3
var circumference = diameter * Double.pi