Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CODE IN C PLEASE Person struct The Person struct should include three fields: 1. first_name to store a string of characters 2. last_name to store

CODE IN C PLEASE

Person struct

The Person struct should include three fields:

1. first_name to store a string of characters

2. last_name to store a string of characters

3. age to store an integer

You should write the struct in such a way that it can be declared like: Person p;.

You should define Person as a data type.

main() function

The main function should call the read_file function to read the file and return an array of

Person. It should pass the name of the file and an int reference to get the count of the Persons

read from the file. After reading the file, it should print the number of records read. It should

then call the print_parr function to print the actual records read from the file. Next, it should

call the avg_age function print the average age.

1.Declare a pointer to an array of Person

2.Declare integer for count

3.Read the array from file

4.Print the count of records read

5.Print the array of Person

6.Print the average of age in array of Person

print_person() function

This function accepts a Person and prints the data one line separated by spaces. It should print

a new line after each Person.

print_parr() function

This function accepts an array of Person and the count of Persons, and calls the print_person

function passing each Person in the array.

make_parr() function

This function should accept the size of the array of Person to be allocated, check for success of

the memory allocation and return the allocated array.

read_people() function

This function should receive the name of the file and a reference to an integer from the calling

function and return an array of Person. It should open the file for reading and, before

attempting to read, it should make sure that the file opened properly. It should read all the

records in the file to count them and call the make_parr function to allocate an array of Person

to contain all the Persons in the file, and no larger. It should then read the records one at a

time, tokenize the fields for each Person and copy them to the array of Person. When done

reading the file, it should return the array of Person.

image text in transcribed

Sample output Read 3 records Homer Simpson 50 Bart Simpson 12 Marge Simpson 45 The average age is: 35.67 Process returned 0 (0x0) execution time 0.282 s Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions