Question: I need help with the following cod can you please add the following to the C code below Thank you here i have the code
I need help with the following cod can you please add the following to the C code below
Thank you
here i have the code
and the following part is the questions
#include
struct address_tag { int houseNum; char street[30]; char city[30]; char state[3]; };
typedef struct address_tag Address;
struct person_tag { char firstName[20]; char lastName[20]; Address addr; };
typedef struct person_tag Person;
void printAddress(Address addr); void printPerson(Person per); void displayPeople(Person ppl[], int pplCount); void addPerson(Person newPerson, Person ppl[], int *pplCount); void moveToTacoma(Person *per); void moveAllToTacoma(Person ppl[], int pplCount);
int main(void) { Person people[10] = { { "Joseph", "Miller", { 10, "Downing", "London", "WA" } }, { "Anne", "Simpson", { 1600, "Pennsylvania Ave", "Columbia", "WA" } }, { "Peter", "Price", { 832, "Main St.", "Dallas", "TX" } } };
int peopleCount = 3;
displayPeople(people, peopleCount);
Person historicFigure = { "Thea", "Foss", { 17, "Prospect St.", "Tacoma", "WA" } }; addPerson(historicFigure, people, &peopleCount); displayPeople(people, peopleCount);
moveAllToTacoma(people, peopleCount);
printf("After massive relocation "); // Now this works! displayPeople(people, peopleCount); return 0;
}
void printAddress(Address addr) { printf("%d %s ",addr.houseNum, addr.street); printf("%s, %s ",addr.city, addr.state); }
void printPerson(Person per){ printf("%s, %s ",per.lastName, per.firstName); printAddress(per.addr); }
void displayPeople(Person ppl[], int pplCount) { int i; for (i = 0; i < pplCount; i++) { printPerson(ppl[i]); printf(" "); } }
void addPerson(Person newPerson, Person ppl[], int *pplCount) { ppl[*pplCount] = newPerson; (*pplCount)++; }
void moveToTacoma(Person *per) { strcpy(per->addr.city, "Tacoma"); strcpy(per->addr.state, "WA"); }
void moveAllToTacoma(Person ppl[], int pplCount) { int i = 0; for (i = 0; i < pplCount; i++) { moveToTacoma(&ppl[i]); }
}
1.Add afloatmember to struct address_tagcalled latitudemake it the first entity in the structure.
2..Add afloatmember to struct address_tagcalled longitudemake it the secondentity in the structure.
3.Update the code in mainso that these 2newfieldsaregiven some valueswhen creating an array of people and printed in display functions
4.Compile and run in Emacs
5.Add function changeLocationlab03structs.cthat takes one Person variable and alatitudeand alongitudevalues for that persons house(3 arguments all together). Change the existing latitudeand longitude for that Persons address to the new ones. Test in mainby passing one of the array records to this functionalong with some new latitude and longitude values.
6.Compile and run in Emacs.
7.Add a function changeFirstNameto lab03structs.cthat takesonePerson variable and a new firstname for that person. Change the existing name to this new name. Assume that the new firstname is of appropriate length(no error checkingrequired). Test in mainby passing one of the array records to this functionalong with a new first name.
8.Compile and run in Emacs.Take a couple of screenshotsthat showyou editedand ran the code in Emacs.Do it for each lab partner since we are working remotely this quarter.
thank for helping....
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
