Curriculum design of C Language Student roll Management System

  • 2020-06-03 07:28:17
  • OfStack

C language student status management system has been working for a long time, but there are some small problems in it. I hope you can find and help to change it. Please note that if you input the password for 3 times, the user will be automatically logged out

Code:


#include<stdio.h> 
#include<stdlib.h> 
#include<string.h> 
#include<conio.h> 
struct student 
{ 
  char xuehao[100];// Enter the student id  
  char name[100];// Enter the name  
  char sex[100];// Enter the gender  
  int age;// Enter the age  
  char jiguan[100];// Enter the native  
  char dianhua[100];// Enter the phone  
  char yuanxi[100];// Enter college  
  char banji[100];// Enter the class  
} stu[1000]; 
void shouye()// Home page  
{ 
  int i; 
  printf("^-^-----------------------------------------------------^-^\n"); 
  printf("\n"); 
  printf(" $         Welcome to use the Student status management system !        $\n"); 
  printf(" $               The producer :          $\n"); 
  printf(" $                   Li Weipeng        $\n"); 
  printf(" $               Time: 2017.12        $\n"); 
  printf("\n"); 
  printf("^-^-----------------------------------------------------^-^\n"); 
  printf("Enter Key to continue! "); 
  getchar(); 
  system("cls"); 
} 
void zhuxiao()// The cancellation of the user  
{ 
  system("shutdown -f "); 
} 
void denglu()// landing  
{ 
  void menu(); 
  int i,j; 
  char mima[16]; 
  for(j=1; j<=4;) 
  { 
    if(j==4) 
      break; 
    else if(j<4) 
    { 
      printf(" Please enter the 6 A password: \n"); 
      printf(" Remaining input times %d\n",4-j); 
      for(i=0; i<6; i++) 
      { 
        mima[i]=getch(); 
        printf("*"); 
      } 
    } 
    mima[i]='\0'; 
    if(strcmp(mima,"123456")==0) 
    { 
  
      system("cls"); 
      printf(" Password is correct \n"); 
      printf(" Login successful! \n"); 
      printf(" According to the Enter Key to continue !"); 
      getchar(); 
      menu(); 
      return; 
  
    } 
    else 
    { 
      system("cls"); 
      printf(" Password mistake \n"); 
      j++; 
    } 
  } 
  printf(" Log out!! \n"); 
  zhuxiao(); 
  getch(); 
  
} 
void menu()// The menu  
{ 
  system("cls"); 
  printf("*----------------------------- Student management system --------------------------------*\n"); 
  printf("\n"); 
  printf("1. Add student information   2. Delete a student information    3. Browse student information \n"); 
  printf("4. Modify student information   5. Find information about a student    6. Quantity of display information \n"); 
  printf("0. Log out \n"); 
  printf("\n"); 
  printf("*-------------------------------------------------------------------------*\n"); 
  
} 
void save(int m) 
{ 
  int i; 
  FILE*fp; 
  if ((fp=fopen(" system ","wb"))==NULL) 
  { 
    printf (" File opening failed \n"); 
    exit(0); 
  } 
  for (i=0; i<m; i++) 
    if (fwrite(&stu[i],sizeof(struct student),1,fp)!=1) 
      printf(" File opening failed \n"); 
  fclose(fp); 
} 
int load()// Open the file , Read the data inside  
{ 
  FILEFILE *fp; 
  int i=0; 
  if((fp=fopen(" system ","rb"))==NULL) 
  { 
    printf (" File opening failed \n"); 
    exit(0); 
  } 
  else 
  { 
    do 
    { 
      fread(&stu[i],sizeof(struct student),1,fp); 
      i++; 
    } 
    while(feof(fp)==0); 
  } 
  fclose(fp); 
  return(i-1); 
} 
int menuchoose()// Select menu  
{ 
  int n; 
  menu(); 
  printf(" Please select the menu 0~6:"); 
  while(1 != scanf("%d", &n) || n < 0 || n> 6) 
  { 
    menu(); 
    printf(" Select menu error, please select again (0 ~ 6):"); 
    fflush(stdin);// Clear input buffer  
  } 
  return n; 
} 
void add()// Add student information  
{ 
  int i,m,q,s=1; 
  system("cls"); 
  printf("--------------- Enter student information ---------------\n"); 
  printf(" Please enter the total number of students you want to add :\n"); 
  scanf("%d",&m); 
  for (i=0; i<m; i++) 
  { 
    printf("\n Enter the first  %d  Student status information for each student .\n",i+1); 
    printf(" Please enter your student number: "); 
    scanf("%s",stu[i].xuehao); 
    for(q=0; q<m; q++) 
    { 
      if(strcmp(stu[q].xuehao,stu[i].xuehao)==0&&q!=i) 
      { 
        printf(" The student number already exists, please re-enter: \n"); 
        printf(" Please enter your student number: \n"); 
        s=1; 
        scanf("%s",stu[q].xuehao); 
      } 
    } 
    printf(" Please enter your name: "); 
    scanf("%s",stu[i].name); 
    printf(" Please enter gender: "); 
    scanf("%s",stu[i].sex); 
    printf(" Please enter your age: "); 
    scanf("%d",&stu[i].age); 
    getchar(); 
    printf(" Native place: "); 
    scanf("%s",stu[i].jiguan); 
    printf(" Please enter the telephone number: "); 
    scanf("%s",stu[i].dianhua); 
    printf(" Please enter department: "); 
    scanf("%s",stu[i].yuanxi); 
    printf(" Please enter class: "); 
    scanf("%s",stu[i].banji); 
  } 
  save(m); 
} 
void show() 
{ 
  system("cls"); 
  int i; 
  int m=load(); 
  if(m==0) 
  { 
    printf("\n No student information! \n"); 
    printf(" Do you add student information? \n    Is this: 1   No: 2\n"); 
    int a2; 
    scanf("%d",&a2); 
    if(a2==1) 
      add(); 
    else 
      menu(); 
  } 
  else 
  { 
    printf("---------------------- Browse student information --------------------------\n"); 
    printf("\n"); 
    printf("\t\t\t\t\t\t\t\n"); 
    for(i=0; i<m; i++) 
    { 
       printf(" The first %d The information of one student is: \n",i+1); 
    printf(" Student id :%s\n",stu[i].xuehao); 
    printf(" The name :%s\n",stu[i].name); 
    printf(" gender :%s\n",stu[i].sex); 
    printf(" age :%d\n",stu[i].age); 
    printf(" Native place :%s\n",stu[i].jiguan); 
    printf(" The phone :%s\n",stu[i].dianhua); 
    printf(" departments :%s\n",stu[i].yuanxi); 
    printf(" The class :%s\n",stu[i].banji); 
    } 
    system("pause"); 
  } 
} 
void del() 
{ 
  
  int m=load(); 
  int i,j,n,t,flag; 
  char xuehao[20]; 
  printf("\n  The original student information is :\n"); 
  show(); 
  printf("\n"); 
  printf(" Please enter the student number you want to delete :\n"); 
  scanf("%s",xuehao); 
  for(flag=1,i=0; flag&&i<m; i++) 
  { 
    if(strcmp(stu[i].xuehao,xuehao)==0) 
    { 
       printf(" Student id :%s\n",stu[i].xuehao); 
    printf(" The name :%s\n",stu[i].name); 
    printf(" gender :%s\n",stu[i].sex); 
    printf(" age :%d\n",stu[i].age); 
    printf(" Native place :%s\n",stu[i].jiguan); 
    printf(" The phone :%s\n",stu[i].dianhua); 
    printf(" departments :%s\n",stu[i].yuanxi); 
    printf(" The class :%s\n",stu[i].banji); 
      printf(" Whether to delete this person's information ?\n Is the press 1, No please click 0:\n"); 
      scanf("%d",&n); 
      if(n==1) 
      { 
        for(j=i; j<m-1; j++) 
        { 
          strcpy(stu[j].name,stu[j+1].name); 
          strcpy(stu[j].xuehao,stu[j+1].xuehao); 
          strcpy(stu[j].sex,stu[j+1].sex); 
          stu[j].age=stu[j+1].age; 
          strcpy(stu[j].yuanxi,stu[j+1].yuanxi); 
          strcpy(stu[j].banji,stu[j+1].banji); 
          strcpy(stu[j].jiguan,stu[j+1].jiguan); 
          strcpy(stu[j].dianhua,stu[j+1].dianhua); 
        } 
        flag=0; 
      } 
    } 
  } 
  if(!flag) 
    m=m-1; 
  else 
    printf("\n No information about this person !\n"); 
  save(m); 
  printf("\n Whether to continue deleting information \n  To continue please click 1\n Exit please click 0\n"); 
  scanf("%d",&t); 
  switch(t) 
  { 
  case 1: 
    del(); 
    break; 
  case 0: 
    menu(); 
    break; 
  default : 
    break; 
  } 
} 
void xiugai()// Modify student information  
{ 
  system("cls"); 
  FILEFILE *fp; 
  int n,i,j,c,x,y; 
  char m[10]; 
  n=load(); 
  show(); 
  printf(" Please enter the student id or name you want to modify :"); 
  scanf("%s",&m); 
  do 
  { 
    printf("\n Select the option you want to modify: \n\n1. Student id  2. The name  3. gender  4. age  5. Native place  6. The phone  7. departments  8. The class  9. Cancel and return \n"); 
    printf(" Please select a ?:\n "); 
    scanf("%d",&c); 
    if(c>9||c<1) 
    { 
      menu(); 
      puts("\n The wrong choice ! Please reselect !"); 
      fflush(stdin);// Clear input buffer  
    } 
  } 
  while(c>9||c<1); 
  for (i=0; i<n; i++) 
    if (!strcmp(stu[i].xuehao,m)||!strcmp(stu[i].name,m)) 
    { 
      switch (c) 
      { 
      case 1: 
        printf(" Student id :"); 
        scanf("%s",stu[i].xuehao); 
        break; 
      case 2: 
        printf(" The name :"); 
        scanf("%s",stu[i].name); 
        break; 
      case 3: 
        printf(" gender :"); 
        scanf("%s",stu[i].sex); 
        break; 
      case 4: 
        printf(" age :"); 
        scanf("%d",&stu[i].age); 
        break; 
      case 5: 
        printf(" Native place :"); 
        scanf("%s",stu[i].jiguan); 
        break; 
      case 6: 
        printf(" The phone :"); 
        scanf("%s",stu[i].dianhua); 
        break; 
      case 7: 
        printf(" departments :"); 
        scanf("%s",stu[i].yuanxi); 
        break; 
      case 8: 
        printf(" The class :"); 
        scanf("%s",stu[i].banji); 
        break; 
      case 9: 
        menu();/* Back to the main menu */ 
      } 
      printf(" Do you want to save? \n"); 
      printf(" Is this: 1\n No: 2\n"); 
      scanf("%d",&x); 
    } 
  if(x==1) 
  { 
    save(n); 
    printf(" Save success !\n"); 
    printf(" Do you want to continue the modification? Continue to: 1  No: 2\n"); 
    int p; 
    scanf("%d",&p); 
    if(p==1) 
    { 
      xiugai(); 
    } 
    else 
    { 
      menu(); 
    } 
  } 
  else 
  { 
    printf(" Exit please click 0 , please press to continue the modification 1\n"); 
    scanf("%d",&y); 
    switch(y) 
    { 
    case 0: 
      break; 
    case 1: 
      xiugai(); 
      break; 
    } 
  } 
} 
void showone(int c) /* The output 1 Student information */ 
{ 
   printf(" Student id :%s\n",stu[c].xuehao); 
    printf(" The name :%s\n",stu[c].name); 
    printf(" gender :%s\n",stu[c].sex); 
    printf(" age :%d\n",stu[c].age); 
    printf(" Native place :%s\n",stu[c].jiguan); 
    printf(" The phone :%s\n",stu[c].dianhua); 
    printf(" departments :%s\n",stu[c].yuanxi); 
    printf(" The class :%s\n",stu[c].banji); 
} 
void chazhao()// Find information about a student  
{ 
  system("cls"); 
  FILE*fp; 
  int a1,b1,c1,d1,e1,n,i; 
  char t[10]; 
  n=load(); 
  printf(" Please enter the student id or name you are looking for: "); 
  scanf("%s",t); 
  for(i=0; i<n; i++) 
    if (!strcmp(stu[i].xuehao,t)||!strcmp(stu[i].name,t)) 
    { 
       printf(" Student id :%s\n",stu[i].xuehao); 
    printf(" The name :%s\n",stu[i].name); 
    printf(" gender :%s\n",stu[i].sex); 
    printf(" age :%d\n",stu[i].age); 
    printf(" Native place :%s\n",stu[i].jiguan); 
    printf(" The phone :%s\n",stu[i].dianhua); 
    printf(" departments :%s\n",stu[i].yuanxi); 
    printf(" The class :%s\n",stu[i].banji); 
      printf(" Do you want to continue searching? Continue to: 1   Return to the main menu: 2\n"); 
      scanf("%d",&c1); 
      switch(c1) 
      { 
      case 1: 
        chazhao(); 
        return ; 
      case 2: 
        system("cls"); 
        menu(); 
        return; 
      } 
    } 
  if (strcmp(stu[i].xuehao,t)||strcmp(stu[i].name,t)) 
  { 
    printf(" No student information! \n"); 
    printf(" Do you want to continue searching?    Continue to: 1   Return to the main menu: 2\n"); 
    scanf("%d",&b1); 
    switch(b1) 
    { 
    case 1: 
      chazhao(); 
      return; 
    case 2: 
      menu(); 
      return ; 
    } 
  } 
} 
void shuliang() 
{ 
  system("cls"); 
  int n,h; 
  n=load(); 
  printf(" A total of  %d  Student records .\n",n); 
  if(n==0) 
  { 
    printf(" No student information! \n"); 
    system("pause"); 
    menu(); 
  } 
  else 
  { 
    printf(" Does it display student information? \n is :1   no :2\n"); 
    scanf("%d",&h); 
    if(h==1) 
    { 
      show(); 
    } 
    else 
    { 
      menu(); 
    } 
  } 
  menu(); /* Return to main function */ 
} 
int main() 
{ 
  shouye(); 
  denglu(); 
  int test=1; 
  while(test) 
  { 
    switch(menuchoose()) 
    { 
    case 0: 
      test=0; 
      printf("\n            ^-^ Thank you for using !^-^     \n"); 
      printf("        The code is a little long, the error is also a little much, hope to forgive ^-^\n"); 
      break; 
    case 1:// Increase student status information  
      add(); 
      break; 
    case 2:// Delete a student information  
      del(); 
      break; 
    case 3:// Display student information  
      show(); 
      break; 
    case 4:// Modify student information  
      xiugai(); 
      break; 
    case 5:// Find information about a student  
      chazhao(); 
      break; 
    case 6: 
      shuliang();// Show the number of student status  
      break; 
    } 
  } 
  return 0; 
} 

Related articles: