CPPS Lab 17 SOLUTIONS
CPPS Lab 17 SOLUTIONS
CPPS Lab 17 SOLUTIONS
MENU.c
#include <stdio.h>
#include <conio.h>
#define MAX 20
extern int marks[];
void showMenu(void){
puts("A: Enter marks of the students:\n");
puts("B: Display marks of the students:\n");
puts("C: Display grades of the students:\n");
puts("D: Display average mark of the class.\n");
puts("E: Display number of students scored above the average mark of
class.\n");
puts("Q: Exit students’ marks records.\n");
void enterMarks(void)
{
int j;
for (j=0;j<MAX;j++)
{
printf("Enter marks for student no. %d : ", j+1);
scanf("%d", &marks[j]);
fflush(stdin);
}
}
void dispMarks(void)
{
int j;
putch('\n');
for (j=0;j<MAX;j++) printf("%5d",marks[j]);
putch('\n');
}
void dispGrades(void)
{
int j;
char grades[MAX];
for (j=0;j<MAX;j++)
{
switch(marks[j]/10)
{
case 0: case 1: case 2: case 3: case 4: grades[j]='F';
break;
case 5: grades[j]='D'; break;
case 6: grades[j] = 'C'; break;
case 7: grades[j]='B'; break;
case 8: case 9: case 10: grades[j]='A'; break;
}
}
float getAverage(void)
{
int j,total;
float average;
total=0;
for (j=0;j<MAX; j++) total=total+marks[j];
average=total/20.0;
return average;
}
MAIN.c
#include <stdio.h>
void showMenu(void);
void enterMarks(void);
void dispMarks(void);
void dispGrades(void);
float getAverage(void);
void dispAboveAverage(float);
void main(void)
{
char userinput;
float averageMark;
do{
showMenu();
userinput = getchar();
fflush(stdin);
switch(userinput){
case 'A':
case 'a':
enterMarks();
break;
case 'B':
case 'b':
dispMarks();
break;
case 'C':
case 'c':
dispGrades();
break;
case 'D':
case 'd':
averageMark = getAverage();
printf("Class average mark = %.1f\n", averageMark);
break;
case 'E':
case 'e':
averageMark = getAverage();
dispAboveAverage(averageMark);
break;
case 'Q':
case 'q':
userinput = 'Q';
break;
default:
printf("Incorrect input try again\n");
break;
}
}while(userinput!='Q');
DATA.c
int marks[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};