Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Working with Swift Structures Task 1: Do exercises on page 1: Structs, Instanc

ID: 3755918 • Letter: #

Question

-Working with Swift Structures


Task 1: Do exercises on page 1: Structs, Instances, and Default Values. Demo your code for GPS struct and Book struct. Upload screenshots for the record.



The two screenshot and the instructions above is all one question. please can you write the code using xcode, not c++, i will be glad if you do that. thanks.

Exercise Structs, Instances, and Default Values Imagine you are creating some kind of app for monitoring location. Create a GPS struct with two variable properties, latitude and longitude, both with default values of 0.0 Create a variable instance of GPS called somePlace. It should be initialized without supplying any arguments. Print out the latitude and longitude of somePlace, which should be 0.0 for both 12 Change somePlace's latitude to 51.514004, and the longitude to 0.125226, then print the updated values. 16 17 Now imagine you are making a social app for sharing your favorite variable properties: title, author, pages, and price. The default values for both title and author should be an empry string pages should default to O, and price should default to 0.0. books. Create a Book struct with four

Explanation / Answer

Creating a GPS struct with two variables:-

struct GPS

{

   double latitude = 0.0 ;

   double longitude = 0.0;

}


Creating variable instance someplace and printing the values of latitude and longitude:-

int main()

{

   struct GPS somePlace;

somePlace.latitude = 0.0;

somePlace.longitude = 0.0;

printf("%f",somePlace.latitude);

printf("%f",somePlace.longitude);

   // changing the values of variables and printing the values

somePlace.latitude = 51.514004;

somePlace.longitude = 0.125226;

  

   printf("%f",somePlace.latitude);

printf("%f",somePlace.longitude);

return 0;

}

BOOK STRUCT:-

struct book

{

   char title[];

char author[];

int pages = 0;

float price = 0.0;

}


Creating variable instance favouritebook and printing the values of struct variables:-

int main()

{

   struct book favouritebook;

  

printf("%s",favouritebook.title);

   favouritebook.title = "the mistress of spices";

   favouritebook.author = "chitra banerjee";

   favouritebook.pages = 291;

   favouritebook.price = 304.0;

printf("%s",favouritebook.title);

printf("%s",favouritebook.author);

printf("%d",favouritebook.pages);

printf("%f",favouritebook.price);

return 0;

}