0

grades average

I have to calculate the average grade of each student at each subject. The grades, students and subjects are read from a file. name file look like this: 2, student1 7, student2 1, student3 .... subject file : 5, math 3, physics 8, geography ... grades file: // date, number of grades // student code, subject code, grade 18.06.2020, 3 2, 3, 10 1, 8, 7 7, 5, 9 19.06.2020, 2 8, 3, 8 3, 8, 6 .... I stored these values in structs: struct Subject { char subjectName[N]; int code; }; struct Students { char studentName[N]; int code; }; struct Grades { int grade[N][3]; char date[N]; int number_of_grades; // number of grades in a day }; struct Date { int number_of_days; // total number of days int number_of_students; // total number of students int number_of_subjects; // total number of subjects }data; Now I think I need to store these values depending on the students and subjects code and after that calculate the average. Can you give me an advice on how can i solve these?

8th Jul 2020, 4:40 PM
tibi
tibi - avatar
7 Respostas
+ 2
You have a student (class or struct) with n subjects (field / member) with each n grades (field / member) of each at a specific date (which is completely irrelevant for your requested output). Finally you want to calculate each average of all student.subject.grades in a loop over all student.subjects in a loop over all students. Your current structures doesn't match this structure at all. You might solve this problem with your separated structs as well, but this can only work, if you calculate them while reading the file and with many temporary variables to store the current state of parsing and it will only work this way, if the file is strictly sorted.
8th Jul 2020, 5:45 PM
Sandra Meyer
Sandra Meyer - avatar
0
The structs are dynamically allocated. The student and subject struct contain only the name and code. The first grade struct contain all grades for the first day, the following struct contain the grades for the second day and so on. Files are not sorted.
9th Jul 2020, 12:37 PM
tibi
tibi - avatar
0
I hate writing C, would a Java code snippet help you as well to understand?
9th Jul 2020, 2:31 PM
Sandra Meyer
Sandra Meyer - avatar
0
I don't know java.
9th Jul 2020, 5:25 PM
tibi
tibi - avatar
9th Jul 2020, 6:33 PM
Sandra Meyer
Sandra Meyer - avatar
0
python is ok
9th Jul 2020, 7:01 PM
tibi
tibi - avatar
0
It's too late for me today for Python, but I think Java and especially the classes stuff should be a little closer to C written in Java, even if you've not already learned it. Go there: https://code.sololearn.com/cLfEsROHGtzc And use the modified sample input: 1, student1 2, student2 3, student3 nextfile 1, math 2, physics 3, geography nextfile 18.06.2020, 3 1, 1, 5 1, 2, 5 1, 3, 5 2, 1, 7 2, 2, 7 2, 3, 7 3, 1, 10 3, 2, 10 3, 3, 10 19.06.2020, 2 1, 1, 7 1, 2, 7 1, 3, 5 2, 1, 5 2, 2, 7 2, 3, 7 3, 1, 2 3, 2, 4 3, 3, 6
9th Jul 2020, 8:56 PM
Sandra Meyer
Sandra Meyer - avatar