Question
1)Program in C. I) Write a function void loadPeople(char fileName[],Person people[],int * length) that reads a file with the format described below. fileName is the
1)Program in C.
I) Write a function void loadPeople(char fileName[],Person people[],int * length) that reads a file with the format described below. fileName is the name of the file. people is the array where you store the people in the file. (You may assume that the array is long enough to store all the people in the file.) length should be set to equal the number of people that are stored in the file.
Ex. of input file
4
John 21 70
Sean 45 98
Andrew 21 34
Emily 32 80
N = (#Number of people)
Name_of_person_1 Age_of_person_1 Score_of_person_1
..
Name_of_person_N Age_of_person_N Score_of_person_N
II) Write a function Person findOldest(Person people[], int length) that returns the oldest person in the array. If there are multiple people that are equally old, just return one of them. Use only a single for loop to solve the problem. You are not allowed to change the order or the people in the array (do NOT sort the array based on the age).
III) Write a function void sortByScore(Person people[], int length) that sorts the people in the array based on each persons score. The people should be ordered from highest score to the lowest score. People with the same score may be sorted in any order.
IV) Write a function void sortByName(Person people[],int length) that sorts the people in the array based on the name of each person. People with the same name may be sorted in any order.
The function prototypes and a sample main is provided below:
void printPerson(Person p);
void printPeople(Person people[],int length);
void loadPeople(char fileName[],Person people[],int * length);
Person findOldest(Person people,int length);
void sortByScore(Person people[],int length);
void sortByName(Person people[], int length);
void main(){
Persons people[100];
int length;
char fileName[] = "peopleFile";
loadPeople(fileName,people,&length);
printPeople(people,length);
Person p = findOldest(people,length);
printPerson(p);
sortByScore(people,length);
printPeople(people,length);
sortByName(people,length);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started