C language USES structural array to implement student grade management system

  • 2020-06-01 10:38:33
  • OfStack

Requirements:

There are no more than 30 students in a class (the specific number is entered by the keyboard) to take the final exam, and no more than 6 students (the specific number is entered by the keyboard). Define the structure type to describe the student information. Each student information includes: student number, name, grades for multiple courses, total grades, and average grades. Using struct array as function parameter, the following menu-driven student grade management system is programmed.
(1) input each student's student number, name and examination result of each subject.
(2) calculate the total score and average score of each course.
(3) calculate the total score and average score of each student.
(4) according to the total score of each student from high to low ranking table.
(5) according to the student number from small to large discharge results table.
(6) list the results in alphabetical order of names.
(7) search student rankings and exam scores by student number.
(8) check student rankings and examination results by name.
(9) according to the five categories of "excellent" (90~100), "good" (80~90), "medium" (70~80), "pass" (60~70) and "fail" (0~59), the number and percentage of students in each category were calculated for each course.
(10) output each student's student number, name, examination results of each subject, total score and average score of each course.

Code:


#include<stdio.h>
#include<Windows.h>
#include<conio.h>

#define SN 30 // The number of students 
#define CN 6 // Number of subjects 
#define NL 20 // Name byte length 

typedef struct student{
 long int num;
 char name[NL];
 float score[CN];
 float sum;
 float aver;
}STU;

STU s[SN];
int itemSelected=-1;
int n=0;// Number of students 
int m=0;// Number of course 

int Menu();// The menu 
void chose(int itemSelected);// choose 
void inputScore();// Input the score 
void AverofC();// Calculate the average for each course 
void AverofS();// Each student's total score was divided evenly 
void sortByNum();// Total score ranking 
void sortByGrade();
void sortByName();
void findByNum();
void findByName();
void statisticsAnalysis();
void printScore();

void main(){
 printf(" Please enter the total number of students (n<%d):\n",SN);
 scanf("%d",&n);
 printf(" Please enter the total number of courses (m<%d):\n",CN);
 scanf("%d",&m);
 while(1){
 itemSelected=Menu();
 chose(itemSelected);
 itemSelected=-1;
 }
}

int Menu(){
 int itemSelected;
 system("cls");
 printf("\n ============== Student grade management system ===============\n");
 printf("\t 1. Enter your student number, name and grade \n");
 printf("\t 2. Calculate the total score and average score of each course \n");
 printf("\t 3. Calculate the total score and score for each student \n");
 printf("\t 4. According to the total score of each student ranking table \n");
 printf("\t 5. According to the student number from small to big discharge result table \n");
 printf("\t 6. List the students in dictionary order \n");
 printf("\t 7. Search student ranking and examination results by student number \n");
 printf("\t 8. Check student rankings and grades by name \n");
 printf("\t 9. Results analysis \n");
 printf("\t 10. Output information \n");
 printf("\t 0. exit \n");
 printf("===============================================\n");
 printf(" Please select options :");
 scanf("%d",&itemSelected);
 return itemSelected;
}

void chose(int itemSelected){
 switch(itemSelected){
 case 1: inputScore(); break;
 case 2: AverofC();break;
 case 3: AverofS();break;
 case 4: sortByGrade();break;
 case 5: sortByNum();break;
 case 6: sortByName();break;
 case 7: findByNum();break;
 case 8: findByName();break;
 case 9: statisticsAnalysis();break;
 case 10: printScore();break;
 case 0: exit(0);
 printf(" About to exit the program ");break;
 default: printf(" Input error !");break;
 }
}

void inputScore(){
 printf("\n===============================================\n");
 printf(" Please enter student number, name and subject information ( The input 0 Stop information entry )\n");
 for(int i=0;i<n;i++){
 printf(" Student id (8 position )");
 scanf("%ld",&s[i].num);
 if(s[i].num==0) break;
 getchar();// Absorb excess newline characters 
 printf(" The name ");
 gets(s[i].name);
 printf(" Please enter your grades for each subject ");
 s[i].sum=0;
 for(int j =0;j<m;j++){
  scanf("%f",&s[i].score[j]);
  s[i].sum +=s[i].score[j];
 }
 }
}

void AverofC(){
 float sum[CN]={0};
 float average[CN]={0};
 for(int i=0;i<m;i++){
 for(int j=0;j<n;j++){
 sum[i]+=s[j].score[i];
 }
 average[i]=sum[i]/n;
 printf(" The first %d The total score of the course is: %.2f , average score %.2f\n",i+1,sum[i],average[i]);
 } 
 getch();
}

void AverofS(){
 float sum[SN]={0};
 float average[SN]={0};
 for (int i=0;i<n;i++){
 for(int j=0;j<m;j++){
  sum[i]+=s[i].score[j];
 }
 average[i]=sum[i]/m;
 printf(" The first %d The total score of the students is: %.2f , average score %.2f\n",i+1,sum[i],average[i]);
 }
 getch();
}

void sortByNum(){
 // Sort student Numbers from small to large 
 STU temp1={0};
 for(int i=0;i<n-1;i++){
 if(s[i].num>s[i+1].num){
  temp1=s[i];
  s[i]=s[i+1];
  s[i+1]=temp1;
 }
 }
 printf("\n============== Student Numbers from small to small ===============\n");
 for(int j=0;j<n;j++){
 printf(" The student's student number is :%d\n",s[j].num);
 printf(" The student's name is :");
 for(int k=0;k<NL;k++){
  printf("%c",s[j].name[k]);
 }
 printf("\n The student's grades in all subjects are \n");
 for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[j].score[c]);
 }
 printf("\n");
 }
 getch();
}

void sortByGrade(){
 // Rank from highest to lowest by total score 
 STU temp1={0};
 for(int i=0;i<n-1;i++){
  if(s[i].sum<s[i+1].sum){
  temp1=s[i];
  s[i]=s[i+1];
  s[i+1]=temp1;
 }
 }
 printf("\n============ Rank from highest to lowest overall score ===========\n");
 for(int j=0;j<n;j++){
 printf(" The student's student number is :%d\n",s[j].num);
 printf(" The student's name is :");
 for(int k=0;k<NL;k++){
  printf("%c",s[j].name[k]);
 }
 printf("\n The student's grades in all subjects are \n");
 for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[j].score[c]);
 }
 printf(" The student's total score is :%.2f",s[j].sum);
 printf("\n");
 }
 getch();
}

void sortByName(){
 // Sort by alphabetical lexicographical order 
 STU temp1={0}; 
 for(int i=0;i<n-1;i++){
  if(((int)(s[i].name[0])>(int)(s[i+1].name[0]))){
  // Change the initials into letters ASCII Code to compare size sort 
  temp1=s[i];
  s[i]=s[i+1];
  s[i+1]=temp1;
 }
 }
 printf("\n============== Student Numbers from small to small ===============\n");
 for(int j=0;j<n;j++){
 printf(" The student's student number is :%d\n",s[j].num);
 printf(" The student's name is :");
 for(int k=0;k<NL;k++){
  printf("%c",s[j].name[k]);
 }
 printf("\n The student's grades in all subjects are \n");
 for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[j].score[c]);
 }
 printf(" The student's total score is :%.2f",s[j].sum);
 printf("\n");
 }
 getch();
}

void findByNum() {
 int find=-1;
 // Record the student number to look for , And as an identifier for the success or failure of the search 
 printf(" Please enter the student number you are looking for: ");
 scanf("%d",&find);
 for(int i=0;i<n;i++){
 if(s[i].num==find){
  printf("\n Find success \n");
  printf(" The student's student number is %d\n",s[i].num);
  printf(" The student's name is :");
  for(int k=0;k<NL;k++){
  printf("%c",s[i].name[k]);
  }
  printf("\n The student's grades in all subjects are \n");
  for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[i].score[c]);
  }
  printf(" The student's total score is :%.2f",s[i].sum);
  printf("\n");
  find=-2;
 }
 }
 if(find!=-2){
 printf(" No such person \n");
 printf(" Press any key to continue ");
 }
 getch();
}

void findByName(){
 int is_find=0;
 char find[SN];
 printf(" Please enter the name to look for: ");
 getchar();
 gets(find);
 for(int i=0;i<n;i++){
 if(strcmp(s[i].name,find)==0){
  printf("\n Find success \n");
  printf(" The student's student number is %d\n",s[i].num);
  printf(" The student's name is :");
  for(int k=0;k<NL;k++){
  printf("%c",s[i].name[k]);
  }
  printf("\n The student's grades in all subjects are \n");
  for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[i].score[c]);
  }
  printf(" The student's total score is :%.2f",s[i].sum);
  printf("\n");
  is_find=1;
 }
 }
 if(is_find!=1){
 printf(" No such person \n");
 printf(" Press any key to continue ");
 }
 getch();
}

void statisticsAnalysis(){
 printf(" Output the percentage of outstanding, good, medium, passing and failing students in each course \n");
 int a1[CN]={0},a2[CN]={0},a3[CN]={0},a4[CN]={0},a5[CN]={0};
 for(int i=0;i<n;i++){
 for(int j=0;j<m;j++){
  if(s[i].score[j]>=90 && s[i].score[j]<=100){
  a1[j]++;
  }else if (s[i].score[j]>=80 && s[i].score[j]<90){
  a2[j]++;
  }else if (s[i].score[j]>=70 && s[i].score[j]<80){
  a3[j]++;
  }else if (s[i].score[j]>=60 && s[i].score[j]<70){
  a4[j]++;
  }else if (s[i].score[j]<60){
  a5[j]++;
  }
 }
 }
 printf("\n==================== Course overview ==================\n");
 for(int k=0;k<m;k++){
  printf(" The first %d The number of outstanding students in the course %.2f%% . ",k+1,(a1[k]/(n*1.0))*100);
  printf(" Good representation %.2f%% . ",(a2[k]/(n*1.0))*100);
  printf(" Medium population %.2f%% . ",(a3[k]/(n*1.0))*100);
  printf(" Number of passing students %.2f%% . ",(a4[k]/(n*1.0))*100);
  printf(" Number of flunks %.2f%% . ",(a5[k]/(n*1.0))*100);

  printf("\n");
 }
 getch();
}

void printScore(){
 printf("============== The following is the student information ==============");
 for(int j=0;j<n;j++){
 printf(" The student's student number is :%d\n",s[j].num);
 printf(" The student's name is :");
 for(int k=0;k<NL;k++){
  printf("%c",s[j].name[k]);
 }
 printf("\n The student's grades in all subjects are \n");
 for(int c=0;c<m;c++){
  printf(" The first %d Door scores for %.2f\n",c+1,s[j].score[c]);
 }
 printf(" The student's total score is :%.2f",s[j].sum);
 printf("\n");
 }
 getch();
}

For more information, please refer to the topic "management system development".


Related articles: