Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Swift command line for macOS (open xcode, create a new xcode project, macOS, command line tool) or playground, practice the following exercises: Exercise: Swift

Using Swift command line for macOS (open xcode, create a new xcode project, macOS, command line tool) or playground, practice the following exercises:

Exercise: Swift Classes

  1. Create a class named Flight with 3 properties: airlineName, number of seats, number of customers with confirmed seats
  2. Create a custom initializer in the class to set its properties
  3. Create a method that returns the number of seats available after booking
  4. Create another class named Boeing as subclass of Flight and initialize it using the custom initializer in the flight class
  5. Calculate number of seats available in the Boeing flight and print its details
  6. Now, create one more class called Airbus as subclass of Flight with custom initializer. Override the calculate number of seats method to ignore 2 seats that are only available for cabin crew and rewrite it.
  7. Also, create a subclass of Airbus that again calculates number of seats using the overridden method above

Exercise: Enum

  1. Define an enum Month which consists of all the months in a year.
  2. Next, define a function NumberOfDays() which accepts the month and prints out Number of Days for that month. {Use switch case statement}

Exercise: Structures

  1. Define a structure, Cube, having 3 parameters length, breadth and height to encapsulate the data
  2. Create an area function inside struct that calculates the cubes area
  3. Instantiate cube1 with values of length, breadth and height.
  4. Assign cube1 to cube2
  5. Set length of cube2 to some other value
  6. Calculate and print area of both cubes

Exercise: Protocols

  1. Define a protocol MastersDegree, define following functions inside this protocol:

  • printGPA() - This should print the GPA

  • isSmartphonesCourseCompleted() - This should print if the student has completed smartphones course or not

  1. Now define a class Student which adopt MastersDegree protocol and provide the actual implementation

Exercise: Extensions

  1. Extending the datatype String add methods: stringLength() and concatenateString (Use another string as Smartphones)

  1. Next, create a constant named stringExtension of String initializing it to a string of your choice. Use the extended functionality in point 1 and print out the values in the console.

  1. Complete the code below:

class division {

var number: Int = 0

}

extension Division {

//Define a method to divide 2 numbers and print the result

}

let div = division()

div.dividedBy(number1: 1800, number2: 3)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions