First of all, we need to know what functions the student management system needs before we build a management system , as : Simple increase , Delete , change , check , Namely : Enter grades , Query results , Delete grades , Modify grades , Insert grades , These are the basic ones , Of course, we can also add sorting , Count the number of students , These functions .

When we know what functions we need, we can write the interface of the system .

The renderings are as follows :

 
printf("\t\t\t---------------STUDENT---------------\t\t\t\n");
printf("\t\t\t0. sign out \t\t\t\n"); printf("\t\t\t1. Enter grades \t\t\t\n");
printf("\t\t\t2. Query results \t\t\t\n"); printf("\t\t\t3. Delete grades \t\t\t\n");
printf("\t\t\t4. Modify grades \t\t\t\n"); printf("\t\t\t5. Insert grades \t\t\t\n");
printf("\t\t\t6. sort \t\t\t\n"); printf("\t\t\t7. Count the number of students \t\t\t\n");
printf("\t\t\t-------------------------------------\t\t\t\n");
printf("\t\t\t choice (0---7)\t\t\t");
Then we can join switch Function for function selection

  Define integer variables choice 
int choice ; scanf("%d",&choice ); switch(choice ) { case 0:exit(0); break;
case 1: in();save();system("pause");system("cls");break;// Input case 2:
show();system("pause");system("cls");break;// query case 3:
del();save();system("pause");system("cls");break;// delete case 4:
modify();system("pause");system("cls");break;// modify case 5:
insert();save();system("pause");system("cls");break;// insert case 6:
order();system("pause");system("cls");break;// sort case 7:
total();system("pause");system("cls");break;// Statistics
default:printf("\n Input error , Please enter 0---7\n\n");system("pause");system("cls");break; }
Define a Menu Function combines the above two , Let's add one while Cycle makes this menu cycle all the time , Instead of using it once and then losing it .
void Menu()// menu { while(1) {
printf("\t\t\t---------------STUDENT---------------\t\t\t\n");
printf("\t\t\t0. sign out \t\t\t\n"); printf("\t\t\t1. Enter grades \t\t\t\n");
printf("\t\t\t2. Query results \t\t\t\n"); printf("\t\t\t3. Delete grades \t\t\t\n");
printf("\t\t\t4. Modify grades \t\t\t\n"); printf("\t\t\t5. Insert grades \t\t\t\n");
printf("\t\t\t6. sort \t\t\t\n"); printf("\t\t\t7. Count the number of students \t\t\t\n");
printf("\t\t\t-------------------------------------\t\t\t\n");
printf("\t\t\t choice (0---7)\t\t\t"); int chioce; scanf("%d",&chioce);
switch(chioce) { case 0:exit(0); break; case 1:
in();save();system("pause");system("cls");break;// Input case 2:
show();system("pause");system("cls");break;// query case 3:
del();save();system("pause");system("cls");break;// delete case 4:
modify();system("pause");system("cls");break;// modify case 5:
insert();save();system("pause");system("cls");break;// insert case 6:
order();system("pause");system("cls");break;// sort case 7:
total();system("pause");system("cls");break;// Statistics
default:printf("\n Input error , Please enter 0---7\n\n");system("pause");system("cls");break; } } }
After writing the menu, we will “ student ” Analyze this data

What should students' information include in this system , for instance : Student number , full name , Elective grades , Results of experimental courses , Required course grades , Total score , Average score . Then write a structure based on these ( I wrote an array type structure )
struct student { char num[20];// Student number char name[20];// full name float elec;// Elective courses float
expe;// Experimental class float requ;// required course float sum;// Total score ' float ave;// Average score }student[N];
Then we began to write functions to realize the functions of the system

The first is the entry of grades
void in()// Input information { void save() ; int i,n; printf(" Enter the number of students admitted \n"); scanf("%d",
&n); for (i=1 ; i<=n; i++) { printf(" Please enter No %d Student ID :\n",i);
scanf("%s",student[i].num); printf(" Please enter No %d Names of students :\n", i );
scanf("%s",student[i].name); printf(" Please enter No %d Student elective grades :\n", i );
scanf("%f",&student[i].elec); printf(" Please enter No %d Experimental results of students :\n", i ); scanf("%f",
&student[i].expe); printf(" Please enter No %d Required course scores of students :\n", i ); scanf("%f",
&student[i].requ);
student[i].sum=student[i].elec+student[i].expe+student[i].requ;
student[i].ave=student[i].sum /3; count++; } printf(" Entered successfully \n"); }
The second is the query of grades
void show() // query { int i; char xh[20]; printf(" Please enter the student ID to be queried :\n"); getchar();
gets(xh); for (i=0;i<N;i++) {
if(strcmp(student[i].num,xh)==0)// Compare two strings. If the two are the same, proceed if The following statement, otherwise continue the loop
printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f Results of experimental courses :%-5.1f Required course grades :%-5.1f Total score :%-5.1f
average :%-5.1f\n",
student[i].num,student[i].name,student[i].elec,student[i].expe,student[i].requ,student[i].sum,student[i].ave);
} }
The third is the deletion of grades
void del()// delete { void save() ; int j,a=0,k=count; char xh[25];
printf(" The student ID to be deleted is :\n"); scanf("%s",xh); flush(stdin);// buffer for
(j=0;j<count;j++) { if (strcmp(student[j].num,xh)==0) { for (j=a;j<count;j++)
student[j]=student[j+1]; count--; if (count<k) printf(" Successfully deleted \n"); } a++; } if
(j==count-1) printf(" There is no information about the student you want to delete \n"); }
Item 4 , Revision of grades

step 1. Find the student to modify first

        2. Select modified items

        3. Change the total score and average score

        4. Display the modified student data
void modify()// modify { void save() ; int i,j,h; float score; char xh[20]; printf
("01. Enter the student number of the modified student :\n") ; scanf("%s",xh); for(i=1;i<N;i++) if
(strcmp(student[i].num,xh)==0) j=i; printf(" Please select the modified content \n");
printf("1. Modify the student's elective grades \n"); printf("2. Modify the student's experimental class score \n");
printf("3. Revise the student's required course score \n"); scanf("%d",&h); switch (h) { case
1:printf(" Please enter the student's elective grade \n");scanf("%f",&score);student[j].elec=score; break;
case 2:printf(" Please enter the student's lab grade \n");scanf("%f",&score);student[j].expe=score;break;
case 3:printf(" Please enter the student's required course score \n");scanf("%f",&score);student[j].requ=score;break;
default :printf("\n Input error , Please enter 1---3\n\n"); break; } student[j].sum =
student[j].elec+student[j].expe + student[j].requ; printf(" Modified as :\n");
printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f Results of experimental courses :%-5.1f Required course grades :%-5.1f Total score :%-5.1f
average :%-5.1f\n",
student[j].num,student[j].name,student[j].elec,student[j].expe,student[j].requ,student[j].sum,student[j].ave);
printf("\n"); printf(" Successfully modified \n") ; }
 

Item 5 , Insertion of grades
void insert ()// insert {void save(); int m, flag, i = count, j,k;
printf(" Please enter the number of students to be added :\n"); scanf("%d", &m); if (m > 0) { k=count+1;
for(i=k;i<=count+m;i++) { flag = 1; while (flag!= 0) { flag = 0;
printf(" Please enter No %d Student number of students :\n", i); getchar(); gets(student[i].num); for (j = 0; j <
i; j++) { if (strcmp(student[i].num, student[j].num) == 0) {
printf(" The student number already exists , Please re-enter !\n"); flag = 1; break; } } } printf(" Please enter No %d Names of students :\n", i );
gets(student[i].name); printf(" Please enter No %d Student elective grades :\n", i );
scanf("%f",&student[i].elec); printf(" Please enter No %d Experimental results of students :\n", i ); scanf("%f",
&student[i].expe); printf(" Please enter No %d Required course scores of students :\n", i ); scanf("%f",
&student[i].requ);
student[i].sum=student[i].elec+student[i].expe+student[i].requ;
student[i].ave=student[i].sum /3; } count+= m; printf(" Add complete !\n");
system("pause"); } }
Item 6 , sort
void order()// sort { int i,j,m; for(j=1;j<=count-1;j++) { m=j;
for(i=j+1;i<=count;i++) { if(student[i].sum < student[m].sum) {
student[0]=student[i]; student[i]=student[m]; student[m]=student[0]; } } }
for(j=1;j<=count;j++) { printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f Results of experimental courses :%-5.1f
Required course grades :%-5.1f Total score :%-5.1f average :%-5.1f\n",
student[j].num,student[j].name,student[j].elec,student[j].expe,student[j].requ,student[j].sum,student[j].ave);
} }
Item 7 , Count the number of students
void total ()// Statistics { printf(" Number of students %d\n",count); }
Complete code
#include<stdio.h> #include<string.h> #include<stdlib.h> #define N 100 struct
student { char num[20];// Student number char name[20];// full name float elec;// Elective courses float
expe;// Experimental class float requ;// required course float sum;// Total score ' float ave;// Average score }student[N];
void Menu(); // menu void in();// Input void show() ;// lookup void order();// sort void
del(); // delete void modify();// modify void total ();// Statistics void insert ();// insert int
count=0;// Number of people void save();// preservation int main() { Menu(); return 0; } void Menu()// menu
{ while(1) { printf("\t\t\t---------------STUDENT---------------\t\t\t\n");
printf("\t\t\t0. sign out \t\t\t\n"); printf("\t\t\t1. Enter grades \t\t\t\n");
printf("\t\t\t2. Query results \t\t\t\n"); printf("\t\t\t3. Delete grades \t\t\t\n");
printf("\t\t\t4. Modify grades \t\t\t\n"); printf("\t\t\t5. Insert grades \t\t\t\n");
printf("\t\t\t6. sort \t\t\t\n"); printf("\t\t\t7. Count the number of students \t\t\t\n");
printf("\t\t\t-------------------------------------\t\t\t\n");
printf("\t\t\t choice (0---7)\t\t\t"); int chioce; scanf("%d",&chioce);
switch(chioce) { case 0:exit(0); break; case 1:
in();save();system("pause");system("cls");break;// Input case 2:
show();system("pause");system("cls");break;// query case 3:
del();save();system("pause");system("cls");break;// delete case 4:
modify();system("pause");system("cls");break;// modify case 5:
insert();save();system("pause");system("cls");break;// insert case 6:
order();system("pause");system("cls");break;// sort case 7:
total();system("pause");system("cls");break;// Statistics
default:printf("\n Input error , Please enter 0---7\n\n");system("pause");system("cls");break; } }
} void save() // preservation { FILE* fp; char filename[100]; int i;
printf(" Please enter the file name to save :\n"); scanf("%s", filename); if ((fp = fopen(filename, "w"))
== NULL) { printf(" fail to open file !\n"); exit(0); } for (i = 1; i<=count; i++) { if
(fwrite(&student[i], sizeof(struct student), 1, fp) != 1) printf(" Save failed !\n"); }
printf(" Saved successfully !\n"); fclose(fp); } void in()// Input information { void save() ; int i,n;
printf(" Enter the number of students admitted \n"); scanf("%d", &n); for (i=1 ; i<=n; i++) {
printf(" Please enter No %d Student ID :\n",i); scanf("%s",student[i].num);
printf(" Please enter No %d Names of students :\n", i ); scanf("%s",student[i].name);
printf(" Please enter No %d Student elective grades :\n", i ); scanf("%f",&student[i].elec);
printf(" Please enter No %d Experimental results of students :\n", i ); scanf("%f", &student[i].expe);
printf(" Please enter No %d Required course scores of students :\n", i ); scanf("%f", &student[i].requ);
student[i].sum=student[i].elec+student[i].expe+student[i].requ;
student[i].ave=student[i].sum /3; count++; } printf(" Entered successfully \n"); } void
modify()// modify { void save() ; int i,j,h; float score; char xh[20]; printf
("01. Enter the student number of the modified student :\n") ; scanf("%s",xh); for(i=1;i<N;i++) if
(strcmp(student[i].num,xh)==0) j=i; printf(" Please select the modified content \n");
printf("1. Modify the student's elective grades \n"); printf("2. Modify the student's experimental class score \n");
printf("3. Revise the student's required course score \n"); scanf("%d",&h); switch (h) { case
1:printf(" Please enter the student's elective grade \n");scanf("%f",&score);student[j].elec=score; break;
case 2:printf(" Please enter the student's lab grade \n");scanf("%f",&score);student[j].expe=score;break;
case 3:printf(" Please enter the student's required course score \n");scanf("%f",&score);student[j].requ=score;break;
default :printf("\n Input error , Please enter 1---3\n\n"); break; } student[j].sum =
student[j].elec+student[j].expe + student[j].requ; printf(" Modified as :\n");
printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f Results of experimental courses :%-5.1f Required course grades :%-5.1f Total score :%-5.1f
average :%-5.1f\n",
student[j].num,student[j].name,student[j].elec,student[j].expe,student[j].requ,student[j].sum,student[j].ave);
printf("\n"); printf(" Successfully modified \n") ; } void show() // query { int i; char xh[20];
printf(" Please enter the student ID to be queried :\n"); getchar(); gets(xh); for (i=0;i<N;i++) {
if(strcmp(student[i].num,xh)==0) printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f
Results of experimental courses :%-5.1f Required course grades :%-5.1f Total score :%-5.1f average :%-5.1f\n",
student[i].num,student[i].name,student[i].elec,student[i].expe,student[i].requ,student[i].sum,student[i].ave);
} } void order()// sort { int i,j,m; for(j=1;j<=count-1;j++) { m=j;
for(i=j+1;i<=count;i++) { if(student[i].sum < student[m].sum) {
student[0]=student[i]; student[i]=student[m]; student[m]=student[0]; } } }
for(j=1;j<=count;j++) { printf("\n Student number :%-5s full name :%-5s Elective grades :%-5.1f Results of experimental courses :%-5.1f
Required course grades :%-5.1f Total score :%-5.1f average :%-5.1f\n",
student[j].num,student[j].name,student[j].elec,student[j].expe,student[j].requ,student[j].sum,student[j].ave);
} } void del()// delete { void save() ; int j,a=0,k=count; char xh[25];
printf(" The student ID to be deleted is :\n"); scanf("%s",xh); flush(stdin); for (j=0;j<count;j++) {
if (strcmp(student[j].num,xh)==0) { for (j=a;j<count;j++)
student[j]=student[j+1]; count--; if (count<k) printf(" Successfully deleted \n"); } a++; } if
(j==count-1) printf(" There is no information about the student you want to delete \n"); } void insert ()// insert {void save(); int
m, flag, i = count, j,k; printf(" Please enter the number of students to be added :\n"); scanf("%d", &m); if (m > 0)
{ k=count+1; for(i=k;i<=count+m;i++) { flag = 1; while (flag!= 0) { flag = 0;
printf(" Please enter No %d Student number of students :\n", i); getchar(); gets(student[i].num); for (j = 0; j <
i; j++) { if (strcmp(student[i].num, student[j].num) == 0) {
printf(" The student number already exists , Please re-enter !\n"); flag = 1; break; } } } printf(" Please enter No %d Names of students :\n", i );
gets(student[i].name); printf(" Please enter No %d Student elective grades :\n", i );
scanf("%f",&student[i].elec); printf(" Please enter No %d Experimental results of students :\n", i ); scanf("%f",
&student[i].expe); printf(" Please enter No %d Required course scores of students :\n", i ); scanf("%f",
&student[i].requ);
student[i].sum=student[i].elec+student[i].expe+student[i].requ;
student[i].ave=student[i].sum /3; } count+= m; printf(" Add complete !\n");
system("pause"); } } void total ()// Statistics { printf(" Number of students %d\n",count); }
 

 

Technology
Daily Recommendation