Reference no: EM132211291
Question :
Write a program (in Q1.c) in which you consider the following structure:
struct student { int id; int score; };
Implement the following functions and demonstrate their functionality using the calls already existing in main():
Write a function struct student* allocate() that allocates a contiguous chunk of memory for 10 students and returns the pointer.
Write a function void generate(struct student* students) that populates the id and score fields of the array of 10 students passed as an argument. Each student should have an id that corresponds to their index in the array (i.e. the first student in the array should have id 0). If each student's id is x, the student's score should be (10 * x) % 50.
Write a function void output(struct student* students) that prints the ids and scores of all 10 students.
Write a function float avg(struct student* students) that computes the average of all scores.
Write a function int min(struct student* students) that computes the minimum of all scores.
Write a function void deallocate(struct student* stud) that frees the memory allocated to students. Check that students is not NULL (NULL == 0) before you attempt to free it.
Write a function void sort(struct student* stud) that sorts students by descending score (i.e. highest scores at the top). You must sort the array in-place - that is, you should not allocate any additional memory. You may not use C sorting routines like qsort(). You must implement the sort yourself.