C programming Lab 2 – Dynamic Memory Allocation



In this problem, you will read a set of student data and their grading information from a file and then process them and then write the requested data to another file.






In a course, there are N number of students. Each student has to complete one assignment, attend M number of quizzes and one final exam.


The total score of the student is calculated as follows:

The total score = sum of scores from M quizzes + score in the assignment + score in the final exam Write a program that will perform the following operation:

Define a student structure to store student’s last name (one word), scores for one assignment, M quizzes (M is an input from file), final exam, and total.


Take number of students N and number of quizzes M as the input from the file.


Then Dynamically allocate memory for N students. For each student, dynamically allocate memory to store scores of M quizzes.


Take input for all the scores for quizzes, assignments, and final exams for all the students. Calculate the total scores for each student and store it in the corresponding structure. Do this whole task in a separate method and return the appropriate pointer.



The function header should look like this:

students* readData(FILE *in, int *noOfRecords, int *noofquiz)



Display the student’s details who achieved the highest total score. Also write the same details into a file output.txt.


Sample Input: All the inputs, including N and M will come from an input file called input.txt The input file is structured as follows:



3 2

adam 10 12 9 45

jones 8 11 7 41

Sahar 10 12 10 45

(please copy them in a text file and name it input.txt) For more clarification:

3 2 //N and M

adam 10 12 9 45 // last name, assignment score, scores for M number of quizzes, and final exam score jones 8 11 7 41

Sahar 10 12 10 45


Sample output.txt: (Sahar , 77)

Need a custom answer at your budget?

This assignment has been answered 6 times in private sessions.

© 2021 Codify Tutor. All rights reserved