⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 info.c

📁 学生信息管理系统。C入门课设内容
💻 C
字号:

#define LEN sizeof(INFO)

/* FUNCITON 001 */
/* This function is designed to INPUT ONE student's information. */
void input_1_info(INFO *p)
{
 char confirm,gen_temp,sort_temp;

 do
  {
    printf("\nPlease enter the entrance year:\n");
    scanf("%d",&(*p).year);
    while((*p).year>2008||(*p).year<2000)
     {printf("Error! Year out of range.\n");
      printf("\nPlease enter the year:\n");
      scanf("%d",&(*p).year);}
    (*p).number[0]='0';
    switch((*p).year)
       {case 2000:(*p).number[1]='0';break;
        case 2001:(*p).number[1]='1';break;
        case 2002:(*p).number[1]='2';break;
        case 2003:(*p).number[1]='3';break;
        case 2004:(*p).number[1]='4';break;
        case 2005:(*p).number[1]='5';break;
        case 2006:(*p).number[1]='6';break;
        case 2007:(*p).number[1]='7';break;
        case 2008:(*p).number[1]='8';break;}
   
    printf("\nPlease enter the school (a 1-bit code):\n");
    scanf("%d",&(*p).school);
    while(((*p).school!=1)&&((*p).school!=2)&&((*p).school!=6)&&((*p).school!=7))
     {printf("Error! School out of range.\n");
      printf("\nPlease enter the school:\n");
      scanf("%d",&(*p).school);}
    (*p).number[2]='0';
    switch((*p).school)
       {case 1:(*p).number[3]='1';break;
        case 2:(*p).number[3]='2';break;
        case 3:(*p).number[3]='3';break;
        case 4:(*p).number[3]='4';break;
        case 5:(*p).number[3]='5';break;
        case 6:(*p).number[3]='6';break;
        case 7:(*p).number[3]='7';break;
        case 8:(*p).number[3]='8';break;
        case 9:(*p).number[3]='9';break; }
    
    printf("\nPlease enter the major (a 1-bit code):\n");
    scanf("%d",&(*p).major);
    while((*p).major>7||(*p).major<0)
     {printf("Error! Major out of range.\n");
      printf("\nPlease enter the major:\n");
      scanf("%d",&(*p).major) ;}
    switch((*p).major)
       {case 0:(*p).number[4]='0';break;
        case 1:(*p).number[4]='1';break;
        case 2:(*p).number[4]='2';break;
        case 3:(*p).number[4]='3';break;
        case 4:(*p).number[4]='4';break;
        case 5:(*p).number[4]='5';break;
        case 6:(*p).number[4]='6';break;
        case 7:(*p).number[4]='7';break; }
  
    printf("\nPlease enter the class (a one-bit code):\n");
    scanf("%d",&(*p).classes);
    while((*p).classes>9||(*p).classes<0)
     {printf("Error! Class out of range.\n");
      printf("\nPlease enter the class:\n");
      scanf("%d",&(*p).classes);   }
    switch((*p).classes)
       {case 0:(*p).number[5]='0';break;
        case 1:(*p).number[5]='1';break;
        case 2:(*p).number[5]='2';break;
        case 3:(*p).number[5]='3';break;
        case 4:(*p).number[5]='4';break;
        case 5:(*p).number[5]='5';break;
        case 6:(*p).number[5]='6';break;
        case 7:(*p).number[5]='7';break;
        case 8:(*p).number[5]='8';break;
        case 9:(*p).number[5]='9';break; }
  
    printf("\nPlease enter the serial number\n(The last 2-bit code of student number):");
    scanf("%s",&(*p).num);
    (*p).number[6]=(*p).num[0];
    (*p).number[7]=(*p).num[1];
    (*p).number[8]='\0';

   printf("\nPlease enter the name (less than 20 characters):\n");
   scanf("%s",(*p).name);

   do
   {
       printf("\nPlease enter the gender of the student\n('M' for male, 'F' for female):\n");
       scanf("%*c%c",&gen_temp);  /*  "%*c" means to receive a CARRIAGE RETURN character, but not valuing to any variable. */
       if (gen_temp=='M'||gen_temp=='m') (*p).gender='M';
            else if (gen_temp=='F'||gen_temp=='f') (*p).gender='F';
                else printf("Error!  Gender must be 'M' or 'F'\n");
    }while(gen_temp!='f'&&gen_temp!='F'&&gen_temp!='m'&&gen_temp!='M');

   do
   {
       printf("\nPlease enter the sort of the student\n('U' for undergraduates, 'S' for graduates):\n");
       scanf("%*c%c",&sort_temp);
       if (sort_temp=='U'||sort_temp=='u') (*p).sort='U';
            else if (sort_temp=='S'||sort_temp=='s') (*p).sort='S';
                else printf("Error!  Sort must be 'S' or 'U'\n");
    }while(sort_temp!='u'&&sort_temp!='U'&&sort_temp!='s'&&sort_temp!='S');

   printf("\nPlease confirm the information you entered:\n");
   printf("Student Number:\t%s\nSchool:\t%d\nMajor:\t%d\nClass:\t%d\nName:\t%s\nGender:\t%c\nSort:\t%c\n",
          (*p).number,(*p).school,(*p).major,(*p).classes,(*p).name,(*p).gender,(*p).sort);

   printf("Do you confirm?(y/n):");
   scanf("%*c%c",&confirm);
   }while((confirm!='y')&&(confirm!='Y'));
 }


/* FUNCTION 002 */
/* This function is designed to print out a student's information on the screen. */
void print_1_info(INFO *p)
{
 char MJR[9];
 char SCH[9];
 
 switch((*p).school)
  {case 1:strcpy(SCH,"Jidian");break;
   case 2:strcpy(SCH,"Diankong");break;
   case 6:strcpy(SCH,"Shuli");break;
   case 7:strcpy(SCH,"Jisuanji");break;}
 
 switch((*p).major)
  {case 0:strcpy(MJR,"Zidonghua");break;
   case 1:strcpy(MJR,"Dianxin");break;
   case 2:strcpy(MJR,"Shuxue");break;
   case 3:strcpy(MJR,"Weidianzi");break;
   case 4:strcpy(MJR,"Tongxin");break; 
   case 5:strcpy(MJR,"Jixie");break;
   case 6:strcpy(MJR,"Wuli");break; 
   case 7:strcpy(MJR,"Jisuanji");break; }

 printf("%-10s%-22s%c\t%-10s%-11s%c\n",
    (*p).number,(*p).name,(*p).gender,SCH,MJR,(*p).sort);
 }


/* FUNCTION 003 */
/* This function is designed to print out a table head which is on top of a list showing students' information. */
/* Last edited at 2006-4-30 23:06 */
void print_head(void)
{
 printf("\nNUMBER    NAME                  GENDER  SCHOOL    MAJOR      SORT\n");
}


/* FUNCTION 005 */
/* print out an active link */
void print_all_info(INFO *head_print, int n)
{
  
  INFO *p_out;
  p_out=head_print;
  if(head_print!=NULL)
    {print_head();
     do
       {print_1_info(p_out);
        p_out=p_out->next;
        }while(p_out!=NULL);
     }
  printf("\nThere are altogether %d students in the list\n",n);
  getch();
}


/*  FUNCTION 006 */
/* To delete a record from a chain */
void del(INFO *head_del)
{
    extern n;
    char num_del[9];
    INFO *p1, *p2;
    if(head_del==NULL)
        {printf("\nError!  List null!\n");
     	 getch();
         return; }
    printf("Please enter the number of the student you want to delete:");
    scanf("%s",num_del);
    p1=head_del;
    while((strcmp(num_del,p1->number)!=0)&&(p1->next!=NULL))
        {p2=p1; p1=p1->next;}
    if(strcmp(num_del,p1->number)==0)
        {if(p1==head_del) head_del=p1->next;
         else p2->next=p1->next;
         printf("%s:  Successfully deleted.\n",p1->number);
         n-=1;
        }
      else printf("%s:  Error! Record cannot be found.\n",num_del);
      getch();
 }


/* FUNCTION 007 */
/* To create a list */
void create(INFO *head_create)
{
    extern n;
    INFO *p_new,*p_temp;
    char neu='y';
    p_new=p_temp=head_create;
    n=0;
    input_1_info(p_new);
    n++;
    printf("\n%s:  New record added successfully!\n",p_new->number);
    while(neu=='y'||neu=='Y')
    {
        p_temp->next=p_new;
        p_temp=p_new;
        printf("\nDo you want to input more students' information?(y/n):");
        scanf("%*c%c",&neu);
        
        if(neu!='Y'&&neu!='y'){printf("\nPress any key to back to main menu...\n");getch();break;}
        p_new=(INFO *)malloc(LEN);
        n++;
        clrscr();
        input_1_info(p_new);
        printf("\n%s:  New record added successfully!\n",p_new->number);
     }
    p_temp->next=NULL;
}


/* FUNCTION 008 */
/* This function is designed to add a new info record to the end of current list. */
void add(INFO *head_add)
{
    extern n;
    INFO *p1, *p2;
    if(head_add==NULL)
        {printf("\nError! List null!\n");
         getch();
         return;
         }
    p1=head_add;
    while(p1->next!=NULL)
        {p1=p1->next;}
    p2=p1->next=(INFO *)malloc(LEN);
    input_1_info(p2);
    p2->next=NULL;
    n+=1;
    printf("\n%s:  New record added successfully!\n",p2->number);
    printf("\nPress any key to back to main menu...\n");
    getch();
    /* return(head_add); */
 }


/* FUNCTION 009 */
void modify(INFO *head_modi)
{
    INFO *p_temp;
    char num_modi[9];
    printf("Please enter the number of the student you want to modify:");
    scanf("%s",num_modi);

    if(head_modi==NULL)  
    { printf("\nError!  List null!\n");getch();}
    p_temp=head_modi;
    while((strcmp(num_modi,p_temp->number)!=0)&&(p_temp->next!=NULL))
        {p_temp=p_temp->next;}
    if(strcmp(num_modi,p_temp->number)==0)
        {input_1_info(p_temp);
         printf("%s:  Successfully modified.\n",p_temp->number);  }
      else printf("%s:  Error! Record cannot be found.\n",num_modi);
    getch();
 }


/* Function 015 */
/* A small hint. */
void back_print(void)
{
 printf("\nPress any key back to previous menu...\n");
 getch();
}


/* Function 025 */
/* "About", basic information of the program. */
void about(void)
{
    printf("\n\t    ====== About the Program ======\n");
    printf("\n\tStudent Information Management Sysytem is only a small program\n\taiming to practise C programming.\n");
    printf("\tDesigned with Borland Win-TC (with Turbo C 2.0 Core).\n");
    printf("\n\tCopyright (c) by LI Lei (04062201) June 2006\n");
    printf("\tAll Rights Reserved.\n");
    printf("\n\t    ====== Thanks To ======\n");
    printf("\n\tWANG Zhixin\n\t\tMy teacher of C Languange.\n\t\tShe taught me basic applications of C Language.\n");
    printf("\n\tWANG Fan\n\tMA Ran\n\tLI Tong\n\t\tMy fellow classmates, they all helped me during programming.\n");
    printf("\n\tFor more information, please contact the author by email:\n");
    printf("\tlee982318@sina.com\n");
    printf("\tThank you for using my program!\n");
    printf("\nPress any key back to main menu...");
    getch();
}


/* Function 026 */
/* Sub-menu of creating a new list. */
void menu_create(void)
{
    char choice_create;
    extern INFO *data_head;

    clrscr();
    printf("\n\t  ====== Create a New List ======\n");
    printf("\n  In SIMS, you have two methods to create a new record list:\n");
    printf("\n\t 1. Enter information by yourself");
    printf("\n\t 2. Load existing files automatically\n");
    printf("\n\t X. Quit to previous menu\n");
    printf("\n Please choose one item:");
    scanf("%*c%c",&choice_create);
    switch(choice_create)
     {
        case '1': clrscr();create(data_head);break;
        case '2': clrscr();f_load_2(data_head);break;
        case 'x':
        case 'X': clrscr();break;
     }
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -