#include <stdio.h>
#include <stdlib.h>
#define rSize 3
#define cSize 4
void accScores(int [rSize][cSize]);
void Menu(int [rSize][cSize]);
void disp_allScore(int [rSize][cSize]);
int pick_student(); //Pick which of the student
void disp_specScore(int [rSize][cSize], int); //Display Specific Student's score
void disp_specAvgScore(int [rSize][cSize], int); //Display Specific Student's Average Score
void disp_quizStat(int [rSize][cSize]); //Display Quiz Statistics
void accScores(int scores[rSize][cSize]){
int row, col;
for(row = 0; row < rSize; row++)
{
printf("\nStudent %d:\n", row+1);
for(col = 0; col < cSize; col++)
{
printf("Quiz %d: ", col+1);
scanf("%d", &scores[row][col]);
}
}
}
int main(){
int scores[rSize][cSize];
int type;
printf("Input the scores of 3 students in the 4 quizzes;");
accScores(scores);
Menu(scores);
return 0;
}
void Menu(int scores[rSize][cSize])
{
system("cls");
int x;
do
{
printf("==================\n");
printf("[1] Display All Scores\n");
printf("[2] Display Scores of a specific student\n");
printf("[3] Display Average Score of a specific student\n");
printf("[4] Display Quiz Statistics\n");
printf("[0] exit\n");
printf("==================\n");
printf("Your choice ==> ");
scanf("%d", &x);
system("cls");
}while(x<0 || x>4);
switch(x)
{
case 0:
{
break;
}
case 1:
{
disp_allScore(scores);
Menu(scores);
break;
}
case 2:
{
int c = pick_student();
system("cls");
if(c > 0)
{
disp_specScore(scores, c);
}
Menu(scores);
break;
}
case 3:
{
int c = pick_student();
system("cls");
if(c > 0)
{
disp_specAvgScore(scores, c);
}
Menu(scores);
break;
}
case 4:
{
disp_quizStat(scores);
Menu(scores);
break;
}
}
}
void disp_quizStat(int scores[rSize][cSize])
{
int i, j;
float total_avg = 0;
printf("Quiz Statistics\n");
printf("===============================================\n");
printf("Quiz\t\tAverage\tHighest\tLowest");
printf("\n===============================================");
for(i=0; i<cSize; i++)
{
float avg = 0;
int high, low;
high = low = scores[0][i];
for(j=0; j<rSize; j++)
{
int temp = scores[j][i];
avg += temp;
if(temp > high)
{
high = temp;
}
if(temp < low)
{
low = temp;
}
}
total_avg += avg/4;
printf("\nNo. %d\t\t%.2f\t%d\t%d\n", i+1, avg/4, high, low);
}
printf("\nTotal Quiz Average Score: %.2f\n", total_avg/4);
printf("\n===============================================\n");
getwchar();
getchar();
}
void disp_specAvgScore(int scores[rSize][cSize], int x)
{
int i;
float avg = 0;
printf("Student Average Score");
printf("\n===============================================\n");
printf("Student\t\tAverage Score");
printf("\n===============================================");
for(i=0; i<cSize; i++)
{
avg += scores[x-1][i];
}
printf("\nNo. %d\t\t%.2f", x, avg/4);
printf("\n===============================================\n");
getchar();
getchar();
}
void disp_allScore(int scores[rSize][cSize])
{
int i, j;
printf("Student Quiz Record");
printf("\n===============================================\n");
printf("Student\t\tQuiz 1\tQuiz 2\tQuiz 3\tQuiz 4");
printf("\n===============================================");
for(i=0; i<rSize; i++)
{
printf("\nNo. %d\t", i+1);
for(j=0; j<cSize; j++)
{
printf("\t%d", scores[i][j]);
}
}
printf("\n===============================================\n");
getchar();
getchar();
}
void disp_specScore(int scores[rSize][cSize], int x)
{
int i;
printf("Student Quiz Record");
printf("\n===============================================\n");
printf("Student\t\tQuiz 1\tQuiz 2\tQuiz 3\tQuiz 4\n");
printf("===============================================\n");
printf("No. %d\t", x);
for(i=0; i<cSize; i++)
{
printf("\t%d", scores[x-1][i]);
}
printf("\n===============================================\n");
getchar();
getchar();
}
int pick_student()
{
int x;
do
{
printf("Choose which student's score to display.\n");
printf("=========================================\n");
printf("[1] Student 1\n");
printf("[2] Student 2\n");
printf("[3] Student 3\n");
printf("[0] Exit\n");
printf("=========================================\n");
scanf("%d", &x);
}while(x<0 || x>3);
return x;
}