C language roll management system source code

  • 2020-06-03 07:45:55
  • OfStack

C Language roll Management system, 1 copy for your reference, the specific content is as follows


#include <stdio.h> 
#include <conio.h> 
#include <stdlib.h> 
#define N 100 
void mycreat(); 
void mynewcreat(); 
void mydisplay(); 
void myretake(); 
void myselect(); 
void mynumsort(); 
void mysort(); 
void myprint1(); 
void myprint2(); 
void myprint3(); 
void myfenduan(); 
struct student 
{ 
 char name[10]; 
 int grade[5]; 
 double ave; 
 char num[10]; 
 
}; 
void myprint1() 
{ 
 char choose='\0',yes_no='\0'; 
 do 
 { 
 system("cls"); 
 printf (" |---------------------------|\n"); 
 printf (" |  Please enter the option number (0-4) |\n"); 
 printf (" |---------------------------|\n"); 
 printf (" | 1---------- School grades  |\n"); 
 printf (" | 2---------- Statistical results  |\n"); 
 printf (" | 3---------- Dealing with one's status as a student  |\n"); 
 printf (" | 4---------- Display the data  |\n"); 
 printf (" | 0---------- Log out  |\n"); 
 printf (" |---------------------------|\n"); 
 printf("   "); 
 choose=getche(); 
 switch(choose) 
 { case '1':mycreat(); break; 
  case '2':myprint2(); break; 
  case '3':myprint3(); break; 
  case '4':mydisplay(); break; 
  case '0':break; 
  default :printf("\n   %c Illegal option! \n",choose); 
 } 
 if(choose=='0') 
  { 
  printf("\n"); 
  printf(" Thank you for your use! \n"); 
  break; 
  } 
 printf("\n    Should I continue to choose (Y/N) ? \n"); 
 do 
 { yes_no=getch( ); 
 } while(yes_no!='Y' && yes_no!='y'&& yes_no!='N' && yes_no!='n'); 
 } while(yes_no=='Y' || yes_no=='y'); 
} 
 
 
void myprint2() 
{ 
 char choose='\0',yes_no='\0'; 
 do 
 { 
 system("cls"); 
 printf (" |-----------------------------------|\n"); 
 printf (" |  Please enter the option number (0-4)  |\n"); 
 printf (" |-----------------------------------|\n"); 
 printf (" | 1---------- Sort by student number   |\n"); 
 printf (" | 2---------- Calculate the average score and sort it  |\n"); 
 printf (" | 3---------- Statistical fraction segment   |\n"); 
 printf (" | 4---------- return    |\n"); 
 printf (" | 0---------- Log out   |\n"); 
 printf (" |-----------------------------------|\n"); 
 printf("   "); 
 choose=getche(); 
 switch(choose) 
 { case '1':mynumsort(); break;  
  case '2':mysort(); break; 
  case '3':myfenduan(); break;  
  case '4':myprint1(); break; 
  case '0':break; 
  default :printf("\n   %c Illegal option! \n",choose); 
 } 
 if(choose=='0') 
  { 
  printf("\n"); 
  printf(" Thank you for your use! \n"); 
  break; 
  } 
 printf("\n    Should I continue to choose (Y/N) ? \n"); 
 do 
 { yes_no=getch( ); 
 } while(yes_no!='Y' && yes_no!='y'&& yes_no!='N' && yes_no!='n'); 
 } while(yes_no=='Y' || yes_no=='y'); 
} 
 
void myprint3() 
{ 
 char choose='\0',yes_no='\0'; 
 do 
 { 
 system("cls"); 
 printf (" |---------------------------------------|\n"); 
 printf (" |  Please enter the option number (0-4)   |\n"); 
 printf (" |---------------------------------------|\n"); 
 printf (" | 1---------- Generate and print the make-up exam notice  |\n"); 
 printf (" | 2---------- Generate and print the drop-out notice  |\n"); 
 printf (" | 3---------- Generate and print the new roster   |\n"); 
 printf (" | 4---------- return    |\n"); 
 printf (" | 0---------- Log out    |\n"); 
 printf (" |---------------------------------------|\n"); 
 printf("   "); 
 choose=getche(); 
 switch(choose) 
 { case '1':myretake(); break; 
  case '2':myselect(); break; 
  case '3':mynewcreat(); break; 
  case '4':myprint1(); break; 
  case '0':break; 
  default :printf("\n   %c Illegal option! \n",choose); 
 } 
 if(choose=='0') 
  { 
  printf("\n"); 
  printf(" Thank you for your use! \n"); 
  break; 
  } 
 printf("\n    Should I continue to choose (Y/N) ? \n"); 
 do 
 { yes_no=getch( ); 
 } while(yes_no!='Y' && yes_no!='y'&& yes_no!='N' && yes_no!='n'); 
 } while(yes_no=='Y' || yes_no=='y'); 
} 
 
void mycreat() 
{ 
 int i=1,j=0; 
 struct student temp={0}; 
 FILE*fp=NULL; 
 fp=fopen("d:\\yuan.dat","w"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 system("cls"); 
 printf(" Note: Please keep all the digits when entering your student id 1 To be out of position 0 A filling. For example, the maximum student number is 1000 Are all keep 4 A significant digit. "); 
 printf("\n  Please enter the first 1 A record: \n"); 
 printf("  Student id ( with # The end of the input ):"); 
 do 
 { 
 gets(temp.num); 
 }while(strcmp(temp.num,"")==0); 
 printf("  The name ( with # The end of the input ):"); 
 gets(temp.name); 
 printf("  Please enter the   The high number of   English   physical   programming   philosophy  5 Set of results ( with # The end of the input ): "); 
 for(j=0;j<=4;j++) 
 { 
 scanf("%d",&temp.grade[j]); 
 } 
 
 while(temp.num[0]!='#'&&temp.name[0]!='#'&&temp.grade[0]!='#') 
 { 
 fprintf(fp,"%23s%15s",temp.num,temp.name); 
 for(j=0;j<=4;j++) 
 { 
  fprintf(fp,"%5d",temp.grade[j]); 
 } 
 fprintf(fp,"\n"); 
 i++; 
 printf("\n   Please enter the first %d A record :\n",i); 
 printf("   Student id ( with # The end of the input ):"); 
 do 
 { 
  gets(temp.num); 
 }while(strcmp(temp.num,"")==0); 
  printf("  The name ( with # The end of the input ):"); 
 gets(temp.name); 
 printf("  Please enter the   The high number of   English   physical   programming   philosophy  5 Set of results  ( with # The end of the input ): "); 
 for(j=0;j<=4;j++) 
 { 
  scanf("%8d",&temp.grade[j]); 
 } 
 
 } 
 fclose(fp); 
} 
void mynumsort() 
{ 
 int i=0,j=0,k=0,n=0,grade=0,num=0,m=0,ww; 
 struct student temp[N]={0}; 
 struct student a; 
 FILE *fp=NULL; 
 FILE *fq=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf("\n  Failed to open file !\n"); 
 return; 
 
 } 
 system("cls"); 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 printf("n=%d",n); 
 fclose(fp); 
 printf("\n"); 
 for(i=0; i<n; i++)   
 { k=i; 
 for(j=k+1; j<n; j++) 
  if(strcmp(temp[k].num,temp[j].num)>0) 
  k=j; 
 a=temp[i]; 
 temp[i]=temp[k]; 
 temp[k]=a; 
 } 
 for(k=0;k<n;k++) 
 { 
 printf("%10s No.  %10s classmate ",temp[k].num,temp[k].name); 
 for(m=0;m<5;m++) 
 { 
  printf("%5d points ",temp[k].grade[m]); 
 } 
 printf("\n"); 
 } 
 if(n==0)printf("\n  There is no record in the file! \n"); 
 else printf("\n   In the file %d A record ",n); 
 
 fq=fopen("d:\\std.dat","w"); 
 if(fq==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 exit(0); 
 } 
 for(i=0;i<n;i++) 
 { 
 fprintf(fq,"%23s%15s",temp[i].num,temp[i].name); 
 for(j=0;j<5;j++) 
 { 
  fprintf(fq,"%2d",temp[i].grade[j]); 
 } 
 fprintf(fq,"\n"); 
 } 
 fclose(fq); 
 printf(" Calculation completed   Stored in the d:\std.dat Among the documents, please check "); 
} 
void mysort() 
{ 
 struct student temp[N]={0},a[N]={0}; 
 int i=0,j=0,n=0,ww=0; 
 FILE*fp=NULL; 
 FILE*fq=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 exit(0); 
 } 
 system("cls"); 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 
 for(i=0;i<n;i++) 
 { 
 for(j=0;j<5;j++) 
 { 
  temp[i].ave=temp[i].ave+temp[i].grade[j]; 
 } 
 temp[i].ave=temp[i].ave/5; 
  
 } 
 for(i=0;i<n;i++) 
 { 
 if(temp[i].ave<temp[i+1].ave) 
 { 
  a[i]=temp[i]; 
  temp[i]=temp[i+1]; 
  temp[i+1]=a[i]; 
 } 
 } 
 fq=fopen("d:\\sort.dat","w"); 
 if(fq==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 exit(0); 
 } 
 for(i=0;i<n;i++) 
 { 
 fprintf(fq,"%23s%15s%10.2f",temp[i].num,temp[i].name,temp[i].ave ); 
 
 for(j=0;j<5;j++) 
 { 
  fprintf(fq,"%2d",temp[i].grade[j]); 
 } 
 fprintf(fq,"\n"); 
 } 
 
 fclose(fq); 
 printf(" Calculation completed   Stored in the d:\sort.dat Among the documents, please check "); 
} 
 
void myfenduan() 
{ 
 int i=0,j=0,n=0,ww; 
 int b[N]={0},c[N]={0},d[N]={0},e[N]={0},f[N]={0}; 
 struct student temp[N]={0}; 
 FILE*fp=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 system("cls"); 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 for(i=0;i<n;i++) 
 { 
 for(j=0;j<5;j++) 
  { 
  if(temp[i].grade[j]>=90) 
   b[j]=b[j]+1; 
  else if(temp[i].grade[j]>=80) 
   c[j]=c[j]+1; 
  else if(temp[i].grade[j]>=70) 
   d[j]=d[j]+1; 
  else if(temp[i].grade[j]>=60) 
   e[j]=e[j]+1; 
  else f[j]=f[j]+1; 
  } 
 } 
 printf(" The number of students in each course and section \n"); 
 printf("________________________________________________________\n"); 
 printf(" |90 Points above  | 80~89 points  | 70~79 points  | 60~69 points  | 60 The following  \n"); 
 printf("--------------------------------------------------------\n"); 
 printf(" The high number of _____%d________%d_________%d________%d_________%d___\n",b[0],c[0],d[0],e[0],f[0]); 
 printf("__________________________________________________\n"); 
 printf(" English _____%d________%d_________%d________%d_________%d___\n",b[1],c[1],d[1],e[1],f[1]); 
 printf("__________________________________________________\n"); 
 printf(" physical _____%d________%d_________%d________%d_________%d___\n",b[2],c[2],d[2],e[2],f[2]); 
 printf("__________________________________________________\n"); 
 printf(" programming _____%d________%d_________%d________%d_________%d___\n",b[3],c[3],d[3],e[3],f[3]); 
 printf("__________________________________________________\n"); 
 printf(" philosophy _____%d________%d_________%d________%d_________%d___\n",b[4],c[4],d[4],e[4],f[4]); 
 printf("__________________________________________________\n"); 
 fclose(fp); 
} 
void mydisplay() 
{ int n=0,j=0,k=0,m=0,ww; 
 struct student temp[N]={0}; 
 FILE*fp=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 system("cls"); 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 for(k=0;k<n;k++) 
 { 
 printf("%23s %15s ",temp[k].num,temp[k].name); 
 
 for(m=0;m<5;m++) 
 { 
  printf("%d ",temp[k].grade[m]); 
 } 
 printf("\n"); 
 } 
 if(n==0)printf("\n  There is no record in the file! \n"); 
 else printf("\n  The files are all together %d A record! ",n); 
 fclose(fp); 
} 
 
void myretake() 
{ 
 int i=0,e=0,j=0,n=0,s[5]={0},ww; 
 struct student temp[N]={0}; 
 FILE*fp=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 for (i=0;i<n;i++) 
 { 
 for(j=0;j<5;j++) 
 { 
  if(temp[i].grade[j]<60) 
  s[i]++; 
 } 
  
 if(s[i]>=1 && s[i]<=3) 
 { printf("\n"); 
  printf(" Student id %10s  The name %10s \n",temp[i].num,temp[i].name); 
 if(temp[i].grade[0]<60) 
  printf("%10s Your advanced degree is %6d A make-up examination is required , please 2011 years 2 month 26 The morning of 9 Point at the teaching building 5023 The classroom has a make-up examination \n",temp[i].name,temp[i].grade[0]); 
  
 if(temp[i].grade[1]<60) 
  printf("%10s Your score in English is %6d A make-up examination is required , please 2011 years 2 month 27 The morning of 9 Point at the teaching building 5023 The classroom has a make-up examination \n",temp[i].name,temp[i].grade[1]); 
  
 if(temp[i].grade[2]<60) 
  printf("%10s Your physics score is %6d A make-up examination is required , please 2011 years 2 month 28 The morning of 9 Point at the teaching building 5023 The classroom has a make-up examination \n",temp[i].name,temp[i].grade[2]); 
  
 if(temp[i].grade[3]<60) 
  printf("%10s Your programming score is %6d A make-up examination is required , please 2011 years 2 month 26 On the afternoon 3 Point at the teaching building 5023 The classroom has a make-up examination \n",temp[i].name,temp[i].grade[3]); 
  
 if(temp[i].grade[4]<60) 
  printf("%10s Your marks for Mazur are %6d A make-up examination is required , please 2011 years 2 month 28 On the afternoon 3 Point at the teaching building 5023 The classroom has a make-up examination \n",temp[i].name,temp[i].grade[4]); 
 } 
 } 
 for(e=0;e<n;e++) 
 { 
 if(s[e]!=0) 
 { 
  printf("\n"); 
  printf(" The above students need make-up examination! "); 
 } 
 else 
 { 
  printf("\n"); 
  printf(" No students need make-up exams! "); 
 } 
 break; 
 } 
} 
void myselect() 
{ 
 int i=0,k=0,s[5]={0},n=0,j=0,ww; 
 struct student temp[N]={0}; 
 FILE*fp=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
  
 for(j=0;j<5;j++) 
  { 
  ww=fscanf(fp,"%d",&temp[n].grade[j]); 
  if(ww==-1) break; 
 } 
 n++; 
 } 
 for(i=0;i<n-1;i++) 
 { 
  
  for(k=0;k<5;k++) 
  { 
  if (temp[i].grade[k]<60) 
   s[i]=s[i]+1; 
  }  
  if(s[i]>3) 
  { 
  printf("\n"); 
  printf(" Student id %10s  The name %10s  Because you failed the subject for %d The door (more than 3 ), so I quit school. \n",temp[i].num,temp[i].name,s[i]); 
  if (temp[i].grade[0]<60) 
   printf("%15s Your advanced degree is %6d To fail. \n",temp[i].name,temp[i].grade[0]); 
   
  if (temp[i].grade[1]<60) 
   printf("%15s Your score in English is %6d To fail. \n",temp[i].name,temp[i].grade[1]); 
   
  if (temp[i].grade[2]<60) 
   printf("%15s Your physics score is %6d To fail. \n",temp[i].name,temp[i].grade[2]); 
   
  if (temp[i].grade[3]<60) 
   printf("%15s Your programming score is %6d To fail. \n",temp[i].name,temp[i].grade[3]); 
   
  if (temp[i].grade[4]<60) 
   printf("%15s Your marks for Mazur are %6d To fail. \n",temp[i].name,temp[i].grade[4]); 
   
  } 
 } 
} 
 
void mynewcreat() 
{ 
 int i=0,k=0,s[5]={0},z[5]={0},v=0,n=0,m=0,j=0,p=0,c=0,ww; 
 struct student temp[N]={0}; 
 FILE*fp=NULL; 
 FILE*fq=NULL; 
 fp=fopen("d:\\yuan.dat","r"); 
 if(fp==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 return; 
 } 
 while(feof(fp)==0) 
 { 
 ww=fscanf(fp,"%23s%15s",temp[n].num,temp[n].name); 
 if(ww==-1) break; 
 for(j=0;j<5;j++) 
 { 
  fscanf(fp,"%d",&temp[n].grade[j]); 
  
 } 
 n++; 
 } 
 while(i<=n) 
 { 
  for(k=0;k<5;k++) 
  { 
  if (temp[i].grade[k]<60) 
  s[i]=s[i]+1; 
  } 
  
  for(v=0;v<5;v++) 
  { 
  if(temp[i].grade[v]==0) 
   z[i]++; 
  } 
  if(z[i]==5) 
  { 
  break; 
  } 
  if(s[i]<=3) 
  { 
  i++; 
  } 
  if(s[i]>3) 
  { 
  for(c=i;c<=n;c++) 
  { 
   temp[c]=temp[c+1]; 
  } 
  s[i]=0; 
  } 
 }  
 printf("\n"); 
 printf(" After the removal of a dropped out student, the student roster is: "); 
 printf("\n"); 
 for(p=0;p<n-1;p++) 
 { 
  printf("\n"); 
  printf("%10s No.  %10s points  ",temp[p].num,temp[p].name); 
  for(m=0;m<5;m++) 
  { 
   printf("%d ",temp[p].grade[m]); 
  } 
  printf("\n"); 
 } 
 fq=fopen("d:\\next.dat","w"); 
 if(fq==NULL) 
 { 
 printf(" Failed to open file! \n"); 
 exit(0); 
 } 
 for(i=0;i<n;i++) 
 { 
 fprintf(fq,"%23s%15s",temp[i].num,temp[i].name); 
 for(j=0;j<5;j++) 
 { 
  fprintf(fq,"%2d",temp[i].grade[j]); 
 } 
 fprintf(fq,"\n"); 
 } 
fclose(fq); 
 printf(" Calculation completed   Stored in the d:\next.dat Among the documents, please check "); 
} 
main() 
{ 
 myprint1(); 
 } 

If you have time to sort out what you have learned, review the old and learn the new.

For more information, please pay attention to the topic management System Development.


Related articles: