Exercise - Memberwise and Custom Initializers If you completed the exercise Structs, Instances, and Default Values, you created a GPS struct with default values for properties of latitude and...


How do I solve this using Swift code? Question 3 of 10 part 1


Please find attached an image of the previous exercise I did before as a reference. I just don't know how to do it without providing default values.


Exercise - Memberwise and Custom Initializers<br>If you completed the exercise Structs, Instances, and Default Values, you created a GPS struct with default values for properties of latitude and longitude. Create<br>your GPS struct again, but this time do not provide default values. Both properties should be of type Double.<br>6<br>struct GP {<br>7<br>8<br>9.<br>}<br>Now create a constant instance of GPS called somePlace, and use the memberwise initializer to set latitude to 51.514004, and longitude to 0.125226. Print the<br>values of somePlace's properties.<br>11<br>12<br>In Structs, Instance, and Default Values, you also created a Book struct with properties title, author, pages, and price. Create this struct again without default<br>values. Give each property the appropriate type. Declare your favoriteBook instance and pass in the values of your favorite book using the memberwise initializer.<br>Print a statement about your favorite book using favoriteBook's properties.<br>14<br>15<br>

Extracted text: Exercise - Memberwise and Custom Initializers If you completed the exercise Structs, Instances, and Default Values, you created a GPS struct with default values for properties of latitude and longitude. Create your GPS struct again, but this time do not provide default values. Both properties should be of type Double. 6 struct GP { 7 8 9. } Now create a constant instance of GPS called somePlace, and use the memberwise initializer to set latitude to 51.514004, and longitude to 0.125226. Print the values of somePlace's properties. 11 12 In Structs, Instance, and Default Values, you also created a Book struct with properties title, author, pages, and price. Create this struct again without default values. Give each property the appropriate type. Declare your favoriteBook instance and pass in the values of your favorite book using the memberwise initializer. Print a statement about your favorite book using favoriteBook's properties. 14 15
struct GPS{<br>var latitude: Double=0.0<br>var longitude: Double=0.0<br>}<br>var somePlace=GPS()<br>//printing the latitude and longitude of the place<br>print(somePlace. latitude)<br>print(somePlace. longitude)<br>//changing somePlace latitude and longitudes<br>somePlace.latitude=51.514004<br>somePlace.longitude=0.125226<br>//printing the updated values<br>print(somePlace.latitude)<br>print(somePlace. longitude)<br>struct Book{<br>//by default title and author are empty string<br>var title: String=

Extracted text: struct GPS{ var latitude: Double=0.0 var longitude: Double=0.0 } var somePlace=GPS() //printing the latitude and longitude of the place print(somePlace. latitude) print(somePlace. longitude) //changing somePlace latitude and longitudes somePlace.latitude=51.514004 somePlace.longitude=0.125226 //printing the updated values print(somePlace.latitude) print(somePlace. longitude) struct Book{ //by default title and author are empty string var title: String=""| var author: String="" //pages are 0 var pages: Int=0 //price is of Double data type with 0 var price: Double=0.0 } // variable instance named favoriteBook for Book struct var favoriteBook=Book() //printing the title of instance print(favoriteBook.title) //changing values of the instance favoriteBook favoriteBook=Book(title:"12 Rules for Life",author:"Jordan Peterson",pages:448,price:14.99) //printing each of the instance print(favoriteBook.title) print (favoriteBook.author) print(favoriteBook.pages) print(favoriteBook.price)
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here