Professional Documents
Culture Documents
Đề thi giữa kỳ UTM
Đề thi giữa kỳ UTM
import Foundation
let names = ["Serenity", "Sulaco", "Enterprise",
"Galactica"]
import Foundation
struct Spaceship {
var name: String {
willSet {
print("I'm called \(newValue)!")
}
}
}
var serenity = Spaceship(name: "Serenity")
serenity.name = "TARDIS"
Đáp án:
A. "I'm called Serenity!"
B. "I'm called Serenity!", "I'm called TARDIS!"
C. "I'm called TARDIS!"
D. Nothing will be output
E. This code will compile but crash
F. This code will not compile
import Foundation
let oneMillion = 1_000_000
let oneThousand = oneMillion / 0_1_0_0_0
print(oneThousand)
import Foundation
struct Starship {
var name: String
}
import Foundation
var i = 2
repeat {
i *= i * 2
} while i < 100
print(i)
import Foundation
final class Dog {
func bark() {
print("Woof!")
}
}
class Corgi : Dog {
override func bark() {
print("Yip!")
}
}
let muttface = Corgi()
muttface.bark()
import Foundation
var i = 2
do {
print(i)
i *= 2
} while (i < 128)
Đáp án:
A. 2, 4, 8, 16, 32, 64
B. 2, 4, 8, 16, 32, 64, 128
C. 4, 8, 16, 32, 64
D. 4, 8, 16, 32, 64, 128
E. This code will compile but crash
F. This code will not compile
import Foundation
var myStr: String = "0"
myStr = "shiny"
import Foundation
let names = ["Chris", "Joe", "Doug", "Jordan"]