Write a C program to calculate the weighted mean qualification of a student in a
ID: 3803319 • Letter: W
Question
Write a C program to calculate the weighted mean qualification of a student in a semester. The program must read from the keyboard the marks of the student -5 courses, 6 possible exams per lecture (at most). The program must ask the marks for a course until a mark greaterthanorequalto 5 is introduced, then following with the remaining courses. If a student does not pass a subject after the 6 exams, the program must show the message "reject" and ends. The data must be represented using two arrays, the first one (marks) stores the mark for each course, the second one (exam) stores the number of the exam in which the student passed the course. After reading the marks, the program must calculate and print the average qualification of the students who passed the courses by applying the weights: 1.25 if the course is passed in the first exam, 1 if the course is passed in the second exam, 0.9 for the third exam, 0.75 for the forth exam, 0.6 for the fifth exam, 0.5 for the sixth exam. Store the weights in a 1-dimension array of size 6 (weights).Explanation / Answer
c code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float marks[5][6] ;
float exam[5] ;
int no_exams = 0;
for (int i = 0; i < 5; ++i)
{
int flag = 0;
for (int j = 0; j < 6; ++j)
{
printf("%s%i%s%i ", "Enter marks of obtained in course ", (i+1), " in exam number ", (j+1));
scanf("%f", &marks[i][j]);
if(marks[i][j] >= 5)
{
no_exams = no_exams + j+1 ;
exam[i] = j+1;
flag = 1;
break;
}
}
if(flag == 0)
{
printf("%s ", "Reject!");
exit(0);
}
}
float weights[6] = {1.25, 1,0.9,0.75,0.6,0.5};
float average_qualification = 0;
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < exam[i]; ++j)
{
average_qualification = average_qualification + weights[j]*(marks[i][j]) ;
}
}
average_qualification = average_qualification/no_exams;
printf("%s%f ","Average Qualification in all the courses = ",average_qualification);
return 0;
}
Sample Output:
1)
Enter marks of obtained in course 1 in exam number 1
5
Enter marks of obtained in course 2 in exam number 1
4
Enter marks of obtained in course 2 in exam number 2
5
Enter marks of obtained in course 3 in exam number 1
5
Enter marks of obtained in course 4 in exam number 1
5
Enter marks of obtained in course 5 in exam number 1
3
Enter marks of obtained in course 5 in exam number 2
3
Enter marks of obtained in course 5 in exam number 3
3
Enter marks of obtained in course 5 in exam number 4
3
Enter marks of obtained in course 5 in exam number 5
3
Enter marks of obtained in course 5 in exam number 6
3
Reject!
2)
Enter marks of obtained in course 1 in exam number 1
5
Enter marks of obtained in course 2 in exam number 1
5
Enter marks of obtained in course 3 in exam number 1
5
Enter marks of obtained in course 4 in exam number 1
5
Enter marks of obtained in course 5 in exam number 1
5
Average Qualification in all the courses = 6.250000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.