A simple student grades database using C++
#include <iostream>
#include <stdlib.h>
#include <ctype.h>
#define CLASSES 3
#define GRADES 30
using namespace std;
int grade [CLASSES][GRADES];
void enter_grades();
int get_grade(int n);
void disp_grades(int g[][GRADES]);
int main () {
char ch, str[80];
for(;;){
do{
cout << "(E)nter grades" << endl;
cout << "(R)eport grades" << endl;
cout << "(Q)uit"<<endl;
gets(str);
ch = toupper(*str);
} while(ch!='E' && ch!='R' && ch!='Q');
switch(ch){
case 'E' : enter_grades();
break;
case 'R' : disp_grades(grade);
break;
case 'Q' : exit(0);
}
}
return 0;
}
void enter_grades(){
int t,i;
for(t=0;t<CLASSES;t++){
cout << "Class #" << t+1 <<" :" <<endl;
for(i=0;i<GRADES;++i){
grade[t][i] = get_grade(i);
}
}
}
int get_grade(int n){
char s[80];
cout << "Enter grade for student # " << n+1 << " :" << endl;
gets(s);
return(atoi(s));
}
void disp_grades(int g[][GRADES]){
int t,i;
for(t=0;t<CLASSES;++t){
cout << "Class # " << t+1 << " :" << endl;
for(i=0;i<GRADES;++i){
cout << "Student # "<<i+1<<" is "<< g[t][i] << endl;
}
}
}
Comments
Post a Comment