Student information management system C language version

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

The C language student information management system includes the following functions:

1. Overall registration of student information
2. Modification of student information
3. Input student achievement information
4. Adding student information
5. Restore the student information deleted by mistake
6. Deletion of student information
7. Save password modification function
8. Student information inquiry
9. Password modification function
10. Menu function of student information management system


#include "stdio.h" 
#include "malloc.h" 
#include "string.h" 
#include "stdlib.h" 
#include "conio.h" 
#define M 3 
struct student 
{ 
 char num[10]; /*  Student's student number  */ 
 char name[20]; /*  Student's name  */ 
 char sex[5]; /*  Student gender  */ 
 int age;  /*  Student's age  */ 
 char birth[20]; /*  Student's date of birth  */ 
 long tele;  /*  Student's phone number  */ 
 char addr[30]; /*  Student address  */ 
 char party[10]; /*  Whether students are party members  */ 
 float score[M]; /*  Students' grades in all subjects  */ 
 float total; /*  The total score of the students in the subject  */ 
 struct student *next; 
 
}stud[100]; 
struct secret 
{ 
 char user[30]; 
 char code[30]; 
 
}use[100]; 
int len; // The number of students  
 
///////////////////////////////////////////////////////////////////////////////// 
/* Student information is written to the file ----- The system function */ 
///////////////////////////////////////////////////////////////////////////////// 
void writetxt(struct student *head) 
{ 
 struct student *p; 
 p=head; 
 FILE *fp; 
 fp=fopen("d://student.txt","wb"); 
 if(fp==NULL) 
 { 
 printf("cannot open"); 
 return ; 
 } 
 while(p!=NULL) 
 { 
 fwrite(p,sizeof(struct student),1,fp); 
 p=p->next; 
 } 
 fclose(fp); 
 
} 
 
///////////////////////////////////////////////////////////////////////////////// 
/*  Student information for overall enrollment */ 
///////////////////////////////////////////////////////////////////////////////// 
struct student *create( ) 
{ 
 char ch; 
 char ok; 
 int i; 
 struct student *p,*p1,*head,*p2; 
 FILE *fp; 
 fp=fopen("d://student.txt","rb"); 
 if(fp==NULL) 
 { 
 printf("/n  The file does not exist, do you want to create it? (Y/N)/n"); 
 ch=getchar(); 
 len=1; 
 scanf("%c",&ok); 
 if(ok=='Y'||ok=='y') 
 { 
 p1=p2=(struct student *) malloc(sizeof(struct student)); 
 if((len)<10) 
 printf(" Please enter the 0%d The student id :",len); 
 else 
 printf(" Please enter the %d The student id :",len); 
 scanf("%s",p1->num); 
 if((len)<10) 
 printf(" Please enter the 0%d The names of the :",len); 
 else 
 printf(" Please enter the %d The names of the :",len); 
 scanf("%s",p1->name); 
 if((len)<10) 
 printf(" Please enter the 0%d The gender of the :",len); 
 else 
 printf(" Please enter the %d The gender of the :",len); 
 scanf("%s",p1->sex); 
 ch=getchar(); 
 if((len)<10) 
 printf(" Please enter the 0%d In the age of :",len); 
 else 
 printf(" Please enter the %d In the age of :",len); 
 scanf("%d",&p1->age); 
 if((len)<10) 
 printf(" Please enter the 0%d The birthday of :",len); 
 else 
 printf(" Please enter the %d The birthday of :",len); 
 scanf("%s",p1->birth); 
 if((len)<10) 
 printf(" Please enter the 0%d The phone :",len); 
 else 
 printf(" Please enter the %d The phone no. :",len); 
 scanf("%ld",&p1->tele); 
 if((len)<10) 
 printf(" Please enter the 0%d The address of the :",len); 
 else 
 printf(" Please enter the %d The address of the :",len); 
 scanf("%s",p1->addr); 
 if((len)<10) 
 printf(" Please enter the 0%d Party member :",len); 
 else 
 printf(" Please enter the %d Party member :",len); 
 scanf("%s",p1->party); 
 head=NULL; 
 while(strcmp(p1->num,"0")!=0) 
 { 
 len++; 
 if(head==NULL) 
  head=p1=p2; 
 else 
  p2->next=p1; 
 p2=p1; 
 p1=(struct student *) malloc(sizeof(struct student)); 
 if((len)<10) 
  printf(" Please enter the 0%d The student id :",len); 
 else 
  printf(" Please enter the %d The student id :",len); 
 scanf("%s",p1->num); 
 if((len)<10) 
  printf(" Please enter the 0%d The names of the :",len); 
 else 
  printf(" Please enter the %d The names of the :",len); 
 scanf("%s",p1->name); 
 if((len)<10) 
  printf(" Please enter the 0%d The gender of the :",len); 
 else 
  printf(" Please enter the %d The gender of the :",len); 
 scanf("%s",p1->sex); 
 ch=getchar(); 
 if((len)<10) 
  printf(" Please enter the 0%d In the age of :",len); 
 else 
  printf(" Please enter the %d In the age of :",len); 
 scanf("%d",&p1->age); 
 if((len)<10) 
  printf(" Please enter the 0%d The birthday of :",len); 
 else 
  printf(" Please enter the %d The birthday of :",len); 
 scanf("%s",p1->birth); 
 if((len)<10) 
  printf(" Please enter the 0%d The phone :",len); 
 else 
  printf(" Please enter the %d The phone no. :",len); 
 scanf("%ld",&p1->tele); 
 if((len)<10) 
  printf(" Please enter the 0%d The address of the :",len); 
 else 
  printf(" Please enter the %d The address of the :",len); 
 scanf("%s",p1->addr); 
 if((len)<10) 
  printf(" Please enter the 0%d Party member :",len); 
 else 
  printf(" Please enter the %d Party member :",len); 
 scanf("%s",p1->party); 
 } 
 p2->next=NULL; 
 writetxt(head); 
 return (head); 
 } 
 } 
 if(ok=='N'||ok=='n') 
 { 
 printf(" Please reselect /n"); 
 return NULL; 
 } 
 else 
 { 
 printf("/n  The file already exists /n"); 
 fp=fopen("d://student.txt","rb"); 
 p=stud; 
 for(i=0;!feof(fp);i++) 
 fread(stud+i,sizeof(struct student),1,fp); 
 len=i-1; 
 printf("  The file contains %d Section student information /n",len); 
 printf("/n  Do you use existing student data? (Y/N)/n"); 
 ch=getchar(); 
 scanf("%c",&ok); 
 if(ok=='Y'||ok=='y') 
 { 
 head=p1=p2=NULL; 
 fp=fopen("d://student.txt","rb"); 
 if(fp==NULL) 
 { 
 printf("open error/n"); 
 return NULL; 
 } 
 else 
 { 
 printf(" Student id   The name   gender   age   Date of birth   The phone number   address   Whether the party members' /n"); 
 for(i=0;i<len;i++) 
 { 
  p1=(struct student *)malloc(sizeof(struct student)); 
  fread(p1,sizeof(struct student),1,fp); 
  if(head==NULL) 
  head=p2=p1; 
  else 
  p2->next=p1; 
  p2=p1; 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
 } 
 fclose(fp); 
 return(head); 
 } 
 } 
 if(ok=='N'||ok=='n') 
 { 
 len=1; 
 p1=p2=( struct student *) malloc(sizeof(struct student )); 
 if((len)<10) 
 printf(" Please enter the 0%d The student id :",len); 
 else 
 printf(" Please enter the %d The student id :",len); 
 scanf("%s",p1->num); 
 if((len)<10) 
 printf(" Please enter the 0%d The names of the :",len); 
 else 
 printf(" Please enter the %d The names of the :",len); 
 scanf("%s",p1->name); 
 if((len)<10) 
 printf(" Please enter the 0%d The gender of the :",len); 
 else 
 printf(" Please enter the %d The gender of the :",len); 
 scanf("%s",p1->sex); 
 ch=getchar(); 
 if((len)<10) 
 printf(" Please enter the 0%d In the age of :",len); 
 else 
 printf(" Please enter the %d In the age of :",len); 
 scanf("%d",&p1->age); 
 if((len)<10) 
 printf(" Please enter the 0%d The birthday of :",len); 
 else 
 printf(" Please enter the %d The birthday of :",len); 
 scanf("%s",p1->birth); 
 if((len)<10) 
 printf(" Please enter the 0%d The phone :",len); 
 else 
 printf(" Please enter the %d The phone no. :",len); 
 scanf("%ld",&p1->tele); 
 if((len)<10) 
 printf(" Please enter the 0%d The address of the :",len); 
 else 
 printf(" Please enter the %d The address of the :",len); 
 scanf("%s",p1->addr); 
 if((len)<10) 
 printf(" Please enter the 0%d Party member :",len); 
 else 
 printf(" Please enter the %d Party member :",len); 
 scanf("%s",p1->party); 
 head=NULL; 
 while(strcmp(p1->num,"0")!=0) 
 { 
 if(head==NULL) 
  head=p1=p2; 
 else 
  p2->next=p1; 
 p2=p1; 
 p1=(struct student *) malloc(sizeof(struct student)); 
 if((len)<10) 
  printf(" Please enter the 0%d The student id :",len); 
 else 
  printf(" Please enter the %d The student id :",len); 
 scanf("%s",p1->num); 
 if((len)<10) 
  printf(" Please enter the 0%d The names of the :",len); 
 else 
  printf(" Please enter the %d The names of the :",len); 
 scanf("%s",p1->name); 
 if((len)<10) 
  printf(" Please enter the 0%d The gender of the :",len); 
 else 
  printf(" Please enter the %d The gender of the :",len); 
 scanf("%s",p1->sex); 
 ch=getchar(); 
 if((len)<10) 
  printf(" Please enter the 0%d In the age of :",len); 
 else 
  printf(" Please enter the %d In the age of :",len); 
 scanf("%d",&p1->age); 
 if((len)<10) 
  printf(" Please enter the 0%d The birthday of :",len); 
 else 
  printf(" Please enter the %d The birthday of :",len); 
 scanf("%s",p1->birth); 
 if((len)<10) 
  printf(" Please enter the 0%d The phone :",len); 
 else 
  printf(" Please enter the %d The phone no. :",len); 
 scanf("%ld",&p1->tele); 
 if((len)<10) 
  printf(" Please enter the 0%d The address of the :",len); 
 else 
  printf(" Please enter the %d The address of the :",len); 
 scanf("%s",p1->addr); 
 if((len)<10) 
  printf(" Please enter the 0%d Party member :",len); 
 else 
  printf(" Please enter the %d Party member :",len); 
 scanf("%s",p1->party); 
 } 
 p2->next=NULL; 
 writetxt(head); 
 } 
 return (head); 
 } 
} 
//////////////////////////////////////////////////////////////////////////////// 
/* Student information modification */ 
//////////////////////////////////////////////////////////////////////////////// 
struct student *change(struct student *head) 
{ 
 
 struct student *p=head; 
 int age,choose,m; 
 long tele; 
 char num[10]; 
 char ch,yes,sex[5],birth[20],addr[30],party[10]; 
 char *p1; 
 if(head==NULL) 
 { 
 printf(" The original list is empty "); 
 return NULL; 
 } 
 else 
 { 
 while(1) 
 { 
 printf(" Please enter your student number /n"); 
 scanf("%s",num); 
 p=head; 
 while(p!=NULL&&strcmp(p->num,num)!=0) 
 { 
 p=p->next; 
 if(p==NULL) 
 { 
  printf(" The student does not exist /n"); 
  break; 
 } 
 if(strcmp(p->name,"0")==0) 
 { 
  printf(" The student no longer exists /n"); 
  break; 
 } 
 } 
 m=0; 
 while(1) 
 { 
 if(p==NULL) 
  break; 
 if(strcmp(p->name,"0")==0) 
  break; 
 printf(" Please select a 1. gender  2. age  3. Date of birth 4. The phone  5. Home address 6. The party member /n"); 
 scanf("%d",&choose); 
 if(choose==1) 
 { 
  printf(" Please enter the new gender: /n"); 
  scanf("%s",&sex); 
  p1=sex; 
  strcpy(p->sex,p1); 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 if(choose==2) 
 { 
  printf(" Please enter the new age: /n"); 
  scanf("%d",&age); 
  p->age=age; 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 if(choose==3) 
 { 
  printf(" Please enter new date of birth: /n"); 
  scanf("%s",birth); 
  p1=birth; 
  strcpy(p->birth,p1); 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 if(choose==4) 
 { 
  printf(" Please enter a new phone: /n"); 
  scanf("%d",&tele); 
  p->tele=tele; 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 if(choose==5) 
 { 
  printf(" Please enter your new home address: /n"); 
  scanf("%s",addr); 
  p1=addr; 
  strcpy(p->addr,p1); 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 if(choose==6) 
 { 
  printf(" Please enter the ' is ' or ' no ' : /n"); 
  scanf("%s",party); 
  p1=party; 
  strcpy(p->party,p1); 
  printf(" Whether to continue to modify this student student other information Y/N/n"); 
  ch=getchar(); 
  scanf("%c",&yes); 
  if(yes=='N'||yes=='n') 
  break; 
 } 
 } 
 printf(" Whether to continue to modify other students Y/N/n"); 
 ch=getchar(); 
 scanf("%c",&yes); 
 if(yes=='N'||yes=='n') 
 break; 
 } 
 writetxt(head); 
 p=head; 
 while(p!=NULL) 
 { 
 printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p->num,p->name,p->sex,p->age,p->birth,p->tele,p->addr,p->party); 
 p=p->next; 
 } 
 return head; 
 } 
} 
///////////////////////////////////////////////////////////////////////////////// 
/* Input of student achievement information */ 
///////////////////////////////////////////////////////////////////////////////// 
struct student *chengji(struct student *head) 
{ 
 FILE *fp; 
 struct student *p1,*p; 
 int i; 
 float sum=0; 
 fp=fopen("d://student1.txt","wb"); 
 p1=(struct student *)malloc(sizeof(struct student)); 
 p1=head; 
 while(p1!=NULL) 
 { 
 if(strcmp(p1->name,"0")==0) 
 { 
 printf(" The student does not exist /n"); 
 p1=p1->next; 
 continue; 
 } 
 printf(" Please enter student number as %s The high number of students, C Language, English scores :/n",p1->num); 
 for(i=0;i<M;i++) 
 { 
 scanf("%f",&p1->score[i]); 
 sum+=p1->score[i]; 
 } 
 p1->total=sum; 
 sum=0; 
 fwrite(p1,sizeof(struct student),1,fp); 
 
 p1=p1->next; 
 } 
 fclose(fp); 
 writetxt(head); 
 p=head; 
 printf(" Student id   The name   gender   age   Date of birth   The phone number   address   Whether the party members' /n"); 
 while(p!=NULL) 
 { 
 printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p->num,p->name,p->sex,p->age,p->birth,p->tele,p->addr,p->party); 
 p=p->next; 
 } 
 return(head); 
} 
///////////////////////////////////////////////////////////////////////////////// 
/* The addition of student information */ 
///////////////////////////////////////////////////////////////////////////////// 
struct student *insert(struct student *head) 
{ 
 char ch,ok; 
 struct student *p,*p0,*p1; 
 p=p1=head; 
 while(1) 
 { 
 if((len+1)<10) 
 printf(" Your student number is 0%d/n",len+1); 
 else 
 printf(" Your student number is %d/n",len+1); 
 p0=(struct student *)malloc(sizeof(struct student)); 
 len++; 
 if((len)<10) 
 printf(" Please enter the 0%d The student id :",len); 
 else 
 printf(" Please enter the %d The student id :",len); 
 scanf("%s",p0->num); 
 if((len)<10) 
 printf(" Please enter the 0%d The names of the :",len); 
 else 
 printf(" Please enter the %d The names of the :",len); 
 scanf("%s",p0->name); 
 if((len)<10) 
 printf(" Please enter the 0%d The gender of the :",len); 
 else 
 printf(" Please enter the %d The gender of the :",len); 
 scanf("%s",p0->sex); 
 ch=getchar(); 
 if((len)<10) 
 printf(" Please enter the 0%d In the age of :",len); 
 else 
 printf(" Please enter the %d In the age of :",len); 
 scanf("%d",&p0->age); 
 if((len)<10) 
 printf(" Please enter the 0%d The birthday of :",len); 
 else 
 printf(" Please enter the %d The birthday of :",len); 
 scanf("%s",p0->birth); 
 if((len)<10) 
 printf(" Please enter the 0%d The phone :",len); 
 else 
 printf(" Please enter the %d The phone no. :",len); 
 scanf("%ld",&p0->tele); 
 if((len)<10) 
 printf(" Please enter the 0%d The address of the :",len); 
 else 
 printf(" Please enter the %d The address of the :",len); 
 scanf("%s",p0->addr); 
 if((len)<10) 
 printf(" Please enter the 0%d Party member :",len); 
 else 
 printf(" Please enter the %d Party member :",len); 
 scanf("%s",p0->party); 
 while(p->next!=NULL) 
 p=p->next; 
 p->next=p0; 
 p0->next=NULL; 
 printf(" Whether to continue to add Y/N/n") ; 
 ch=getchar(); 
 scanf("%c",&ok); 
 if(ok=='y'||ok=='Y')len++; 
 else 
 { 
 printf(" You need to do it again 1 To complete the registration of the student information , thank you !/n"); 
 break; 
 } 
 } 
 p=head; 
 while(p!=NULL) 
 { 
 printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p->num,p->name,p->sex,p->age,p->birth,p->tele,p->addr,p->party); 
 p=p->next; 
 } 
 writetxt(head); 
 return(head); 
 
} 
///////////////////////////////////////////////////////////////////////////////// 
/*  Restore the student information deleted by mistake */ 
///////////////////////////////////////////////////////////////////////////////// 
struct student *recover(struct student *head) 
{ 
 FILE *fp; 
 struct student *p1,*p; 
 p=p1=(struct student*)malloc(sizeof(struct student)); 
 char ch; 
 char num[10]; 
 p1=head; 
 printf("input the recover number:"); 
 scanf("%s",num); 
 fp=fopen("d://recycle.txt","rb"); 
 if(fp==NULL) 
 { 
 printf(" The recycle bin is empty !/n"); 
 return NULL; 
 } 
 else 
 { 
 printf(" Will the recycle bin data be restored? Y/N /n"); 
 ch=getchar(); 
 ch=getchar(); 
 if(ch=='n'||ch=='N') 
 printf(" No need to restore! "); 
 else 
 { 
 while(1) 
 { 
 if(strcmp(p1->num,num)==0) 
  break; 
 else 
  p1=p1->next; 
 } 
 while(!feof(fp)) 
 { 
 fread(p,sizeof(struct student),1,fp); 
 if(strcmp(p1->num,p->num)==0) 
 { 
  strcpy(p1->name,p->name); 
  strcpy(p1->sex,p->sex); 
  p1->age=p->age; 
  strcpy(p1->birth,p->birth); 
  p1->tele=p->tele; 
  strcpy(p1->addr,p->addr); 
  strcpy(p1->party,p->party); 
  printf("dddddddddddddddddddd/n"); 
  break; 
 
 } 
 } 
 
 } 
 writetxt(head); 
 
 p=head; 
 while(p!=NULL) 
 { 
 printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p->num,p->name,p->sex,p->age,p->birth,p->tele,p->addr,p->party); 
 p=p->next; 
 }fclose(fp); 
 } 
 return head; 
} 
///////////////////////////////////////////////////////////////////////////////// 
/*  Deletion of student information */ 
///////////////////////////////////////////////////////////////////////////////// 
struct student *del(struct student *head) 
{ 
 FILE *fp; 
 struct student *p1,*p2,*p0; 
 p1=p2=head; 
 char ch; 
 char num[10]; 
 printf("input the delete number:"); 
 scanf("%s",num); 
 if(head==NULL) 
 printf("nothing to delete!"); 
 else 
 { 
 while(p1!=NULL) 
 { 
 if(strcmp(p1->num,num)!=0) 
 { 
 p2=p1; 
 p1=p1->next; 
 } 
 if(strcmp(p1->num,num)==0) 
 { 
 p0=p1; 
 printf(" Do you want to delete the student's information permanently? Y/N /n"); 
 ch=getchar(); 
 ch=getchar(); 
 if(ch=='y'||ch=='Y') 
 { 
  printf(" This student information has been successfully removed from disk! /n"); 
  if(p1==head) 
  { 
  p0=p1; 
  head=p1->next; 
  p1=p2=head; 
  p1=p2->next; 
  } 
  else 
  { 
  p0=p1; 
  p2->next=p1->next; 
  p1=p2->next; 
  } 
  break; 
 } 
 else 
 { 
  fp=fopen("d://recycle.txt","ab+"); 
  if(fp==NULL) 
  { 
  printf("cannot open the file!"); 
  return NULL; 
  } 
  fwrite(p0,sizeof(struct student),1,fp); 
  strcpy(p1->name,"0"); 
  strcpy(p1->sex,"0"); 
  p1->age=0; 
  strcpy(p1->birth,"0"); 
  p1->tele=0; 
  strcpy(p1->addr,"0"); 
  strcpy(p1->party,"0"); 
 
  printf(" Student information has been put into the recycle bin! /n"); 
  fclose(fp); 
 
 
  printf(" If you want to restore the student information you just deleted, please enter 'Y'or'y'/n"); 
  printf(" If you do not want to restore the student information you just deleted, please enter 'N'or'n'/n"); 
  ch=getchar(); 
  ch=getchar(); 
  if(ch=='y'||ch=='Y') 
  { 
  head=recover(head); 
  break; 
  } 
  if(ch=='n'||ch=='N') 
  break ; 
 } 
 } 
 
 } 
 
 } 
 writetxt(head); 
 return head; 
} 
///////////////////////////////////////////////////////////////////////////// 
/*  Password change save function */ 
//////////////////////////////////////////////////////////////////////////// 
void write() 
{ 
 FILE *fp; 
 struct secret p; 
 int i; 
 fp=fopen("d://mima.txt","wb"); 
 if(fp==NULL) 
 { 
 printf("cannot open!"); 
 
 } 
 for(i=0;i<=len;i++) 
 { 
 p=use[i]; 
 fwrite(&p,sizeof(struct secret),1,fp); 
 } 
 fclose(fp); 
 
} 
 
//////////////////////////////////////////////////////////////////////////////// 
/* Student information query */ 
//////////////////////////////////////////////////////////////////////////////// 
void research(struct student *head) 
{ 
 struct student *p1,*p2; 
 p1=p2=head; 
 int i,j,l=1,k=0; 
 char sex[20],party[10],ch,yes; 
 int age; 
 char num[10],name[20]; 
 printf(" Options: 1. Fuzzy query  2. Precise inquiry: "); 
 scanf("%d",&i); 
 if(i==1) 
 { 
 while(l==1) 
 { 
 printf(" Options: 1. gender  2. age  3. Party member or not: "); 
 scanf("%d",&j); 
 if(j==1) 
 { p1=head; 
 printf(" Input gender: "); 
 scanf("%s",sex); 
 ch=getchar(); 
 while(p1!=NULL) 
 { 
 if(strcmp(p1->sex,sex)==0) 
 { 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
  p1=p1->next; 
  continue; 
 } 
 k++; 
 if(k==3) 
  printf(" The student does not exist !/n"); 
 p1=p1->next; 
 } 
 printf(" Whether to continue to search the student's other information Y/N/n"); 
 scanf("%c",&yes); 
 printf("yes=%c/n",yes); 
 if(yes=='N'||yes=='n') 
 break; 
 if(yes=='Y'||yes=='y') 
 k=0; 
 } 
 if(j==2) 
 { 
 p1=head; 
 printf(" Input age: "); 
 scanf("%d",&age); 
 while(p1!=NULL) 
 { 
  if(p1->age==age) 
  { 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
  p1=p1->next; 
  continue; 
  } 
  k++; 
  if(k==3) 
  printf(" The student does not exist !/n"); 
  p1=p1->next; 
 } 
 printf(" Whether to continue to search the student's other information Y/N/n"); 
 ch=getchar(); 
 scanf("%c",&yes); 
 if(yes=='N'||yes=='n') 
  break; 
 if(yes=='Y'||yes=='y') 
  k=0; 
 } 
 if(j==3) 
 { 
 p1=head; 
 printf(" Party member or not: "); 
 scanf("%s",party); 
 ch=getchar(); 
 while(p1!=NULL) 
 { 
  if(strcmp(p1->party,party)==0) 
  { 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
  p1=p1->next; 
  continue; 
  } 
  k++; 
  if(k==3) 
  printf(" The student does not exist !/n"); 
  p1=p1->next; 
 } 
 printf(" Will you continue to search for other information about the student? Y/N/n"); 
 scanf("%c",&yes); 
 if(yes=='N'||yes=='n') 
  break; 
 if(yes=='Y'||yes=='y') 
  k=0; 
 } 
 } 
 } 
 if(i==2) 
 { 
 printf(" Please select the key words for close inspection: 1. Student student id  2. Student name: "); 
 scanf("%d",&j); 
 if(j==1) 
 { 
 while(1) 
 { 
 p1=head; 
 printf(" Enter the student's student number: "); 
 scanf("%5s",num); 
 while(p1!=NULL) 
 { 
  if(strcmp(p1->num,num)==0) 
  { 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
  p1=p1->next;continue; 
  } 
  k++; 
  if(k==3) 
  printf(" The student does not exist !/n"); 
  p1=p1->next; 
 } 
 printf(" Whether to continue to search for other student information ?Y/N/n"); 
 ch=getchar(); 
 scanf("%c",&yes); 
 if(yes=='N'||yes=='n') 
  break; 
 if(yes=='Y'||yes=='y') 
  k=0; 
 } 
 } 
 if(j==2) 
 { 
 while(1) 
 { 
 p1=head; 
 printf(" Enter the student's name: "); 
 scanf("%s",name); 
 while(p1!=NULL) 
 { 
  if(strcmp(p1->name,name)==0) 
  { 
  printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",p1->num,p1->name,p1->sex,p1->age,p1->birth,p1->tele,p1->addr,p1->party); 
  p1=p1->next;continue; 
  } 
  k++; 
  if(k==3) 
  printf(" The student does not exist !/n"); 
  p1=p1->next; 
 } 
 printf(" Whether to continue to search for other student information ?Y/N/n"); 
 ch=getchar(); 
 scanf("%c",&yes); 
 if(yes=='N'||yes=='n') 
  break; 
 if(yes=='Y'||yes=='y') 
  k=0; 
 } 
 } 
 } 
} 
 
//////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////// 
void research1(char num[]) 
{ 
 int i; 
 for(i=0;i<=len;i++) 
 if(strcmp(stud[i].num,num)==0) 
 printf("%2s%15s%10s%10d%15s%8ld%10s%8s/n",stud[i].num,stud[i].name,stud[i].sex,stud[i].age,stud[i].birth,stud[i].tele,stud[i].addr,stud[i].party); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
/*  Password change function -*/ 
//////////////////////////////////////////////////////////////////////////// 
void mimacli() 
{ 
 char use1[30],mima[30],newmima[30],ch; 
 int i,j=0; 
 printf(" Enter user name: /n"); 
 scanf("%s",use1); 
 printf(" Enter password: /n"); 
 while(1) 
 { 
 mima[j]=getch(); 
 if(mima[j]==13) 
 break; 
 putchar('*'); 
 j++; 
 } 
 mima[j]='/0'; 
 printf("/n"); 
 for(i=0;i<=len;i++) 
 { 
 if(strcmp(stud[i].name,"0")==0) 
 { 
 printf(" The student does not exist /n"); 
 continue; 
 } 
 if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)==0) 
 { 
 printf(" Enter a new password: /n"); 
 ch=getchar(); 
 j=0; 
 while(1) 
 { 
 newmima[j]=getch(); 
 if(newmima[j]==13) 
  break; 
 putchar('*'); 
 j++; 
 } 
 newmima[j]='/0'; 
 printf("/n"); 
 strcpy(use[i].code,newmima); 
 write(); 
 for(i=0;i<=len;i++){ 
 printf("///////////////////////////////////////////////n"); 
 printf("%s ",use[0].user); 
 printf("%s/n",use[0].code); 
 printf("///////////////////////////////////////////////n");} 
 break; 
 } 
 if(strcmp(use1,use[1].user)<0||strcmp(use1,use[len].user)>0) 
 { 
 printf("**************************************/n"); 
 printf(" 4 User name error  /n"); 
 printf("***************************************/n"); 
 
 break; 
 } 
 if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)!=0) 
 { 
 printf("**************************************/n"); 
 printf("  Password mistake  /n"); 
 printf("***************************************/n"); 
 
 break; 
 } 
 } 
} 
///////////////////////////////////////////////////////////////////////////// 
/*  Menu function of student information management system - The system function */ 
//////////////////////////////////////////////////////////////////////////// 
int menu() 
{ 
 int sn,i,j=0; 
 char use1[30]; 
 char mima[30]; 
 int m=0; 
 printf("  Student information management system /n"); 
 printf("=========================================/n"); 
 printf(" 1. Student information for overall enrollment /n"); 
 printf(" 2. Student information modification /n"); 
 printf(" 3. The addition of student information /n"); 
 printf(" 4. Deletion of student information /n"); 
 printf(" 5. Input of student achievement information /n"); 
 printf(" 6. Student information query /n"); 
 printf(" 7. Change of visitor password /n"); 
 printf(" 8. Restore deleted student information by mistake /n"); 
 printf(" 0. Exit the student information management system /n"); 
 printf("==========================================/n"); 
 printf(" Please select a 0-8:/n"); 
 while(1) 
 { 
 scanf("%d",&sn); 
 if(sn==7) 
 for(i=1;i<=len;i++) 
 { 
 strcpy(use[i].user,stud[i-1].num ); 
 strcpy(use[i].code,stud[i-1].num ); 
 } 
 if(sn>1&&sn<7||sn==8) 
 { 
 
 printf(" Please enter your username: "); 
 scanf("%s",use1); 
 printf(" Please enter your password: "); 
 while(1) 
 { 
  mima[j]=getch(); 
  if(mima[j]==13) 
  break; 
  putchar('*'); 
  j++; 
 } 
 mima[j]='/0'; 
 printf("/n"); 
 if(sn==6) 
  if(strcmp(use1,use[0].user)!=0) 
  { 
  for(i=0;i<=len;i++) 
  { 
  if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)==0) 
  { 
  if(i!=0) 
  { 
  printf("**************************************/n"); 
  printf("  You can only find information about yourself  /n"); 
  printf("***************************************/n"); 
  research1(use1); 
  break; 
  } 
  } 
  if(strcmp(use1,use[0].user)==0&&strcmp(use[0].code,mima)!=0) 
  { 
  printf("**************************************/n"); 
  printf("  Password mistake  /n"); 
  printf("***************************************/n"); 
  while(1) 
  { 
  m++; 
  if(m<3) 
  { 
   printf(" Enter again :/n"); 
   printf(" Please enter your username: "); 
   scanf("%s",use1); 
   printf(" Please enter your password: "); 
   j=0; 
   while(1) 
   { 
   mima[j]=getch(); 
   if(mima[j]==13) 
   break; 
   putchar('*'); 
   j++; 
   } 
   mima[j]='/0'; 
   if(strcmp(use1,use[0].user)==0&&strcmp(use[0].code,mima)!=0) 
   { 
   printf("**************************************/n"); 
   printf("  Password mistake  /n"); 
   printf("***************************************/n");  
   } 
  } 
  else 
  { 
   sn=0; 
   break; 
  } 
  } 
  sn=0; 
  break; 
  } 
  if(strcmp(use1,use[1].user)<0||strcmp(use1,use[len].user)>0) 
  { 
  printf("**************************************/n"); 
  printf(" 3 User name error  /n"); 
  printf("***************************************/n"); 
  sn=0; 
  break; 
  } 
  if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)!=0) 
  { 
  printf("**************************************/n"); 
  printf("  Password mistake  /n"); 
  printf("***************************************/n"); 
  while(1) 
  { 
  m++; 
  if(m<3) 
  { 
   if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)==0) 
   { 
   printf("**************************************/n"); 
   printf("  You do not have permission to operate  /n"); 
   printf("***************************************/n"); 
   sn=0; 
   break;   
   } 
   printf(" Enter again :/n"); 
   printf(" Please enter your username: "); 
   scanf("%s",use1); 
   printf(" Please enter your password: "); 
   j=0; 
   while(1) 
   { 
   mima[j]=getch(); 
   if(mima[j]==13) 
   break; 
   putchar('*'); 
   j++; 
   } 
   mima[j]='/0'; 
   printf("/n"); 
   if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)!=0) 
   { 
   printf("**************************************/n"); 
   printf("  Password mistake  /n"); 
   printf("***************************************/n"); 
 
   } 
   else 
   { 
   printf("**************************************/n"); 
   printf("  Welcome to the system  /n"); 
   printf("***************************************/n"); 
   research1(use1); 
   break; 
   } 
   } 
  else 
  { 
   sn=0; 
   break; 
  } 
  } 
  } 
  } 
  } 
  for(i=0;i<=len;i++) 
  { 
  if(sn==6) 
  if(strcmp(use1,use[0].user)!=0) 
  { 
  sn=0; 
  break; 
  } 
  if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)==0) 
  { 
  if(i!=0) 
  { 
   printf("**************************************/n"); 
   printf("  You do not have permission to operate  /n"); 
   printf("***************************************/n"); 
  sn=0; 
  break; 
  } 
  else 
  { 
   printf("**************************************/n"); 
   printf("  Welcome to the system  /n"); 
   printf("***************************************/n"); 
   break; 
  } 
  } 
  if(strcmp(use1,use[0].user)==0&&strcmp(use[0].code,mima)!=0) 
  { 
  printf("**************************************/n"); 
  printf("  Password mistake  /n"); 
  printf("***************************************/n"); 
 
  while(1) 
  { 
  m++; 
  if(m<3) 
  { 
   printf(" Enter again :/n"); 
   printf(" Please enter your username: "); 
   scanf("%s",use1); 
   printf(" Please enter your password: "); 
   j=0; 
   while(1) 
   { 
   mima[j]=getch(); 
   if(mima[j]==13) 
   break; 
   putchar('*'); 
   j++; 
   } 
   mima[j]='/0'; 
   printf("/n"); 
   if(strcmp(use1,use[0].user)==0&&strcmp(use[0].code,mima)!=0) 
   { 
   printf("**************************************/n"); 
   printf("  Password mistake  /n"); 
   printf("***************************************/n"); 
   } 
   else 
   { 
   printf("**************************************/n"); 
   printf("  Welcome to the system  /n"); 
   printf("***************************************/n"); 
   break; 
   } 
  } 
  else 
  { 
   sn=0; 
   break; 
  } 
  } 
  break; 
  } 
  if(strcmp(use1,use[1].user)<0||strcmp(use1,use[len].user)>0) 
  { 
  printf("**************************************/n"); 
  printf("  User name error  /n"); 
  printf("***************************************/n"); 
  sn=0; 
  break; 
  } 
  if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)!=0) 
  { 
  printf("**************************************/n"); 
  printf("  Password mistake  /n"); 
  printf("***************************************/n"); 
 
  while(1) 
  { 
  m++; 
  if(m<3) 
  { 
   if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)==0) 
   { 
   printf("**************************************/n"); 
   printf("  You do not have permission to operate  /n"); 
   printf("***************************************/n"); 
   sn=0; 
   break; 
 
   } 
   printf(" Enter again :/n"); 
   printf(" Please enter your username: "); 
   scanf("%s",use1); 
   printf(" Please enter your password: "); 
   j=0; 
   while(1) 
   { 
   mima[j]=getch(); 
   if(mima[j]==13) 
   break; 
   putchar('*'); 
   j++; 
   } 
   mima[j]='/0'; 
   printf("/n"); 
   if(strcmp(use1,use[i].user)==0&&strcmp(use[i].code,mima)!=0) 
   { 
   printf("**************************************/n"); 
   printf("  Password mistake  /n"); 
   printf("***************************************/n"); 
 
   } 
  } 
  else 
  { 
   sn=0; 
   break; 
  } 
  } 
 
  } 
  } 
 } 
 if (sn<0 || sn>8) 
 { 
 printf("/n/t Enter error, re - select 0-8/n"); 
 break; 
 } 
 else 
 break; 
 } 
 return sn; 
} 
 
///////////////////////////////////////////////////////////////////////////////// 
/*  The main function of student information management system -- The system function */ 
///////////////////////////////////////////////////////////////////////////////// 
void main() 
{ 
 struct student *head; 
 int i,j=0; 
 while(1) 
 { 
 switch(menu()) 
 { 
 case 1: 
 printf("**************************************/n"); 
 printf("  Student information for overall enrollment  /n"); 
 printf("***************************************/n"); 
 head=create(); 
 FILE *fp; 
 struct secret p; 
 fp=fopen("d://mima.txt","rb"); 
 if(fp==NULL) 
 printf("open error/n"); 
 else 
 { 
 for(i=0;i<=len;i++) 
 { 
  fread(&p,sizeof(struct secret),1,fp); 
  strcpy(use[i].user,p.user); 
  strcpy(use[i].code,p.code); 
 } 
 
 fclose(fp); 
 } 
 
 break; 
 
 case 2: 
 printf("**************************************/n"); 
 printf(" Student information modification /n"); 
 printf("**************************************/n"); 
 change(head); 
 break; 
 case 3: 
 printf("**************************************/n"); 
 printf(" The addition of student information /n"); 
 printf("**************************************/n"); 
 head=insert(head); 
 break; 
 case 4: 
 printf("**************************************/n"); 
 printf(" The deletion of student achievement information /n"); 
 printf("**************************************/n"); 
 head=del(head); 
 break; 
 case 5: 
 printf("**************************************/n"); 
 printf(" Input of student achievement information /n"); 
 printf("**************************************/n"); 
 head=chengji(head); 
 break; 
 case 6: 
 printf("**************************************/n"); 
 printf(" Student information query /n"); 
 printf("**************************************/n"); 
 research(head); 
 break; 
 case 7: 
 printf("**************************************/n"); 
 printf(" Change of visitor password /n"); 
 printf("**************************************/n"); 
 mimacli(); 
 break; 
 case 8: 
 printf("**************************************/n"); 
 printf(" Restore deleted information by mistake /n"); 
 printf("**************************************/n"); 
 recover(head); 
 break; 
 case 0: 
 printf("**************************************/n"); 
 printf(" Exit the student information management system /n"); 
 printf("**************************************/n"); 
 printf("The end./n"); 
 return; 
 default: printf("/n The wrong choice , Please re-election !/n"); 
 getchar(); 
 getchar(); 
 } 
 system("cls"); 
 } 
} 

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


Related articles: