根据各位指正后,更改的学生记录信息系统

根据各位提出的意见,我做了如下的改动,特此发表,忘各位继续为我指正!
 
 
 
/*下面我们用数组来实现增、删、改、查的函数功能,我写的输入不支持中文,目前没学*/
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define Max_storage 20  /*能够存储的最大学生记录数*/
#define Max_num 20      /*能够存储的最大学号位数*/
#define Max_name 15     /*能够存储的最大名字位数*/
#define Max_dep 32       /*同上*/
#define TURE 1           /*定义结果状态代码*/
#define FALSE 0
typedef int Status;       /*Status是函数类型,定义函数结果状态代码,返回如:OK*/
typedef struct student_type       /*用结构体来定义学生信息存储结构*/
{
    char num[Max_num];   /*学号*/
    char name[Max_name]; /* 姓名*/
    int age; /*年龄*/
    char dep[Max_dep]; /*系*/
}Stud;
int count=0;              /*定义一个计数器,用来记录存储学生信息的数目*/
void add(Stud *a)
{                  /*添加新纪录*/
    int i;
    printf("Please input added information:\n");
    printf("(add)Age:\n");
    scanf("%d",&a[count].age);
    printf("(add)Number:\n");
    scanf("%s",a[count].num);
    printf("(add)Name:\n");
    scanf("%s",a[count].name);
    printf("(add)Department:\n");
    scanf("%s",a[count].dep);
    /*输出学生信息*/
    printf("This is the %d student information:\n",count+1);
    printf("a[%d].age=",count);
    printf("%d\n",a[count].age);
    printf("a[%d].num[]=",count);
    printf("%s\n",a[count].num);
    printf("a[%d].name[]=",count);
    printf("%s\n",a[count].name);
    printf("a[%d].dep[]=",count);
    printf("%s\n",a[count].dep);
    count++;                /*学生记录数增加一个*/
}
void del(Stud *a)
{   /*以学号为关键字删除记录,a为需要进行删除的学生记录*/
    int i,j;
    int compare1;    /*通过输入学号跟存储学号比较,判断删除记录是否存在*/
    int count1;    /*计数器二,用于查找到该学号,在进行删除操作*/
    Stud del1;
    Status sentence=TURE;   /*判断删除操作是否成功!TURE or FALSE*/
    printf("(delete)Please input the number you want to delete:\n");
    scanf("%s",del1.num);
    for(count1=0;count1<count;count1++)
    {
     compare1=strcmp(a[count1].num,del1.num);
     if(compare1==0)       /*如果完全匹配*/
         {
           memset(a[count1].num,'\0',strlen(a[count1].num));             /*先清空,避免字符串长度不同问题*/
           strcpy(a[count1].num,a[count1+1].num);
           memset(a[count1].name,'\0',strlen(a[count1].name));
           strcpy(a[count1].name,a[count1+1].name);
           memset(a[count1].dep,'\0',strlen(a[count1].dep));
           strcpy(a[count1].dep,a[count1+1].dep);
           a[count1].age=a[count1+1].age;
           count--;           /*学生记录数少一个*/
           printf("Delete Succeed!\n");
           sentence=TURE;
         }
         else
           sentence=FALSE;
     }
  if(sentence==FALSE)
     printf("Delete Failed!\n");
}
void update(Stud *a){   /*以学号为关键字修改记录信息*/
    int i,menu1;
    int compare;
    int count2;            /*计数器2,用来查找修改学生信息是否存在*/
    Stud modify;
    printf("(update)Please input the number you want to modify:\n");
    scanf("%s",modify.num);
    for(count2=0;count2<=count;count2++)   /*在数组逐一查询*/
    {
      compare=strcmp(a[count2].num,modify.num);
         if(compare==0)       /*如果完全匹配,即需要修改的学生信息存在*/
         {
             while(1){                             /*用while结构实现子菜单选择功能*/
             printf("1. Modify the name.\n");
             printf("2. Modify the age.\n");
             printf("3. Modify the department.\n");
             printf("4. Quit the Modify.\n");        /*退出修改*/
             printf("Please input the your choose:");
             scanf("%d",&menu1);
             switch(menu1)
            {
             case 1:
               printf("Please input the name:");
               scanf("%s",modify.name);
               if(strlen(a[count2].name)<=strlen(modify.name)){
                     strcpy(a[count2].name,modify.name);
                }
               else{            /*清楚掉a[count2].name里多余的元素*/
                   strcpy(a[count2].name,modify.name);
                   for(i=strlen(a[count2].name);i<strlen(a[count2].name)-strlen(modify.name);i--)
                     a[count2].name[i]='\0';
                   }
               break;
             case 2:
               printf("Please input the age:");
               scanf("%d",&modify.age);
               a[count2].age=modify.age;
                break;
             case 3:
               printf("Please input the department:");
               scanf("%s",modify.dep);
               if(strlen(a[count2].dep)<=strlen(modify.dep)){
                  strcpy(a[count2].dep,modify.dep);
                   }
               else{
                  for(i=strlen(a[count2].dep);i<strlen(a[count2].dep)-strlen(modify.dep);i--)
                    a[count2].dep[i]='\0';
                 }
               break;
             case 4:
               goto in;  /*跳转到下面的输出信息语句,in为行号*/
             }
           printf("\n");
         }
      }
  }
   /*goto的跳转语句在这里*/
    in:printf("This is the %d student information after you modified::\n",count2+1);
    printf("a[%d].age=",count2);
    printf("%d",a[count2].age);
    printf("a[%d].num[]=",count2);
    printf("%s",a[count2].num);
    printf("a[%d].name[]=",count2);
    printf("%s",a[count2].name);
    printf("a[%d].dep[]=",count2);
    printf("%s",a[count2].dep);
}
Status query(Stud *a){                  /*以学号或姓名为查询字段进行查询,*a为指向存储学生记录的数组的指针*/
    Stud find;
    int i,j,count3;                       /*计数器3*/
    int compare;
    Status sentence=TURE;
    printf("(query)Please input the number you want to find:\n");
    scanf("%s",find.num);
    for(count3=0;count3<count;count3++)   /*在数组逐一查询*/
    {
      compare=strcmp(a[count3].num,find.num);
      if(compare==0)       /*如果完全匹配,则输出查询结果*/
         {
          printf("This is the result you find out:\n");    /*输出查找结果*/
          printf("a[%d].num[]=",count3);          /*输出所查找信息的学号*/
          printf("%s\n",a[count3].num);
          printf("a[%d].name[]=",count3);         /*输出所查找信息的姓名*/
          printf("%s\n",a[count3].name);
          printf("a[%d].age=",count3);   /*输出所查找信息的年龄*/
          printf("%d\n",a[count3].age);
          printf("a[%d].dep=",count);                 /*输出所查找信息的系别*/
          printf("%s\n",a[count3].dep);
          sentence=TURE;
          printf("Find Succeed!\n");                       /*查找成功*/
         }
         else
           sentence=FALSE;
      }
     if(sentence==FALSE)
        printf("Find Failed!\n");                    /*没有查询内容*/
}
void main()
{
    int menu;
    Stud STU[Max_storage];              /*用来存储学生记录的数组*/
    int i;
    while(1)
    {                        /*用while结构定义主菜单结构,供用户选择操作*/
        printf("------The Simple Student Information Management System v1.0------\n");
        printf("1. Add the student information in STU.\n");
        printf("2. Delete the student information in STU.\n");
        printf("3. Modify the student information in STU.\n");
        printf("4. Find the student information in STU.\n");
        printf("5. Quit the system.\n");
        printf("Please input your selection:");
        scanf("%d", &menu);
        if(menu==1||menu==2||menu==3||menu==4||menu==5)
        {
           printf("**We begin to operate now!\n");
         switch(menu)
        {
            case 1:
                  add(STU);
                  break;
            case 2:
                  del(STU);
                  break;
            case 3:
                  update(STU);
                  break;
            case 4:
                  query(STU);
                  break;
            case 5:
                  exit(1);
                  break;
         }
       }
       else
         printf("Sorry! Your input does not match,again please!\n");
    }
   getch();
}
 

 

你可能感兴趣的:(职场,休闲)