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 latitude and longitu your GPS struct again, but this time do not provide default values. Both properties should be of type Double. truct GPS { 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 values of somePlace's properties.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

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
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
Transcribed Image 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{
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)
Transcribed Image 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)
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY