The deadline for this lab is Wednesday 11 April 2007, 11:45:59 hours. Strictly no submissions will be accepted after the deadline.
CAP = [Sum of (grade point * modular credit)]/sum[modular credits]
Cumulative Grade Points = Sum of (grade point * modular credit)
A line sample of the file “init.txt” is shown below:
Yang Fei 28 108
It means the student named Yang Fei has a CAP of 3.86 (108/28) after taking 28 modular credits.
The second file “exam_results.txt” stores the exam results of the latest semester, which needs to be input to the database and the CAP updated for each student. The file content is grouped by modules. Each module starts with a separate line indicating the module code (starting with a “#”) and its MC, followed by student grades. For your convenience, the grades has already been translated into numeric scores (0 to 5). Students that have no records in the database will be added in. For example:
#EG1108 3 Soo Yuen Jien 3.5 Yang Fei 4.5
means for the module EG1108 which worth 3 MCs, Soo Yuen Jien got a "B" (he will be added into the database since he is a new student), and Yang Fei finished with "A-" (his record will be updated).
For example, let’s say “init.txt” contains the following lines:
Raymond Tan 110 537 Beatrice Luca 30 116 Yang Fei 28 108
“exam_results.txt” contains:
#CS1101C 4 Beatrice Luca 4.5 Yang Fei 4.5 #EG1108 3 Soo Yuen Jien 3.5 Yang Fei 4.5 #MA1505 4 Yang Fei 5.0 Raymond Tan 4.0
Your program should print the following result on to the screen:
Raymond Tan 114 4.85 Beatrice Luca 34 3.94 Yang Fei 39 4.09 Soo Yuen Jien 3 3.50
You may assume that there are at the most 1000 different students, each student's name is at the most 30-characters long and contains only alphabets, and each module code is at the most 10-characters long and contains only alphabets and digits. You are not required to handle file I/O errors.
Following are some built-in String functions that may be helpful (it is not compulsory for you to use them).
int strcmp( const char *str1, const char *str2 );
The function strcmp() compares two strings, and returns 0 if they are the same, positive integer for str1 is greater than str2 and negative if str1 is less than str2
char *strcat( char *str1, const char *str2 );
The strcat() function concatenates str2 onto the end of str1, and returns str1.
Remember to add the line #include <string.h> since we are using the above functions related to strings.
#include <stdlib.h> double atof( const char *str ); int atoi( const char *str );
The function atof() converts str into a double, then returns that value. str must start with a valid number, but can be terminated with any non-numerical character, other than "E" or "e". Similarly, atoi() converts str into an integer, then returns that value.e.g.
x = atof( "42.0is_the_answer" ); i = atoi( "512" );
would result in x being set to 42.0 and i being set to 512. Note that you need to #include <stdlib.h> for these 2 functions.
Do not use any structures or any form of dynamic memory allocation (using malloc or calloc) in your program, else no credit will be given.
Remember to submit your program frequently using the submit studb.c command, and check your submission using the check command.
All the best!