Share
Explore

Final Exam w23 MADS3004 Introduction to Swift Programming

Final Exam: MADS3004 Introduction to Swift Programming
Instructions:
This exam consists of 4 sections (A, B, C, and D) with a total of 20 questions.
The total marks for this exam are 100.
Please read each question carefully and provide your answers in the space provided.
Show your work where necessary.
No electronic devices are allowed during the exam.
Section A: Multiple Choice Questions (2 marks each, total 20 marks)
What is the primary platform for Swift programming?
a. Android
b. Windows
c. macOS
d. Web
Which keyword is used to define a constant in Swift?
a. let
b. const
c. var
d. static
What is the type of the following variable in Swift?


Copy code
let x = 5.0


a. Int
b. Double
c. Float
d. String
Which method is used to handle exceptions in Swift?
a. try-catch
b. do-try-catch
c. throw-catch
d. error-try-catch
In Swift, how can you define an optional variable?
a. Using the ? symbol
b. Using the ! symbol
c. Using the * symbol
d. Using the & symbol
Section B: Fill in the Blanks (2 marks each, total 10 marks)
In Swift, the _______ keyword is used to define a class.
A _______ is a collection of key-value pairs in Swift.
The _______ statement is used to terminate a loop or switch statement in Swift.
The _______ keyword is used to define a computed property in Swift.
The Swift programming language was developed by _______.
Section C: Short Answer Questions (4 marks each, total 20 marks)
Explain the difference between a variable and a constant in Swift.
Describe the concept of optionals in Swift and provide an example.
Explain the process of error handling in Swift using a brief example.
Describe the purpose and usage of initializers in Swift.
Explain the difference between a class and a struct in Swift.
Section D: Programming Questions (total 50 marks)
Write a Swift function that accepts an integer array and returns the sum of all even numbers in the array. (10 marks)
Create a Swift class named Circle with properties radius and color, and a method to calculate the area of the circle. (10 marks)
Implement a Swift protocol named Drawable with a method draw(). Create a Rectangle class that conforms to the Drawable protocol. (10 marks)
Write a Swift program that demonstrates the use of closures to sort an array of integers in ascending order. (10 marks)
Implement a Swift program that demonstrates the use of error handling to catch and handle errors when reading from a file. (10 marks)
End of Exam
Good luck!
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.