CPPS Lab 17 SOLUTIONS

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CPPS Lab 17

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;
}
}

for (j=0;j<MAX;j++) printf("%5c", grades[j]);


putch('\n');
}

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;
}

void dispAboveAverage(float avarage)


{
int dAverage=0;
int i;
for(i=0;i< MAX; i++)
{
if(marks[i] > avarage) dAverage++;
}
printf("Number of students scored above average marks in TE01 %d\n",
dAverage);
}

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};

You might also like