Question
Can someone please help answer some swift programming questions? Question 21 Which of the following declares a variable that is an implicitly unwrapped optional Double?
Can someone please help answer some swift programming questions?
Question 21
Which of the following declares a variable that is an implicitly unwrapped optional Double?
var income: Double |
var income: Double = 124300.0 |
var income: Double? |
var income: Double! |
Question 22
An implicitly unwrapped optional gives permission for the optional to be unwrapped automatically whenever it is used.
True |
False |
Question 23
Given the following Swift code:
var age: Int? = 20 if let age = age { print(age) }
For the line "if let age = age {", which of the following is true?
If age on the right of the = is not nil, then the age on the left of the = is the unwrapped value of age. |
If age on the right of the = is nil, then the code in the if statement executes. |
The age on the left of the = is tested to see if it is the same as the age on the right of the =. |
Question 24
Given the following code: var temperature: Double? = 98.6 if (temperature != nil) { print(temperature!) } else { print("The temperature has no value.") } What is the purpose of the exclamation mark after temperature in print(temperature!)?
To declare temperature as an implicitly unwrapped optional. |
To make temperature an optional. |
To force unwrap the temperature's optional value. |
To invoke an exception. |
To make the universe collapse into a wormhole. |
It generates an error message in the error log with the value of temperature in it. |
It bolds the temperature when it is printed. |
Question 25
The following code takes the string "49.95", constructs an Double from it, and assigns it to a variable called cost.
var cost = Double("49.95")
Not every string that can be passed to Double() to create a Double is a valid Double value. For example "Mizzou" does not represent a Double, so Double("Mizzou") can't create a Double.
Given this, what type is cost implicitly set to in the following line of code? var cost = Double("49.95")
nil |
Double |
Double? |
Double! |
Question 26
String, Array, and Dictionary are implemented as structures in Swift.
True |
False |
Question 27
Given: struct Font { var name: String var size: Double } Which of the following is the correct line of Swift code for creating an instance of a Font with a name of "times" and a size of 12.0?
let font = new Font(name: "times", size: 12.0) |
let font = Font(name: "times", size: 12.0) |
let font = Font("times", 12.0) |
let font = new Font("times", 12.0) |
Question 28
The === operator in Swift is used to do which of the following?
To test if two variables hold the same value. |
To test if two variables refer to the same instance of a class. |
To test if two instances have the same methods. |
To test if a type and optional type refer to the same value. |
Question 29
Given: struct Circle { var x = 0.0, y = 0.0, width = 0.0 } var circle = Circle()
Which of the following is used to set the width property of circle to 10.0 in Swift?
circle["width"] = 10.0 |
circle.setWidth(10.0) |
circle.width = 10.0 |
circle->width = 10.0 |
Question 30
Given: struct Circle { var x = 0.0, y = 0.0, width = 0.0 } let circle = Circle()
Is the following allowed?
circle.x = 12.3
Yes |
No |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started