haoyuebuzui 2014-06-18 15:46 采纳率: 0%
浏览 1930

大神求救!!!基础学生综合信息管理系统有三个功能运行不了

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
#define N 100
struct stu{
    char number[8];
    char name[8];
    char sex[2];
    int yw,sx,yy,sum;
    float ave;
};
void creat(struct stu score[]);
void add(struct stu score[]);
void search(struct stu score[]);
void alter(struct stu score[]);
void del(struct stu score[]);
void sta(struct stu score[]);
void sort(struct stu score[]);
static int m=0;
void main()
{
    int p;
    struct stu score[50];
    printf("                       学生成绩管理系统\n");
    printf("1.创建学生的资料                       2.追加学生的资料\n");
    printf("3.查询学生的资料                       4.修改学生的资料\n");
    printf("5.删除学生的资料                       6.统计学生的资料\n");
    printf("7.对学生资料进行排序\n");
    printf("***欢迎进入成绩管理系统,请选择您所要的操作(按任意键退出):");
    scanf("%d",&p); 
    while(p>=1&&p<=7)
    {
        switch(p)
        {
            case 1:creat(score);break;
            case 2:add(score);break;
            case 3:search(score);break;
            case 4:alter(score);break;
            case 5:del(score);break;
            case 6:sta(score);break;
            case 7:sort(score);break;
            default :exit(0);
        }
        printf("请选择您所要的操作:");
        scanf("%d",&p);
    }

}



void creat(struct stu score[])
{
    int i=0,k=1;

    while(k!=0)
    {


        printf("请依次输入第%d个学生的学号、姓名、性别、语文、数学、英语:\n",i+1);
        scanf("%s%s%s%d%d%d",
          score[i].number,score[i].name,score[i].sex,&score[i].yw,&score[i].sx,
          &score[i].yy,&score[i].sum,&score[i].ave);
        m++;
        printf("是否继续(0表示结束)");
        scanf("%d",&k);

    }
}
void add(struct stu score[])
{
    int i;
    int q;
    printf("要添加的人数:");
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        printf("请依次输入要添加的第%d个学生的学号、姓名、性别、语文、数学、英语:\n",i+1);
        scanf("%s%s%s%d%d%d",
          score[i].number,score[i].name,score[i].sex,&score[i].yw,&score[i].sx,
          &score[i].yy);
        m=m+q;
    }
}
void search(struct stu score[])
{
    char q[8];int i;
    printf("输入要查询的学生的姓名或学号:");
    gets(q);
    for(i=0;i<m;i++)
    {
        if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
            printf("%s%s%s%d%d%d%f%f",
                score[i].number,score[i].name,score[i].sex,score[i].yw,score[i].sx,score[i].yy,score[i].sum,score[i].ave);
    }
}

void alter(struct stu score[])
{
    char q[8];int i;
    printf("资料要修改的学生的姓名或学号:");
    gets(q);
    for(i=0;i<m;i++)
    {
        if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
        {
            printf("请重新依序输入该学生资料(学号、姓名、性别、语文、数学、英语):");
                scanf("%s%s%s%d%d%d",
                        &score[i].number,&score[i].name,&score[i].sex,&score[i].yw,&score[i].sx,
                        &score[i].yy);
        }
    }
}

void del(struct stu score[])
{
    char q[8];
    int i,j;
    printf("要删除的学生的姓名或学号:");
    gets(q);
    for(i=0;i<m;i++){
      if(strcmp(q,score[i].name)==0||strcmp(q,score[i].number)==0)
        {
        for(j=i;j<m-1;j++)
        score[j]=score[j+1];
        m-=1;       
        }
    }
}
void sta(struct stu score[])
{
    int i;
    for(i=0;i<m;i++)
    {
        score[i].sum=score[i].yw+score[i].sx+score[i].yy;
        score[i].ave=(float)score[i].sum/3;
    }
}
void sort(struct stu score[])
{
    int i,j;
    struct stu t;
    for(i=0;i<m-1;i++)
    {
        for(j=i+1;j<m;j++)
        {
           if(score[i].ave<score[j].ave)
           t=score[i],score[i]=score[j],score[j]=t;
        }
    }
}

////creat函数中我总是要输入k值判断是否继续,能否换个方式优化一下,连续输入,最后判断一次就好。功能5,6,7,运行不了,其他正常 ,实在不知道原因。

  • 写回答

1条回答

  • LightHjj 2014-06-19 02:02
    关注

    case 5:del(score);break;因为你在del函数中使用gets(q),所以要在break前加getchar()消除回车键值。
    而你的功能六和七没有输出啊 可以运行滴

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决