C++

Design of grade management system for C language students


The example of this paper is to share the specific code of C language student performance management system for your reference. The specific content is as follows

Ps: I added a linked list to sort and wrote it in bubbles.

/*
 Title : Student's score management system
 Author: nyist_xiaod
 Date : 2012.5.8
*/

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

#define Print_Head_Num puts(" The class    The name     Chinese language and literature   mathematics   English   Total grade ")
#define Print_Head_Cla puts(" Student id    The name     Chinese language and literature   mathematics   English   Total grade ")
#define Print_Head_All puts(" The class    Student id    The name     Chinese language and literature   mathematics   English   Total grade ")

typedef struct Node Node;

struct Score
{
 int chinese,math,english,sum;
};

struct Node
{
 char name[20],classs[20],number[20];
 struct Score score;
 struct Node* next;
}*head,*u,*p,*q;

int n,C,M,E,Cj,Cy,Mj,My,Ej,Ey;
char num[20];

void Welcome()
{
 printf("\t\t  %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
 printf("\t\t  %c  Welcome to the student grade management system  %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   1. Read the file    %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   2. Save the file    %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   3. Add student grades   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   4. Revise students' grades   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   5. Delete student grades   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   6. Enquiry of my grades   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   7. Check the grades of the class   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   8. Check school grades   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c   9. Exit management system   %c\n",4,4);
 printf("\t\t  %c        %c\n",4,4);
 printf("\t\t  %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n\n",4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4);
 printf("\t\t   Please enter the instruction :(1-9) ");
}
Node* new_node(Node* uu)
{
 uu = (Node*)malloc(sizeof(Node));
 uu->next = NULL;
 return uu;
}
void Add()
{
 u = new_node(u);
 printf("\n Please enter the information of the student you want to join :\n");
 printf("\n The name : ");
 scanf("%s",u->name);
 printf("\n The class : ");
 scanf("%s",u->classs);
 printf("\n Student id : ");
 scanf("%s",u->number);
 printf("\n Chinese, math and English : ");
 scanf("%d%d%d",&u->score.chinese,&u->score.math,&u->score.english);
 u->score.sum = u->score.chinese + u->score.math + u->score.english;
 u->next = head->next;
 head->next = u;
 printf("\n---> Add a success !\n");
}
void Mod()
{
 n = 0;
 printf("\n Please enter the student number you want to modify : ");
 scanf("%s",num);
 for(u = head; u != NULL;u = u->next)
 {
  if(strcmp(u->number,num) == 0)
  {
   n = 1;
   printf("\n Please enter your new Chinese, maths and English scores : ");
   scanf("%d%d%d",&u->score.chinese,&u->score.math,&u->score.english);
   u->score.sum = u->score.chinese + u->score.math + u->score.english;
   printf("\n---> Modify the success !\n");
   break;
  }
 }
 if(!n)
  printf("\n---> There is no information about the student !\n");
}
void Del()
{
 n = 0;
 printf("\n Please enter the student number you want to delete : ");
 scanf("%s",num);
 for(u = head; u != NULL;u = u->next)
 {
  if(strcmp(u->number,num) == 0)
  {
   n = 1;
   p->next = u->next;
   free(u);
   printf("\n---> Delete the success !\n");
   break;
  }
  p = u;
 }
 if(!n)
  printf("\n---> There is no information about the student !\n");
}
void Sort()
{
 int i,j;
 n = 0;
 for(u = head->next; u != NULL;u = u->next)
  n++;
 for(i=1;i<=n;i++)
 {
  u = head;
  for(j=0;j<n-i;j++)
  {
   p = u->next;
   q = p->next;
   if(strcmp(p->classs,q->classs) > 0 || strcmp(p->classs,q->classs) == 0 && p->score.sum < q->score.sum)
   {
    u->next = q;
    p->next = q->next;
    q->next = p;
   }
   u = u->next;
  }
 }
}
void Que_One()
{
 n = 0;
 printf("\n Please enter the student number of the student you want to query : ");
 scanf("%s",num);
 for(u = head->next; u != NULL;u = u->next)
 {
  if(strcmp(u->number,num) == 0)
  {
   n = 1;
   printf("\n");
   Print_Head_Num;
   printf("%-11s%-15s",u->classs,u->name);
   printf("%-6d%-6d%-6d%-6d\n",u->score.chinese,u->score.math,u->score.english,u->score.sum);
   break;
  }
 }
 if(!n)
  printf("\n---> There is no information about the student !\n");
}
void Analyze_Sco(Node *uu)
{
 C += uu->score.chinese;
 M += uu->score.math;
 E += uu->score.english;
 if(uu->score.chinese >= 60)
  Cj++;
 if(uu->score.chinese >= 90)
  Cy++;
 if(uu->score.math >= 60)
  Mj++;
 if(uu->score.math >= 90)
  My++;
 if(uu->score.english >= 60)
  Ej++;
 if(uu->score.english >= 90)
  Ey++;
}
void Print_Sco()
{
 printf(" Language average : %-6.2f,  pass : %%%-6.2f ,  proficiency : %%%-6.2f.\n\n",(float)C/n,(float)100*Cj/n,(float)100*Cy/n);
 printf(" Math gpa : %-6.2f,  pass : %%%-6.2f ,  proficiency : %%%-6.2f.\n\n",(float)M/n,(float)100*Mj/n,(float)100*My/n);
 printf(" Average score in English : %-6.2f,  pass : %%%-6.2f ,  proficiency : %%%-6.2f.\n\n",(float)E/n,(float)100*Ej/n,(float)100*Ey/n);
}
void Que_Cla()
{
 Sort();
 n = C = M = E = Cj = Cy = Mj = My = Ej = Ey = 0;
 printf("\n Please enter the class you want to query : ");
 scanf("%s",num);
 printf("\n");
 for(u = head->next; u != NULL;u = u->next)
 {
  if(strcmp(u->classs,num))
   continue;
  if(!n)
   Print_Head_Cla;
  n++;
  printf("%-11s%-15s",u->number,u->name);
  printf("%-6d%-6d%-6d%-d\n",u->score.chinese,u->score.math,u->score.english,u->score.sum);
  Analyze_Sco(u);
 }
 if(!n)
 {
  printf(" There is no student information for this class !\n");
  return ;
 }
 printf("\n There are altogether students in this class  %d  people .\n\n",n);
 Print_Sco();

}
void Que_All()
{
 Sort();
 n = C = M = E = Cj = Cy = Mj = My = Ej = Ey = 0;
 printf("\n");
 if(head->next == NULL)
 {
  printf("---> No student information !\n");
  return ;
 }
 Print_Head_All;
 for(u = head->next; u != NULL;u = u->next)
 {
  n++;
  printf("%-12s%-12s%-15s",u->classs,u->number,u->name);
  printf("%-6d%-6d%-6d%-d\n",u->score.chinese,u->score.math,u->score.english,u->score.sum);
  Analyze_Sco(u);
 }
 printf("\n All students in the school  %d  people .\n\n",n);
 Print_Sco();
}
void Save()
{
 char c;
 printf("\n Confirm save? (Y/N): ");
 scanf("%*c%c",&c);
 if(c == 'N')
  return ;
 FILE *fp;
 if((fp=fopen("C:\\data.txt","w"))==NULL)
 {
  printf("\n---> Unable to open file \n");
  return ;
 }
 fputs(" The class    Student id    The name     Chinese language and literature   mathematics   English   Total grade ",fp);
 if(head->next != NULL)
  fputs("\n",fp);
 for(u = head->next; u != NULL;u = u->next)
 {
  fprintf(fp,"%-11s%-11s%-15s",u->classs,u->number,u->name);
  fprintf(fp,"%-6d%-6d%-6d%-d",u->score.chinese,u->score.math,u->score.english,u->score.sum);
  if(u->next != NULL)
   fprintf(fp,"\n");
 }
 fclose(fp);
 printf("\n---> Achievements deposited successfully C:\\\\data.txt In the \n");
}
void Open()
{
 printf("\n Please put the data in the directory C:\\\\data.txt In the , Press any key to confirm .\n");
 getch();
 FILE *fp;
 if((fp=fopen("C:\\data.txt","r"))==NULL)
 {
  printf("\n---> No file found !\n");
  return ;
 }
 char tmp[100];
 fgets(tmp,66,fp);
 while(!feof(fp))
 {
  u = new_node(u);
  fscanf(fp,"%s%s%s",u->classs,u->number,u->name);
  fscanf(fp,"%d%d%d%d",&u->score.chinese,&u->score.math,&u->score.english,&u->score.sum);
  u->next = head->next;
  head->next = u;
 }
 printf("\n---> Grades read in successfully !\n");
 fclose(fp);
}
void Exi()
{
 char c;
 printf("\n Are you sure to quit? (Y/N): ");
 scanf("%*c%c",&c);
 if(c == 'N')
  return ;
 system("cls");
 printf("\n\n");
 printf("\t\t\t  %c %c %c %c %c %c %c %c %c\n",4,4,4,4,4,4,4,4,4);
 printf("\t\t\t  %c Made by Xiaod %c\n",4,4);
 printf("\t\t\t  %c %c %c %c %c %c %c %c %c\n",4,4,4,4,4,4,4,4,4);
 printf("\t\t\t       Thank you!\n\n\n");
 exit(0);
}
int main()
{
 int orz;
 system("color 0B");
 head = new_node(head);
 while(1)
 {
  Welcome();
  scanf("%d",&orz);
  system("cls");
  switch(orz)
  {
   case 1:Open();break;
   case 2:Save();break;
   case 3:Add();break;
   case 4:Mod();break;
   case 5:Del();break;
   case 6:Que_One();break;
   case 7:Que_Cla();break;
   case 8:Que_All();break;
   case 9:Exi();break;
   default :printf("\n---> Invalid instruction !\n");
  }
  printf("\n");
  system("pause");
  system("cls");
 }
 return 0;
}

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