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

Answer the following in C source code I) Create a struct Person with attributes

ID: 3699520 • Letter: A

Question

Answer the following in C source code

I) Create a struct Person with attributes “char name[20]”, “int age”, “double score”. Use typedef such

that you can refer to “struct Person” using “Person”. You may assume that no Person has a name longer

than 19 chars, i.e., it will fit into the array of length 20.

II) Write a function “Person createPerson(char name[], int age,double score) that returns a person with

attributes as specified by the inputs. (Remember that you have to use a string function to copy over the

“name” to the the Person.)

III) Write a function void printPerson(Person p) that prints the attributes of the Person p to the screen.

Print the attributes using printf and the format string “%s %d %d ”, i.e., printf(“%s %d %d ”, ...).

Ex.

Name age score

Explanation / Answer

I) Create a struct Person with attributes “char name[20]”, “int age”, “double score”. Use typedef such that you can refer to “struct Person” using “Person”. You may assume that no Person has a name longer than 19 chars, i.e., it will fit into the array of length 20. Answer : typedef struct { char name[20]; int age; double score; } Person; II) Write a function “Person createPerson(char name[], int age,double score) that returns a person with attributes as specified by the inputs. (Remember that you have to use a string function to copy over the “name” to the the Person.) Answer: Person createPerson(char name[], int age,double score) { Person p; strcpy(p.name,name); p.age = age; p.score = score; return p; } III) Write a function void printPerson(Person p) that prints the attributes of the Person p to the screen. Print the attributes using printf and the format string “%s %d %d ”, i.e., printf(“%s %d %d ”, ...). Answer : void printPerson(Person p) { printf(“%s %d %d ”, p.name,p.age,p.score); }