Design and implementation of C language student information management system

  • 2020-06-01 10:35:39
  • OfStack

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


#include"stdio.h" // Standard I/o function file header description  
#include"math.h"  //  Mathematical function header  
#include"string.h" 
#include"stdlib.h" // Change the background and color of the console through the function in the header  
#include"windows.h" // The header file declares that the following is used to change the width and height of the console  
#define M 100  // Macro definition description  
struct student{ // The structure is defined and declared  
 char name[25]; // The name  
 char num[25]; // Student id  
 char credit[20]; // Id number  
 char native[35]; // Native place  
 char tel[25]; // Mobile phone no.  
 int special; // professional  
 int banji; // The class  
 int math,yy,wl,cyy,pe; // Math, English, physics, C Language, sports  
 double ave;}; // average  
//**************************************** Declaration of functions ******************************************** 
void input(struct student stu[M]); // Input function  
void output(struct student stu[M]); // Declarations of various user-defined functions  
void lookfor(struct student stu[M]); // Query function  
void modify(struct student stu[M]); // Modify the function  
void order(struct student stu[M]); // Sorting function  
void delete_student(struct student stu[M]); // Delete function  
void xuehao(struct student stu[M]); 
void xingming(struct student stu[M]); 
void fileread(struct student stu[M]); 
void filewrite(struct student stu[M]); 
void yanshi(char *p); // Delay function description  
//********************************************************************************************** 
int count=0; 
struct student t; 
int main() 
{ 
 int choice,sum; 
 struct student stu[M];  
 system("mode con:cols=400 lines=30000"); // Adjust the width and height of the console  
 system("color 0b"); // Adjust the console background and font color  
point1: 
 sum=0; 
 yanshi("\t\t\t\t\t\t\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3 Welcome to the student information management system \3\3\3\3\3\3\3\3\3\3\n"); 
 do { 
 printf("\t\t\t\t\t\t\t\t-------------------------------------------------\n"); 
 printf("\t\t\t\t\t\t\t\t+  Student information management system   +\n"); 
 printf("\t\t\t\t\t\t\t\t-------------------------------------------------\n"); 
 printf("\t\t\t\t\t\t\t\t\t\t ***************\n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 1 Add student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 2 , browse for student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 3 , search for student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 4 Modify student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 5 Delete student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 6 Arrange student information \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t 7 , read the file students \n");   // Read from file  
 printf("\t\t\t\t\t\t\t\t\t\t 8 Save to a file \n");   // Save to file  
 printf("\t\t\t\t\t\t\t\t\t\t 9 , exit the system \n"); 
 printf("\t\t\t\t\t\t\t\t\t\t ***************\n"); 
 printf(" Please enter your choice \n"); 
 scanf("%d",&choice); 
 fflush(stdin); // Clear input buffer  
 if (choice>9||choice<=0) 
 { 
 sum++; 
 if (sum>=5) 
 { 
 printf(" Too many typing errors , The program will restart \n"); 
 system("pause"); // The pause  
 system("cls"); // CLS statement  
 goto point1; 
 } 
 } 
 switch (choice) // Depending on your choice, call different functions to accomplish different tasks  
 { 
 case 1:input(stu);break;  
 case 2:output(stu);break; 
 case 3:lookfor(stu);break; 
 case 4:modify(stu);break; 
 case 5:delete_student(stu);break; 
 case 6:order(stu);break; 
 case 7:fileread(stu);break; 
 case 8:filewrite(stu);;break; 
 case 9:printf(" Thank you for using the student information management system , Please close the program !!!\n");system("pause");break; 
 default:printf(" Invalid selection !!! Please re-enter !!!\n");break; 
 } 
 }while (choice!=9); 
 printf("the program is over!!!\n"); 
 return 0; 
} 
void input(struct student stu[M]) // Custom input functions  
{ 
 int len,size; 
 system("cls"); 
 printf(" Please add the information to enter the student \n"); 
 do { 
 printf(" Please enter the 11 A student number made up of digits \n"); //do-while Loop application, prompt input number is 1 Determine the number of  
 scanf("%s",&stu[count].num); 
 len=strlen(stu[count].num); 
 }while(len!=11); 
 printf(" Please enter the student's name \n"); 
 scanf("%s",stu[count].name); 
 do { 
 printf(" Please enter the 18 Student id number composed of digits \n"); // Same as above  
 scanf("%s",&stu[count].credit); 
 size=strlen(stu[count].credit); 
 }while(size!=18);       
 printf(" Please enter the student's native place \n"); 
 scanf("%s",&stu[count].native); 
 printf(" Please enter the student's mobile phone number \n"); 
 scanf("%s",&stu[count].tel); 
 printf(" Please enter the required professional code: 1 Computer science  2 Communications engineering  3 , network engineering \n"); // This method solves the difficult problem of professional input  
 scanf("%d",&stu[count].special); 
 printf(" Please enter the corresponding student class number :1 , 1301 2 , 1302 \n"); 
 scanf("%d",&stu[count].banji); 
 do { 
 printf(" Please enter no greater than in sequence 100 Of the students in all subjects \n"); 
 scanf("%d%d%d%d%d",&stu[count].math,&stu[count].yy,&stu[count].wl,&stu[count].cyy,&stu[count].pe); 
 }while(stu[count].math>100||stu[count].yy>100||stu[count].wl>100||stu[count].cyy>100||stu[count].pe>100); // Ditto ditto  
 stu[count].ave=(stu[count].math+stu[count].yy+stu[count].wl+stu[count].cyy+stu[count].pe)/5.0; // Find the average  
 count++; 
} 
void output(struct student stu[M]) // Custom output functions  
{ 
 int j; 
 system("cls"); 
 if (count==0) 
 { 
 printf(" Current saved student information is 0 a \n"); 
 return; 
 } 
 for (j=0;j<count;j++) 
 { 
 printf(" Student id \t\t  The name \t\t Id number \t Native place \t Mobile phone no. \t\t professional \t\t The class \t mathematics \t English \t physical \tC language \t sports \t average \n"); 
 for (j=0;j<count;j++){ //for Loop controls the number of outputs  
 printf("%s\t",stu[j].num); 
 printf("%s\t",stu[j].name); 
 printf("%s\t",stu[j].credit); 
 printf("%s\t",stu[j].native); 
 printf("%s\t",stu[j].tel); 
 if (stu[j].special==1) 
 printf(" Computer science \t"); 
 else if (stu[j].special==2) 
 printf(" Communication engineering \t"); 
 else 
 printf(" Network engineering \t"); 
 printf("%d\t",stu[j].banji); 
 printf("%d\t",stu[j].math); 
 printf("%d\t",stu[j].yy); 
 printf("%d\t",stu[j].wl); 
 printf("%d\t",stu[j].cyy); 
 printf("%d\t",stu[j].pe); 
 printf("%.1lf\t\n",stu[j].ave);} 
 } 
} 
void lookfor(struct student stu[M])   // Customize the query student information function  
{ 
 int j,flag=0; 
 char xh[25]; 
 system("cls"); 
 if (count==0) 
 { 
 printf(" Current saved student information is 0 a , Unable to query !!!\n"); 
 return; 
 } 
 else 
 { 
 printf(" Please enter the student id you want to see \n"); 
 scanf("%s",&xh); 
 fflush(stdin); 
 for (j=0;j<count;j++) 
 { 
 if (strcmp(stu[j].num,xh)==0) // Character functions are used to compare the stored student information , Identify the students to look at  
 { 
 printf(" Student id \t\t The name \t\t Id number \t Native place \t Mobile phone no. \t\t professional \t\t The class \t mathematics \t English \t physical \tC language \t sports \t average \n"); 
 printf("%s\t",stu[j].num); 
 printf("%s\t",stu[j].name); 
 printf("%s\t",stu[j].credit); 
 printf("%s\t",stu[j].native); 
 printf("%s\t",stu[j].tel); 
 if (stu[j].special==1) 
 printf(" Computer science \t"); 
 else if (stu[j].special==2) 
 printf(" Communication engineering \t"); 
 else 
 printf(" Network engineering \t"); 
 printf("%d\t",stu[j].banji); // consider 1 Two factors of alignment  
 printf("%d\t",stu[j].math); 
 printf("%d\t",stu[j].yy); 
 printf("%d\t",stu[j].wl); 
 printf("%d\t",stu[j].cyy); 
 printf("%d\t",stu[j].pe); 
 printf("%.1lf\t",stu[j].ave); 
 } 
 } 
 if (j==count) 
 printf(" I'm sorry , There is no student information you need \n"); 
 } 
} 
void modify(struct student stu[M]) // Customize the modify function  
{ 
 int j,flag=0,course; 
 char xh[25]; 
 system("cls"); 
 if (count==0) 
 { 
 printf(" Current saved student information is 0 a , Can't modify !!!\n"); 
 return; 
 } 
 else 
 { 
 printf(" Please enter the student id you want to modify \n"); 
 scanf("%s",&xh); 
 fflush(stdin); 
 for (j=0;j<count;j++) 
 if (strcmp(stu[j].num,xh)==0) // Same as above  
 { 
 printf(" Are you sure you want to change the student's information ??? If you're not sure , Please close this program !!!\n"); 
 printf(" Choose course : 1 , mathematics  2 , English  3 , physical  4 , C language  5 , sports \n"); 
 scanf("%d",&course); 
 printf(" Please enter the student grade you want to modify \n"); 
 switch(course) 
 { 
 case 1:scanf("%d",&stu[j].math);break; 
 case 2:scanf("%d",&stu[j].yy);break; //switch Control statements  
 case 3:scanf("%d",&stu[j].wl);break; 
 case 4:scanf("%d",&stu[j].cyy);break; 
 case 5:scanf("%d",&stu[j].pe);break; 
 default:printf(" Invalid selection !!! Please re-enter !!!\n");break; 
 } 
 } 
 } 
} 
void delete_student(struct student stu[M]) // Custom delete functions  
{ 
 int choice; 
 system("cls"); 
 if (count==0) 
 { 
 printf(" Current saved student information is 0 a , Unable to delete !!!\n"); 
 return; 
 } 
 else 
 { 
 printf(" Please select the method you want to delete :1 , student id,  2 , name ( If your name is Chinese , So you can't delete , Please select student id to delete ) 3 , cancellation, \n"); 
 scanf("%d",&choice); 
 switch(choice)  //switch The statement selects how the user wants to delete  
 { 
 case 3:return;break; 
 case 2:xingming(stu);break;  // User-defined currying between functions  
 case 1:xuehao(stu);break; 
 default:printf(" Invalid selection !!! Please re-enter !!!\n");break; 
 } 
 } 
} 
void order(struct student stu[M]) // The definition of the sorting function  
{ 
 int j,k,choice,index; 
 system("cls"); 
 printf(" Please enter the way you want to sort ( All sorts are sorted in descending order )!!!\n"); 
 printf("1 , mathematics  2 , English  3 , physical  4 , C language  5 , sports  6 , the average \n"); 
 scanf("%d",&choice); 
 switch (choice) 
 { 
 case 1:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].math>stu[index].math) 
 {t=stu[k];stu[k]=stu[index];stu[index]=t;} 
 };break; 
 case 2:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].yy>stu[index].yy) 
 {stu[k]=stu[index];}    // The whole thing is sort , A method called selection sort was used  
 };break; 
 case 3:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].wl>stu[index].wl) 
 {t=stu[k];stu[k]=stu[index];stu[index]=t;} 
 };break; 
 case 4:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].cyy>stu[index].cyy) 
 {t=stu[k];stu[k]=stu[index];stu[index]=t;} 
 };break; 
 case 5:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].pe>stu[index].pe) 
 {t=stu[k];stu[k]=stu[index];stu[index]=t;} 
 };break; 
 case 6:for (j=0;j<count;j++) 
 { index=j; 
 for (k=j+1;k<count;k++) 
 if (stu[k].ave>stu[index].ave) 
 {t=stu[k];stu[k]=stu[index];stu[index]=t;} // Cast symbols can only be used with operands, according to the type conversion problem in assignment operations  
 };break; 
 default:printf(" Invalid selection !!! Please re-enter !!!\n");break; 
 } 
} 
void xuehao(struct student stu[M])  // Custom delete student information function by student number method  
{ 
 int j,index=0,k=count; 
 char xh[25]; 
 system("cls"); 
 printf(" Please enter the student id you wish to delete \n"); 
 scanf("%s",xh); 
 fflush(stdin); 
 for (j=0;j<count;j++) 
 { if (strcmp(stu[j].num,xh)==0) 
 { 
 for (j=index;j<count;j++) 
 stu[j]=stu[j+1]; 
 count--; 
 if (count<k) 
 printf(" You have deleted successfully \n"); 
 } 
 index++;} 
 if (j==count) 
 printf(" I'm sorry !!! There is no student information you need to delete !*_*!\n"); 
} 
void xingming(struct student stu[M])  // Custom delete student information function by name  
{ 
 int flag=0,j,k=count; 
 char xm[25]; 
 system("cls"); 
 printf(" Please enter the name of the student you want to delete \n"); 
 scanf("%s",xm); 
 fflush(stdin); 
 for (j=0;j<count;j++) 
 { 
 if (strcmp(stu[j].num,xm)==0) 
 { 
 
 for (j=flag-1;j<count;j++)  
 stu[j]=stu[j+1]; 
 count--; 
 if (count<k) 
 printf(" You have deleted successfully \n"); 
 } 
 flag++;} 
 if (j==count) 
 printf(" I'm sorry !!! There is no student information you need to delete !*_*!\n"); 
} 
void yanshi(char *p)  // The definition of a delay function  
{ 
 while (1) 
 { 
 if (*p!=0) 
 printf("%c",*p++); 
 else 
 break; 
 Sleep(100);  // Delay control hiatus statement  
 } 
} 
void filewrite(struct student stu[M])   // Write to the file function definition  
{ 
 int j=0; 
 char c; 
 FILE *fp; 
 printf(" Please select whether to store the entered student information :'y' or 'n'???\n"); 
 scanf("%c",&c); 
 fflush(stdin); 
 while(c!='y'&&c!='n'){ 
 if (c!='y'&&c!='n') 
 printf(" Input error , Please re-enter \n"); 
 printf(" The following actions will overwrite the stored data , Ok, please enter 'y' or 'n'???\n"); 
 scanf("%c",&c); 
 fflush(stdin); 
 } 
 if (c=='y') 
 { 
 if((fp=fopen("d:\\stu.dat","wb"))==NULL) 
 { 
 printf(" File opening error , Program not working \n"); 
 exit(0); 
 } 
 for(j=0;j<count;j++) 
 {fwrite(&stu[j],sizeof(struct student),1,fp); 
 } 
 fclose(fp); 
 if(count==0) 
 printf(" No file, cannot save \n"); 
 else 
 printf(" Data stored \n"); 
 system("pause"); 
 } 
 else 
 return; 
} 
void fileread(struct student stu[M])   // Read file information function definition  
{ 
 int j=0; 
 char c; 
 FILE *fp; 
 system("cls"); 
 printf(" Please select whether to store the entered student information :'y' or 'n'???\n"); 
 scanf("%c",&c); 
 fflush(stdin); 
 while(c!='y'&&c!='n'){ 
 if (c!='y'&&c!='n') 
 printf(" Input error , Please re-enter \n"); 
 printf(" The following actions will overwrite the stored data , Ok, please enter 'y' or 'n'???\n"); 
 scanf("%c",&c); 
 fflush(stdin); 
 } 
 if (c=='y') 
 { 
 if((fp=fopen("d:\\stu.dat","rb"))==NULL) 
 { 
 printf(" File opening error , Program not working \n"); 
 exit(0); 
 } 
 fread(&stu[j],sizeof(struct student),1,fp); 
 count=0; 
 count++; 
 j++; 
 while(fread(&stu[j],sizeof(struct student),1,fp)) 
 { 
 j++; 
 count++; 
 } 
 fclose(fp); 
 printf(" Data read out !!!\n"); 
 system("pause"); 
 } 
 else 
 return; 
}

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


Related articles: