Write a program to manage the grades of students in a class. To represent the in
ID: 3604093 • Letter: W
Question
Write a program to manage the grades of students in a class. To represent the information of each student define a structure type named student. The members of this structure should be: 1. an integer that represents the student’s ID number, 2. an array of 15 characters storing the first name, 3. an array of 15 characters storing the last name, 4. an integer that represents the project 1 grade, 5. an integer that represents the project 2 grade, 6. a floating point representing the final course grade. To store the list of students use an array of pointers of type student*. Each pointer in the array has to point to a structure variable of type student representing the information of one student. The array has to be SORTED in increasing order of students’ ID numbers. Define the following functions student **create_class_list( char *filename, int *sizePtr ) Function create_class_list() reads the students’ ID numbers and names from the input file (a text file), allocates the memory necessary to store the list of students and initializes the students ID’s and names. Note that variable filename represents a string which stores the name of the input file. Additionally, note that the input file is a text file which contains a positive integer representing the number of students at the beginning, then on each line the id of a student, blank, first name, blank, last name. The ID numbers appear in the file in increasing order. The students should appear in the class list in increasing order of their IDs, too. The function should also appropriately change the value of the variable in the caller that is supposed to store the number of students in the class. Note that parameter sizePtr is a pointer to that variable. The function has to additionally initialize all students’ grades to 0 (note that this is done automatically if you allocate the memory for each student variable using calloc()). Finally, the function has to return a pointer to the beginning of the array of pointers to student. You may assume that each student’s first name, respectively last name, has no more than 14 characters. Example of an input file containing the info of three students: 3 1200 Isaac Newton 4580 Alan Turing 9000 Elvis Presley Note: Use the variable filename as the first argument of fopen()when opening the file. int find( int idNo, student **list, int size ) Parameter list is a pointer to the beginning of the array of pointers representing the class list. Parameter size represents the number of students in the list (you may assume it is larger than or equal to 0). Function find() determines if there is a student in the list whose ID number equals idNo. If there is such a student the function returns its position (i.e., index) in the list (note that indexing starts with 0). If such a student is not found the function returns -1. void input_grades( char *filename, student **list, int size ) Parameter list is a pointer to the beginning of the array of pointers representing the class list. Parameter size represents the number of students in the list. Parameter filename represents the name of a text file. Function input_grades() reads the project 1 and project 2 grades from the text file and inputs them in the class list (in other words, it modifies the information of each student accordingly). The file contains the information for each student on a separate line, first the ID number, then the project 1 grade followed by the project 2 grade, all separated by white spaces. Note that the file is not sorted, therefore the ID numbers do not necessarily appear in increasing order. You may need to use function find() to determine the position of a student in the list. compute_final_course_grades() - you need to figure out the prototype Function compute_final_course_grades() computes the final course mark for each student as the arithmetic average of project 1 and project 2 grades. The function accordingly modifies the information in the class list. output_final_course_grades() - you need to figure out the prototype Function output_final_course_grades() outputs the final course marks of all the students in a file whose name is passed to the function, as follows. The first line in the file must contain the number of students. Each line after that should contain an ID number followed by the corresponding grade, separated by white spaces. The data has to be sorted in increasing order of ID numbers. void print_list( student **list, int size) Parameter list is a pointer to the beginning of the array of pointers representing the class list. Parameter size represents the number of students in the list. The function has to print on the screen the information of each student in the list, one student per line. For instance, the info of a student may appear as follows: ID: 1200, name: Isaac Newton, project 1 grade: 100, project 2 grade: 100, final grade: 100.00 void withdraw(int idNo, student **list, int *sizePtr) Parameter list is a pointer to the beginning of the array of pointers representing the class list. Parameter sizePtr is a pointer to the variable in the caller that stores the number of students in the list. Function withdraw() has to remove from the class list the student whose ID number equals idNo. If the student is not in the list the function has to print a message specifying that. When a student is removed from the class list the vacated spot in the array of pointers must be filled by shifting one position to the left all “students” between the vacated position and the end of the array. Additionally, the structure variable storing the information of the student who was withdrawn has to be deallocated. NOTE: Use the C library function free() to deallocate memory that was allocated with calloc() or malloc(). void destroy_list(student **list, int *sizePtr) Parameter list is a pointer to the beginning of the array of pointers representing the class list. Parameter sizePtr is a pointer to the variable in the caller that stores the number of students in the list. Function destroy_list() deallocates all the memory used to store the class list and sets to 0 the variable in the caller that stores its size. NOTE: Use the C library function free() to deallocate memory that was allocated with calloc() or malloc(). Write a program to manage the students’ grades, which uses all the functions specified above. Your program has to invoke function withdraw() at least three times, one time corresponding to an unsuccessful withdrawal (in other words, when the student is not in the list) and two times corresponding to successful withdrawals. NOTE: The only C library functions you are allowed to use are those for input/output (including from/to files) and for memory allocation/deallocation
Explanation / Answer
#include struct student { char name[50]; int roll; float marks; } s[10]; int main() { int i; printf("Enter information of students: "); // storing information for(i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.