Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

These are following questions that require fixing or to be done in SWIFT: 1. Create a variable instance of Height called someonesHeight. Use the initializer

These are following questions that require fixing or to be done in SWIFT:

1. Create a variable instance of Height called someonesHeight. Use the initializer for inches to set the height to 65. Print out the property for height in centimeters and verify that it is equal to 165.1. (edit code below)

struct Height{

var inches: Int

}

1a. Now create a variable instance of Height called myHeight and initialize it with your own height. Verify that both heightInInches and heightInCentimeters are accurate. (write code, use structures)

2. In the Height struct below, height is represented in both inches and centimeters. However, if heightInInches is changed, heightInCentimeters should also adjust to match it. Add a didSet to each property that will check if the other property is what it should be, and if not, sets the proper value. If you set the value of the other property even though it already has the right value, you will end up with an infinite loop of each property setting the other. Create an instance of Height and then change one of its properties. Print out the other property to ensure that it was adjusted accordingly. (edit code below)

struct Height {

var heightInInches: Double{

}

var heightInCentimeters: Double{

}

3. Add to RunningWorkout a type method mileTimeFor(distance:time:) where distance and time are both of type Double. This method should have a return value of type Double. The body of the method should calculate the average mile time needed to cover the passed in distance in the passed in time. Assume that distance is in meters and that one mile is 1600 meters. Call the method from outside of the struct and print the result to ensure that it works properly. (edit code below)

struct RunningWorkout {

var distance: Double

var time: Double

var elevation: Double

}

3a. Go back and add a type property for meterInFeet and assign it 3.28084. Then add a type property for mileInMeters and assign it 1600.0. Print both of these values below. (edit the code above)

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

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions