0% found this document useful (0 votes)
78 views3 pages

CPPS Lab 17 SOLUTIONS

This document contains code for a student marks management program. It includes functions to display a menu, enter marks, display marks, calculate grades, calculate the class average mark, and display the number of students above the average. The main function calls the showMenu function in a loop, gets user input, and calls the appropriate other functions based on the input, exiting when Q is selected. Student marks are stored in a global array.

Uploaded by

Joyce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

CPPS Lab 17 SOLUTIONS

This document contains code for a student marks management program. It includes functions to display a menu, enter marks, display marks, calculate grades, calculate the class average mark, and display the number of students above the average. The main function calls the showMenu function in a loop, gets user input, and calls the appropriate other functions based on the input, exiting when Q is selected. Student marks are stored in a global array.

Uploaded by

Joyce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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