| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1817 人关注过本帖
标题:求助 编译有问题 哪位大神教教我怎么改!!
只看楼主 加入收藏
bateshi996
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2019-12-20
收藏
 问题点数:0 回复次数:4 
求助 编译有问题 哪位大神教教我怎么改!!
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MaxSize 100
typedef struct
{   char num[30];          //考号
    char name[30];         //名字
    char sex[30];         //性别
    char exam[30];          //考试类别
    char jg[30];             //籍贯
    char age[30];        //年龄
}ElemType;




typedef struct
{
    ElemType data[MaxSize],data1[MaxSize],mac[MaxSize],hy[MaxSize];
       int length;//记录一门考试有多少人
    int length2; //记录一个考生报考的门数
    int number;   //记录考试种类
} SqList;




void ListAdd(SqList *&L)                               //添加考生信息
{   int a=0,b=0,c=0,y=0;
    printf("请输入考生信息!\n");
    printf("考号     姓名    性别    年龄     考试类别    籍贯\n");
    scanf("%s %s %s %s %s %s",L->data[L->length].num,L->data[L->length].name,L->data[L->length].sex,L->data[L->length].age,L->data[L->length].exam,L->data[L->length].jg);
    printf("\n");
    for(int i=0;i<L->length;i++)
    {
        if(strcmp(L->data[i].num,L->data[L->length].num)==0)
        {
            
            for(int j=0;j<L->length2;j++)
            {
                if(strcmp(L->mac[j].exam,L->data[L->length].exam)==0)
                {
                    a=1;b=1;break;
                }
            }
            if(b==0)
            {strcpy(L->mac[L->length2].num,L->data[L->length].num);   
            strcpy(L->mac[L->length2].jg,L->data[L->length].jg);
            strcpy(L->mac[L->length2].name,L->data[L->length].name);
            strcpy(L->mac[L->length2].sex,L->data[L->length].sex);
            strcpy(L->mac[L->length2].age,L->data[L->length].age);
            strcpy(L->mac[L->length2].exam,L->data[L->length].exam);                    
            printf("报名考试成功!\n");
            c=1;
            while(y<L->length2&&strcmp(L->mac[y].exam,L->data[L->length].exam)!=0)
            {
                y++;
            }
            if(y>=L->length2)
            {
               
                strcpy(L->hy[L->number].exam,L->data[L->length].exam);
                    L->number++;
            }
            L->length2++;
            }
        }
    }
    if(a==1)
    {
        printf("你已经报名了这门考试。\n");
    }
    if(a==0&&c==0)
    {
        strcpy(L->mac[L->length2].num,L->data[L->length].num);   
        strcpy(L->mac[L->length2].jg,L->data[L->length].jg);
        strcpy(L->mac[L->length2].name,L->data[L->length].name);
        strcpy(L->mac[L->length2].sex,L->data[L->length].sex);
        strcpy(L->mac[L->length2].age,L->data[L->length].age);
        strcpy(L->mac[L->length2].exam,L->data[L->length].exam);
        y=0;
        while(y<L->length2&&strcmp(L->mac[y].exam,L->data[L->length].exam)!=0)
        {
                y++;
        }
        if(y>=L->length2)
        {
            strcpy(L->hy[L->number].exam,L->data[L->length].exam);
            L->number++;
        }   
        L->length2++;
        L->length++;
        printf("报名考试成功!\n");
   
    }
}





void ListChange(SqList *&L)                                      //修改考生信息
{
     printf("请输入你要修改考生的考号:\n");
     char num[11];
     scanf("%s",&num);
     printf("你要修改的考生信息如下:\n");
     int i=0;
     while(i<L->length&&strcmp(L->data[i].num,num)!=0)
        i++;
     if(i>=L->length)
         printf("表内没有此考生!\n");
     else
     {
          printf("考号:%s\n",L->data[i].num);
          printf("姓名:%s\n",L->data[i].name);
          printf("性别:%s\n",L->data[i].sex);
          printf("年龄:%s\n",L->data[i].age);
          printf("籍贯:%s\n",L->data[i].jg);
          printf("参加的考试有:");
          for(int j=0;j<L->length2;j++)
          {
              if(strcmp(L->mac[j].num,L->data[i].num)==0)
              {
                  printf("%s,",L->mac[j].exam);
              }
          }
          printf("\n");
          printf("请输入考生信息!\n");
          printf("考号     姓名    性别    年龄     籍贯\n");
          scanf("%s %s %s %s  %s",L->data[i].num,L->data[i].name,L->data[i].sex,L->data[i].age,L->data[i].jg);
          for(int q=0;q<L->length2;q++)
          {strcpy(L->mac[L->length2].num,L->data[i].num);   
          strcpy(L->mac[L->length2].jg,L->data[i].jg);
        strcpy(L->mac[L->length2].name,L->data[i].name);
        strcpy(L->mac[L->length2].sex,L->data[i].sex);
        strcpy(L->mac[L->length2].age,L->data[i].age);}
          printf("\n");
          int a=0,b=0,c;
          printf("报名参加的考试有:");
          while(a==0)
          {for(int w=0;w<L->length2;w++)
          {
              b++;
              if(strcmp(L->mac[w].num,L->data[w].num)==0)
              {
                  scanf("%s,",L->mac[w].exam);
              }
              printf("还要继续报名其他考试吗? 1:继续 2:不继续");
              scanf("%d",&c);
              if(c==1)
              {
                  a=0;
              }
              if(c==2)
              {
                 a=1; break;
              }
          }
           printf("\n");
          }
          if(a==1)
          {
              for(int v=b+1;v<L->length2;v++)
              {
                  if(strcmp(L->mac[v].num,num)==0)
                  {
                      int j;
                      for (j=v;j<L->length2-1;j++)
                      {
                          L->mac[j]=L->data[j+1];                        
                      }  L->length2--;
                  }
              }
          }
     }
         printf("修改考生信息成功!\n");
 }





void ListDrop(SqList *&L)                //删除考生信息
{
     printf("请输入你要删除考生的考号!\n");
     char num[11];
     scanf("%s",&num);
     int i=0;
     while(i<L->length&&strcmp(L->data[i].num,num)!=0)
         i++;
     printf("该考生已被删除!\n");
     if(i>=L->length)
         printf("表内没有此考生!\n");
     else
     {
         int j;
     for (j=i;j<L->length-1;j++)
        L->data[j]=L->data[j+1];
       L->length--;
     }
}





void ListPaixu(SqList *&L)   //排序
{
       int num,i;
    printf("1:考号 \n2:考试类别 \n");
    printf("请选择你想要进行排序的方式:");
    scanf("%d",&num);
    printf("\n");
    if(num==1)
    {
        for(i=0;i<L->length-1;i++)                //冒泡法排序
        {     
         for(int j=0;j<L->length-1-i;j++)
         {
             if(strcmp(L->data[j].num,L->data[j+1].num)>0)
             {
                 strcpy(L->data1[j].num,L->data[j].num);
                 strcpy(L->data[j].num,L->data[j+1].num);
                 strcpy(L->data[j+1].num,L->data1[j].num);
                 strcpy(L->data1[j].name,L->data[j].name);
                 strcpy(L->data[j].name,L->data[j+1].name);
                 strcpy(L->data[j+1].name,L->data1[j].name);
                 strcpy(L->data1[j].sex,L->data[j].sex);
                 strcpy(L->data[j].sex,L->data[j+1].sex);
                 strcpy(L->data[j+1].sex,L->data1[j].sex);
                 strcpy(L->data1[j].age,L->data[j].age);
                 strcpy(L->data[j].age,L->data[j+1].age);
                 strcpy(L->data[j+1].age,L->data1[j].age);   
                 strcpy(L->data1[j].exam,L->data[j].exam);
                 strcpy(L->data[j].exam,L->data[j+1].exam);
                 strcpy(L->data[j+1].exam,L->data1[j].exam);
                 strcpy(L->data1[j].jg,L->data[j].jg);
                 strcpy(L->data[j].jg,L->data[j+1].jg);
                 strcpy(L->data[j+1].jg,L->data1[j].jg);
             }
         }
    }
   
      for (i=0;i<L->length;i++)
      {
          printf("考号:%s\n",L->data[i].num);
          printf("姓名:%s\n",L->data[i].name);
          printf("性别:%s\n",L->data[i].sex);
          printf("年龄:%s\n",L->data[i].age);
          printf("籍贯:%s\n",L->data[i].jg);
          printf("参加的考试有:");
          for(int j=0;j<L->length2;j++)
          {
              if(strcmp(L->mac[j].num,L->data[i].num)==0)
              {
                  printf("%s,",L->mac[j].exam);
              }
          }
      printf("\n");
      }
 }
    if(num==2)
    {
        
        for(i=0;i<L->length-1;i++)
        {
           for(int j=0;j<L->length-i-1;j++)
           {      
              if(strcmp(L->data[j].exam,L->data[j+1].exam)>0)
              {
                 strcpy(L->data1[j].num,L->data[j].num);
                 strcpy(L->data[j].num,L->data[j+1].num);
                 strcpy(L->data[j+1].num,L->data1[j].num);
                 strcpy(L->data1[j].name,L->data[j].name);
                 strcpy(L->data[j].name,L->data[j+1].name);
                 strcpy(L->data[j+1].name,L->data1[j].name);
                 strcpy(L->data1[j].sex,L->data[j].sex);
                 strcpy(L->data[j].sex,L->data[j+1].sex);
                 strcpy(L->data[j+1].sex,L->data1[j].sex);
                 strcpy(L->data1[j].age,L->data[j].age);
                 strcpy(L->data[j].age,L->data[j+1].age);
                 strcpy(L->data[j+1].age,L->data1[j].age);   
                 strcpy(L->data1[j].exam,L->data[j].exam);
                 strcpy(L->data[j].exam,L->data[j+1].exam);
                 strcpy(L->data[j+1].exam,L->data1[j].exam);
                 strcpy(L->data1[j].jg,L->data[j].jg);
                 strcpy(L->data[j].jg,L->data[j+1].jg);
                 strcpy(L->data[j+1].jg,L->data1[j].jg);
              }
            for(int t=0;t<L->length-1;t++)
           {
                 if(strcmp(L->data[t].exam,L->data[t+1].exam)==0)
                 {
                       if(strcmp(L->data[t].num,L->data[t+1].num)>0)
                       {
                                  strcpy(L->data1[t].num,L->data[t].num);
                                  strcpy(L->data[t].num,L->data[t+1].num);
                                  strcpy(L->data[t+1].num,L->data1[t].num);
                                  strcpy(L->data1[t].name,L->data[t].name);
                                  strcpy(L->data[t].name,L->data[t+1].name);
                                  strcpy(L->data[t+1].name,L->data1[t].name);
                                  strcpy(L->data1[t].sex,L->data[t].sex);
                                  strcpy(L->data[t].sex,L->data[t+1].sex);
                                  strcpy(L->data[t+1].sex,L->data1[t].sex);
                                  strcpy(L->data1[t].age,L->data[t].age);
                                  strcpy(L->data[t].age,L->data[t+1].age);
                                  strcpy(L->data[t+1].age,L->data1[t].age);   
                                  strcpy(L->data1[t].exam,L->data[t].exam);
                                  strcpy(L->data[t].exam,L->data[t+1].exam);
                                  strcpy(L->data[t+1].exam,L->data1[t].exam);
                                  strcpy(L->data1[t].jg,L->data[t].jg);
                                  strcpy(L->data[t].jg,L->data[t+1].jg);
                                  strcpy(L->data[t+1].jg,L->data1[t].jg);
                       }     
                 }
            }
    }
    }   
    for (i=0;i<L->length;i++)
      {
          printf("考号:%s\n",L->data[i].num);
          printf("姓名:%s\n",L->data[i].name);
          printf("性别:%s\n",L->data[i].sex);
          printf("年龄:%s\n",L->data[i].age);
          printf("籍贯:%s\n",L->data[i].jg);
          printf("参加的考试有:");
          for(int j=0;j<L->length2;j++)
          {
              if(strcmp(L->mac[j].num,L->data[i].num)==0)
              {
                  printf("%s,",L->mac[j].exam);
              }
          }
      printf("\n");
      }
}
}





void ListSearch(SqList *&L)                              //查找考生信息
{
    int num;
    printf("1:考号 \n2:考试类别 \n");
    printf("请选择你想要进行查询考生的方式:");
    scanf("%d",&num);
    printf("\n");
    if(num==1)
    {
        printf("请输入你想要查找考生的考号:");
    char num[11];
    scanf("%s",&num);
    int i=0;
     while(i<L->length&&strcmp(L->data[i].num,num)!=0)
         i++;
     if(i>=L->length)
         printf("表内没有此考生!\n");
     else
     {
          printf("考号:%s\n",L->data[i].num);
          printf("姓名:%s\n",L->data[i].name);
          printf("性别:%s\n",L->data[i].sex);
          printf("年龄:%s\n",L->data[i].age);
          printf("籍贯:%s\n",L->data[i].jg);
          printf("参加的考试有:");
          for(int j=0;j<L->length2;j++)
          {
              if(strcmp(L->mac[j].num,L->data[i].num)==0)
              {
                  printf("%s,",L->mac[j].exam);
              }
          }
      printf("\n");
     }
    }
    if(num==2)
    {
       printf("请输入你想要查找的考试类别:");
        char exam[30];
        scanf("%s",&exam);
        int i=0,a=0;
        for(i;i<L->length2;i++)
        {
            if(strcmp(L->mac[i].exam,exam)==0)
                a++;
        }
        if(a==0)
        {
            printf("没有学生参与%s考试\n",exam);
        }
         else
         {
             printf("共有%d个学生报名参加%s考试,信息如下:\n",a,exam);
            printf("考号     姓名    性别    年龄     考试类别    籍贯\n");
            for(int o=0;o<L->length2;o++)
            {
            if(strcmp(L->mac[o].exam,exam)==0)   
            {
            printf("%s\t%s\t%s\t%s\t%s\t%s",L->mac[o].num,L->mac[o].name,L->mac[o].sex,L->mac[o].age,L->mac[o].exam,L->mac[o].jg);
            printf("\n");
            }
            }
         }
    }
}





void InitList(SqList *&L)
{
    L=(SqList *)malloc(sizeof(SqList));         
    L->length=0;           //用来存储人数
    L->length2=0;         //存储人次
    L->number=0;
}



int ListEmpty(SqList *L)
{
    return(L->length==0);
}




void DispList(SqList *&L)                             //输出考生信息
{
   
      int i;
      if(ListEmpty(L))
      printf("表内没有任何考生的信息!");
      for (i=0;i<L->length;i++)
     printf("%s\t%s\t%s\t%s\t%s\t%s\n",L->data[i].num,L->data[i].name,L->data[i].sex,L->data[i].exam,L->data[i].jg);
      printf("\n");
}





void ListTongji(SqList *&L)
{
    int i,j,a=0;
    printf("共有%d个学生报名考试!\n",L->length);
    printf("每个学生报名考试种类数量如下:\n");
    for (i=0;i<L->length;i++)
      {
          printf("考号:%s\n",L->data[i].num);
          printf("姓名:%s\n",L->data[i].name);
          printf("性别:%s\n",L->data[i].sex);
          printf("年龄:%s\n",L->data[i].age);
          printf("籍贯:%s\n",L->data[i].jg);
          printf("参加的考试有:");
          for(j=0;j<L->length2;j++)
          {
              if(strcmp(L->mac[j].num,L->data[i].num)==0)
              {
                  printf("%s,",L->mac[j].exam);
                  a++;
              }
          }
          printf("共报名参加%d门考试",a);
          a=0;
      printf("\n");
      }
    printf("共有%d门考试有同学报名。\n",L->number);
    printf("每种类别考试人数如下:\n");
    for(i=0;i<L->number;i++)
    {
        int sum=0;
        for(j=0;j<L->length2;j++)
        {        
            if(strcmp(L->hy[i].exam,L->mac[j].exam)==0)
            {
                sum++;
            }
        }
        printf("报名参加%s考试的考生有%d名。\n",L->hy[i].exam,sum);
    }
}






void main()
{
   SqList *L;
   InitList(L);
   int num;
    while(1)
    {
    printf("◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇\n");
    printf("\t              欢迎进入考生管理系统!                     \t \n");
    printf("\t       1.报考信息录入      2.考生信息修改             \t \n");
    printf("\t       3.考生信息删除      4.考生信息查询            \t \n");
    printf("\t       5.考生信息统计      6.考生信息排序     \t\n");
    printf("\t       7.退出系统               \t\n");
    printf("◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆◇◆\n");
    printf("请选择你要进行的操作:");
    scanf("%d",&num);
    switch(num)
    {
        case 1:ListAdd(L);break;
        case 2:ListChange(L);break;                    
        case 3:ListDrop(L);break;                        
        case 4:ListSearch(L);break;  
        case 5:ListTongji(L);break;
        case 6:ListPaixu(L);break;
        case 7:return;
        default:{printf("操作错勿,请重新输入!\n");}   
    }
    }
}
搜索更多相关主题的帖子: printf strcpy num data mac 
2019-12-21 20:46
bateshi996
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2019-12-20
收藏
得分:0 
这个代码有个错误,怎么改啊!还有如何加入栈或队列进去
2019-12-21 20:48
WilsonLA
Rank: 1
等 级:新手上路
威 望:1
帖 子:9
专家分:0
注 册:2020-1-20
收藏
得分:0 
同学,有错误请把报错信息或者是警告信息贴出来。另外建议你把ADT和其他功能分开,不要写在一起,这样代码复用性低下,而且冗长不好从中找错误。本来不想看了,但还是看了下,你看你有一些函数的形参,*& 这个东西取地址再解引用,相当于什么也没干,我注意到你主函数体前两行对L进行初始化,L是一个SqList型的指针,而表初始化函数以及诸多函数的形参竟然是SqList *&L,这就相当于SqList L,我们知道C语言是传值而不是传引用,所以你这么写是不行的。另外还有一个严重错误,你没有回收内存。
2020-01-20 23:08
jinxiao66
Rank: 2
等 级:论坛游民
帖 子:11
专家分:16
注 册:2019-12-22
收藏
得分:0 
好复杂。我需要加快学习进度才能看懂。
2020-01-29 20:22
lijingui2010
Rank: 1
等 级:新手上路
威 望:1
帖 子:5
专家分:5
注 册:2020-1-29
收藏
得分:0 
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MaxSize 100
typedef struct {
    char num[30];          //考号
    char name[30];         //名字
    char sex[30];         //性别
    char exam[30];          //考试类别
    char jg[30];             //籍贯
    char age[30];        //年龄
} ElemType;




typedef struct {
    ElemType data[MaxSize],data1[MaxSize],mac[MaxSize],hy[MaxSize];
    int length;//记录一门考试有多少人
    int length2; //记录一个考生报考的门数
    int number;   //记录考试种类
} SqList;




void ListAdd(SqList *L) {                             //添加考生信息
    int a=0,b=0,c=0,y=0;
    printf("请输入考生信息!%d\n", L->length);
    printf("考号     姓名    性别    年龄     考试类别    籍贯\n");
    scanf("%s %s %s %s %s %s",L->data[L->length].num,L->data[L->length].name,L->data[L->length].sex,L->data[L->length].age,L->data[L->length].exam,L->data[L->length].jg);
    printf("\n");
    for(int i=0; i<L->length; i++) {
        if(strcmp(L->data[i].num,L->data[L->length].num)==0) {

            for(int j=0; j<L->length2; j++) {
                if(strcmp(L->mac[j].exam,L->data[L->length].exam)==0) {
                    a=1;
                    b=1;
                    break;
                }
            }
            if(b==0) {
                strcpy(L->mac[L->length2].num,L->data[L->length].num);
                strcpy(L->mac[L->length2].jg,L->data[L->length].jg);
                strcpy(L->mac[L->length2].name,L->data[L->length].name);
                strcpy(L->mac[L->length2].sex,L->data[L->length].sex);
                strcpy(L->mac[L->length2].age,L->data[L->length].age);
                strcpy(L->mac[L->length2].exam,L->data[L->length].exam);
                printf("报名考试成功!\n");
                c=1;
                while(y<L->length2&&strcmp(L->mac[y].exam,L->data[L->length].exam)!=0) {
                    y++;
                }
                if(y>=L->length2) {

                    strcpy(L->hy[L->number].exam,L->data[L->length].exam);
                    L->number++;
                }
                L->length2++;
            }
        }
    }
    if(a==1) {
        printf("你已经报名了这门考试。\n");
    }
    if(a==0&&c==0) {
        strcpy(L->mac[L->length2].num,L->data[L->length].num);
        strcpy(L->mac[L->length2].jg,L->data[L->length].jg);
        strcpy(L->mac[L->length2].name,L->data[L->length].name);
        strcpy(L->mac[L->length2].sex,L->data[L->length].sex);
        strcpy(L->mac[L->length2].age,L->data[L->length].age);
        strcpy(L->mac[L->length2].exam,L->data[L->length].exam);
        y=0;
        while(y<L->length2&&strcmp(L->mac[y].exam,L->data[L->length].exam)!=0) {
            y++;
        }
        if(y>=L->length2) {
            strcpy(L->hy[L->number].exam,L->data[L->length].exam);
            L->number++;
        }
        L->length2++;
        L->length++;
        printf("报名考试成功!\n");

    }
}





void ListChange(SqList *L) {                                    //修改考生信息
    printf("请输入你要修改考生的考号:\n");
    char num[11];
    scanf("%s",num);
    printf("你要修改的考生信息如下:\n");
    int i=0;
    while(i<L->length&&strcmp(L->data[i].num,num)!=0)
        i++;
    if(i>=L->length)
        printf("表内没有此考生!\n");
    else {
        printf("考号:%s\n",L->data[i].num);
        printf("姓名:%s\n",L->data[i].name);
        printf("性别:%s\n",L->data[i].sex);
        printf("年龄:%s\n",L->data[i].age);
        printf("籍贯:%s\n",L->data[i].jg);
        printf("参加的考试有:");
        for(int j=0; j<L->length2; j++) {
            if(strcmp(L->mac[j].num,L->data[i].num)==0) {
                printf("%s,",L->mac[j].exam);
            }
        }
        printf("\n");
        printf("请输入考生信息!\n");
        printf("考号     姓名    性别    年龄     籍贯\n");
        scanf("%s %s %s %s  %s",L->data[i].num,L->data[i].name,L->data[i].sex,L->data[i].age,L->data[i].jg);
        for(int q=0; q<L->length2; q++) {
            strcpy(L->mac[L->length2].num,L->data[i].num);
            strcpy(L->mac[L->length2].jg,L->data[i].jg);
            strcpy(L->mac[L->length2].name,L->data[i].name);
            strcpy(L->mac[L->length2].sex,L->data[i].sex);
            strcpy(L->mac[L->length2].age,L->data[i].age);
        }
        printf("\n");
        int a=0,b=0,c;
        printf("报名参加的考试有:");
        while(a==0) {
            for(int w=0; w<L->length2; w++) {
                b++;
                if(strcmp(L->mac[w].num,L->data[w].num)==0) {
                    scanf("%s,",L->mac[w].exam);
                }
                printf("还要继续报名其他考试吗? 1:继续 2:不继续");
                scanf("%d",&c);
                if(c==1) {
                    a=0;
                }
                if(c==2) {
                    a=1;
                    break;
                }
            }
            printf("\n");
        }
        if(a==1) {
            for(int v=b+1; v<L->length2; v++) {
                if(strcmp(L->mac[v].num,num)==0) {
                    int j;
                    for (j=v; j<L->length2-1; j++) {
                        L->mac[j]=L->data[j+1];
                    }
                    L->length2--;
                }
            }
        }
    }
    printf("修改考生信息成功!\n");
}





void ListDrop(SqList *L) {              //删除考生信息
    printf("请输入你要删除考生的考号!\n");
    char num[11];
    scanf("%s",num);
    int i=0;
    while(i<L->length&&strcmp(L->data[i].num,num)!=0)
        i++;
    printf("该考生已被删除!\n");
    if(i>=L->length)
        printf("表内没有此考生!\n");
    else {
        int j;
        for (j=i; j<L->length-1; j++)
            L->data[j]=L->data[j+1];
        L->length--;
    }
}





void ListPaixu(SqList *L) { //排序
    int num,i;
    printf("1:考号 \n2:考试类别 \n");
    printf("请选择你想要进行排序的方式:");
    scanf("%d",&num);
    printf("\n");
    if(num==1) {
        for(i=0; i<L->length-1; i++) {            //冒泡法排序
            for(int j=0; j<L->length-1-i; j++) {
                if(strcmp(L->data[j].num,L->data[j+1].num)>0) {
                    strcpy(L->data1[j].num,L->data[j].num);
                    strcpy(L->data[j].num,L->data[j+1].num);
                    strcpy(L->data[j+1].num,L->data1[j].num);
                    strcpy(L->data1[j].name,L->data[j].name);
                    strcpy(L->data[j].name,L->data[j+1].name);
                    strcpy(L->data[j+1].name,L->data1[j].name);
                    strcpy(L->data1[j].sex,L->data[j].sex);
                    strcpy(L->data[j].sex,L->data[j+1].sex);
                    strcpy(L->data[j+1].sex,L->data1[j].sex);
                    strcpy(L->data1[j].age,L->data[j].age);
                    strcpy(L->data[j].age,L->data[j+1].age);
                    strcpy(L->data[j+1].age,L->data1[j].age);
                    strcpy(L->data1[j].exam,L->data[j].exam);
                    strcpy(L->data[j].exam,L->data[j+1].exam);
                    strcpy(L->data[j+1].exam,L->data1[j].exam);
                    strcpy(L->data1[j].jg,L->data[j].jg);
                    strcpy(L->data[j].jg,L->data[j+1].jg);
                    strcpy(L->data[j+1].jg,L->data1[j].jg);
                }
            }
        }

        for (i=0; i<L->length; i++) {
            printf("考号:%s\n",L->data[i].num);
            printf("姓名:%s\n",L->data[i].name);
            printf("性别:%s\n",L->data[i].sex);
            printf("年龄:%s\n",L->data[i].age);
            printf("籍贯:%s\n",L->data[i].jg);
            printf("参加的考试有:");
            for(int j=0; j<L->length2; j++) {
                if(strcmp(L->mac[j].num,L->data[i].num)==0) {
                    printf("%s,",L->mac[j].exam);
                }
            }
            printf("\n");
        }
    }
    if(num==2) {

        for(i=0; i<L->length-1; i++) {
            for(int j=0; j<L->length-i-1; j++) {
                if(strcmp(L->data[j].exam,L->data[j+1].exam)>0) {
                    strcpy(L->data1[j].num,L->data[j].num);
                    strcpy(L->data[j].num,L->data[j+1].num);
                    strcpy(L->data[j+1].num,L->data1[j].num);
                    strcpy(L->data1[j].name,L->data[j].name);
                    strcpy(L->data[j].name,L->data[j+1].name);
                    strcpy(L->data[j+1].name,L->data1[j].name);
                    strcpy(L->data1[j].sex,L->data[j].sex);
                    strcpy(L->data[j].sex,L->data[j+1].sex);
                    strcpy(L->data[j+1].sex,L->data1[j].sex);
                    strcpy(L->data1[j].age,L->data[j].age);
                    strcpy(L->data[j].age,L->data[j+1].age);
                    strcpy(L->data[j+1].age,L->data1[j].age);
                    strcpy(L->data1[j].exam,L->data[j].exam);
                    strcpy(L->data[j].exam,L->data[j+1].exam);
                    strcpy(L->data[j+1].exam,L->data1[j].exam);
                    strcpy(L->data1[j].jg,L->data[j].jg);
                    strcpy(L->data[j].jg,L->data[j+1].jg);
                    strcpy(L->data[j+1].jg,L->data1[j].jg);
                }
                for(int t=0; t<L->length-1; t++) {
                    if(strcmp(L->data[t].exam,L->data[t+1].exam)==0) {
                        if(strcmp(L->data[t].num,L->data[t+1].num)>0) {
                            strcpy(L->data1[t].num,L->data[t].num);
                            strcpy(L->data[t].num,L->data[t+1].num);
                            strcpy(L->data[t+1].num,L->data1[t].num);
                            strcpy(L->data1[t].name,L->data[t].name);
                            strcpy(L->data[t].name,L->data[t+1].name);
                            strcpy(L->data[t+1].name,L->data1[t].name);
                            strcpy(L->data1[t].sex,L->data[t].sex);
                            strcpy(L->data[t].sex,L->data[t+1].sex);
                            strcpy(L->data[t+1].sex,L->data1[t].sex);
                            strcpy(L->data1[t].age,L->data[t].age);
                            strcpy(L->data[t].age,L->data[t+1].age);
                            strcpy(L->data[t+1].age,L->data1[t].age);
                            strcpy(L->data1[t].exam,L->data[t].exam);
                            strcpy(L->data[t].exam,L->data[t+1].exam);
                            strcpy(L->data[t+1].exam,L->data1[t].exam);
                            strcpy(L->data1[t].jg,L->data[t].jg);
                            strcpy(L->data[t].jg,L->data[t+1].jg);
                            strcpy(L->data[t+1].jg,L->data1[t].jg);
                        }
                    }
                }
            }
        }
        for (i=0; i<L->length; i++) {
            printf("考号:%s\n",L->data[i].num);
            printf("姓名:%s\n",L->data[i].name);
            printf("性别:%s\n",L->data[i].sex);
            printf("年龄:%s\n",L->data[i].age);
            printf("籍贯:%s\n",L->data[i].jg);
            printf("参加的考试有:");
            for(int j=0; j<L->length2; j++) {
                if(strcmp(L->mac[j].num,L->data[i].num)==0) {
                    printf("%s,",L->mac[j].exam);
                }
            }
            printf("\n");
        }
    }
}





void ListSearch(SqList *L) {                            //查找考生信息
    int num;
    printf("1:考号 \n2:考试类别 \n");
    printf("请选择你想要进行查询考生的方式:");
    scanf("%d",&num);
    printf("\n");
    if(num==1) {
        printf("请输入你想要查找考生的考号:");
        char num[11];
        scanf("%s",num);
        int i=0;
        while(i<L->length&&strcmp(L->data[i].num,num)!=0)
            i++;
        if(i>=L->length)
            printf("表内没有此考生!\n");
        else {
            printf("考号:%s\n",L->data[i].num);
            printf("姓名:%s\n",L->data[i].name);
            printf("性别:%s\n",L->data[i].sex);
            printf("年龄:%s\n",L->data[i].age);
            printf("籍贯:%s\n",L->data[i].jg);
            printf("参加的考试有:");
            for(int j=0; j<L->length2; j++) {
                if(strcmp(L->mac[j].num,L->data[i].num)==0) {
                    printf("%s,",L->mac[j].exam);
                }
            }
            printf("\n");
        }
    }
    if(num==2) {
        printf("请输入你想要查找的考试类别:");
        char exam[30];
        scanf("%s",exam);
        int i=0,a=0;
        for(i; i<L->length2; i++) {
            if(strcmp(L->mac[i].exam,exam)==0)
                a++;
        }
        if(a==0) {
            printf("没有学生参与%s考试\n",exam);
        } else {
            printf("共有%d个学生报名参加%s考试,信息如下:\n",a,exam);
            printf("考号     姓名    性别    年龄     考试类别    籍贯\n");
            for(int o=0; o<L->length2; o++) {
                if(strcmp(L->mac[o].exam,exam)==0) {
                    printf("%s\t%s\t%s\t%s\t%s\t%s",L->mac[o].num,L->mac[o].name,L->mac[o].sex,L->mac[o].age,L->mac[o].exam,L->mac[o].jg);
                    printf("\n");
                }
            }
        }
    }
}





void InitList(SqList *L) {
    //L=(SqList *)malloc(sizeof(SqList));
    L->length=0;           //用来存储人数
    L->length2=0;         //存储人次
    L->number=0;
}



int ListEmpty(SqList *L) {
    return(L->length==0);
}




void DispList(SqList *L) {                           //输出考生信息

    int i;
    if(ListEmpty(L))
        printf("表内没有任何考生的信息!");
    for (i=0; i<L->length; i++)
        printf("%s\t%s\t%s\t%s\t%s\t%s\n",L->data[i].num,L->data[i].name,L->data[i].sex,L->data[i].exam,L->data[i].jg, L->data[i].age);
    printf("\n");
}





void ListTongji(SqList *L) {
    int i,j,a=0;
    printf("共有%d个学生报名考试!\n",L->length);
    printf("每个学生报名考试种类数量如下:\n");
    for (i=0; i<L->length; i++) {
        printf("考号:%s\n",L->data[i].num);
        printf("姓名:%s\n",L->data[i].name);
        printf("性别:%s\n",L->data[i].sex);
        printf("年龄:%s\n",L->data[i].age);
        printf("籍贯:%s\n",L->data[i].jg);
        printf("参加的考试有:");
        for(j=0; j<L->length2; j++) {
            if(strcmp(L->mac[j].num,L->data[i].num)==0) {
                printf("%s,",L->mac[j].exam);
                a++;
            }
        }
        printf("共报名参加%d门考试",a);
        a=0;
        printf("\n");
    }
    printf("共有%d门考试有同学报名。\n",L->number);
    printf("每种类别考试人数如下:\n");
    for(i=0; i<L->number; i++) {
        int sum=0;
        for(j=0; j<L->length2; j++) {
            if(strcmp(L->hy[i].exam,L->mac[j].exam)==0) {
                sum++;
            }
        }
        printf("报名参加%s考试的考生有%d名。\n",L->hy[i].exam,sum);
    }
}






int main(void) {
    SqList LL;
    SqList *L = &LL;
    InitList(L);
    int num;
    while(1) {
        printf("*****************************************\n");
        printf("\t              欢迎进入考生管理系统!                     \t \n");
        printf("\t       1.报考信息录入      2.考生信息修改             \t \n");
        printf("\t       3.考生信息删除      4.考生信息查询            \t \n");
        printf("\t       5.考生信息统计      6.考生信息排序     \t\n");
        printf("\t       7.退出系统               \t\n");
        printf("*****************************************\n");
        printf("请选择你要进行的操作:");
        scanf("%d",&num);
        switch(num) {
        case 1:
            ListAdd(L);
            break;
        case 2:
            ListChange(L);
            break;
        case 3:
            ListDrop(L);
            break;
        case 4:
            ListSearch(L);
            break;
        case 5:
            ListTongji(L);
            break;
        case 6:
            ListPaixu(L);
            break;
        case 7:
            return 0;
        default:
            printf("操作错勿,请重新输入!\n");
        }
    }

    return 0;
}
2020-01-30 01:45
快速回复:求助 编译有问题 哪位大神教教我怎么改!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031952 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved