To write a program that first reads the total number of student in a class. Then, for each student, the program asks for student ID (represented as 5 digits integer), IC (the last four digits of IC number) and the number of subject(s) taken. Each subject is represented by a subject code consisting of four characters followed by three digits integers e.g. CSEB213, where the last integer represents the credit hour for the subject. For each subject, the program then asks for the mark obtained by the student for that subject. Based on the mark entered, the program determines the corresponding grade point (GP) value e.g. if the mark obtained is 89, GP value is 4.00. After the mark for the last subject of a student is entered, the program then calculates the grade point average (GPA) of the student for that semester and proceeds asking the number of subject(s) taken by the next student in the class. The same procedures repeat until the last mark for the last subject taken by the last student is entered. Finally the program displays in descending order, the student ID, IC and GPA of all students in the class.
Requirements
To ensure modularity is practiced in writing the program, these are the requirement functions.
getNos() function that prompts for the number of students in the class (of long integer) and returns that number.
getTotal() function that prompts for the total number of subject taken by a student (of type integer) and returns that number.
getID() function that prompts for the student ID (of type long integer) and returns that ID.
getIC() function that prompts for the student IC (of type long integer) and returns that IC.
getPoint() function that takes a mark (of type double) as argument and return the corresponding grade point value (also of type double) for the mark. For this purpose, please use the information in the following table to ensure consistency.
Marks Range Points
85 - 100 4.00
80 - 84.9 3.75
75 - 79.9 3.33
70 - 74.9 3.00
65 - 69.9 2.75
60 - 64.9 2.33
55 - 59.9 2.00
50 - 54.9 1.75
45 - 49.9 1.33
40 - 44.9 1.00
39.9 and below 0
getCH() function that takes the subject code (of type array of characters) and return the last element of that array (of type integer).
getGP() function that takes a credit hour value (of type integer) and a mark (of type double), and returns the grade point (GP) value (of type double) multiplied by the credit hour value for a subject.
getGPA() function that takes the total credit hour(s) taken by a student (of type integer) for that semester (of type integer) and returns the GPA obtained (of type double) by that student.
sortGPA() function that takes an array of GPAs (of type double), a 2 dimensional array of student IDs and corresponding ICs and the number of student in the class (of type integer). This function will sort the arguments in descending GPA order.
printResult() that takes a 2 dimensional array of student ID and corresponding IC (of type long integer), an array of corresponding GPA (of type double) and the number of student in the class (of type integer). This function then prints the result of students in descending GPA order.
For each of the functions above, decide which of them are general purpose and which are specific to the program. Provide your reasons of not more than five lines of words for each function.
Evaluation
For evaluation, your libraries will called from an application file containing the following main() function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#define MAX_STUD 5
void main(void)
{
int i, total, nos;
long int idarray[MAX_STUD][2];
double gparray[MAX_STUD];
total = getTotal();
for (i=0;i<total;i++)
{
idarray[i][0] = getID();
idarray[i][1] = getIC();
nos = getNos();
gparray[i] = getGPA(nos);
}
sortGPA(gparray, idarray, total);
printResult(idarray, gparray, total);
}
|
Hints
Shown below is a function that takes a string of 7 characters as input and return the last character in the string which is converted to type int. You may find this function helpful in writing your program.
1 2 3 4 5 6 7 8
|
int charToInt(char string[7])
{
int value;
char str[2];
str[0] = string[6];
value = atoi(str);
return value;
}
|
Note that you have to include stdlib.h to use atoi() function.
*Could someone help me. I am getting crazy in doing this. Newbie here.