标题:【求助】我有个c语言的题目出错了 可不可以帮我改下
只看楼主
disseek
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-6-21
结帖率:0
已结贴  问题点数:20 回复次数:6 
【求助】我有个c语言的题目出错了 可不可以帮我改下
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
#include "gotoxy.c"
#define STUSIZE 40
void mainmenu();//主菜单
void editmenu();//编辑子菜单
void dispmenu();//显示子菜单
void compmenu();//计算子菜单
void sortmenu();//排序子菜单
int add(struct student *,int *);//追加记录
void Open(struct student stu[],int *size);//打开文件
void Save(struct student stu[],int n);//保存文件
int del(struct student *,int *);//删除记录
int modify(struct student *,int *);//修改程序
void DispOne(struct student *,int,char *);//查看一个记录
void Disp(struct student *,int,char *);//查看全部记录
void DispSort(struct student *,int);//显示排序结果
void NotElig(struct student *,int);//显示不及格记录
void compsum(struct student *,int);//计算总成绩和平均成绩
void compmax(struct student *,int);//计算最高成绩
void compmin(struct student *,int);//计算最低成绩
void DropSort(struct student *,int);//按降序排列
void AsceSort(struct student *,int);//按升序排列
void DispMaxMin(struct student,char *);//显示最高分和最低分记录

struct student
{
    int stunum;//学号
    char stuname[10];//姓名
    float stuscore[5];//3门成绩,平均成绩,总成绩
};

void main()
{
    char choose='\0';
    char editch='\0';
    char dispch='\0';
    char compch='\0';
    char sortch='\0';
    struct student stu[STUSIZE];
    //int size;
    int stunum=0;//学生数
    system("cls");
    gotoxy(10,3);
    printf("     欢迎来到软件1202班【胡良艺】开发的课程设计任务程序中 \n");
    gotoxy(10,5);
    printf("通过简单学生成绩管理系统软件的开发,您将看到我对C语言开\n");
    gotoxy(10,7);
    printf("发程序的方法与技巧。\n");
    gotoxy(10,9);
    printf("    该任务又分为5个小任务,每个小任务又分为若干个小项目,通过完\n");
    gotoxy(10,11);
    printf("成小任务和小项目最终达到完成整个任务的设计。\n");
    gotoxy(10,13);
    printf("**************************************************************\n");
    gotoxy(10,15);
    printf("**************************************************************\n");
    gotoxy(10,17);
    printf("**************************************************************\n");
    gotoxy(10,19);
    printf("**************************************************************\n");
    gotoxy(23,23);
    printf("按任意键进入学生成绩管理系统主菜单!");
    getch();


    while(1)
    {
        mainmenu();//调用主菜单
        printf("                              请输入序号:");
        choose=getchar();
        switch(choose)
        {
        case '1':Open(stu,&stunum);break;
        case '2':Save(stu,stunum);break;
        case '3':
            do
            {
                editmenu();//调用编辑子菜单
                printf("                              请输入序号:");
                editch=getchar();
                switch(editch)
                {
                case '1':add(stu,&stunum);break;
                case '2':del(stu,&stunum);break;
                case '3':modify(stu,&stunum);break;
                case '0':
                    system("cls");
                    printf("\n\n\n\n\n\n                          操作结束,返回上级菜单!");
                    getch();
                    system("cls");
                    break;
                }
            }while(editch!='0');
        break;//Input(stu,N)
        case '4':
            do
            {
                dispmenu();//调用显示子菜单
                printf("                              请输入序号:");
                dispch=getchar();
                switch(dispch)
                {
                case '1':DispOne(stu,stunum,"显示单个学生记录!");break;
                case '2':Disp(stu,stunum,"学生成绩报表!");break;
                case '3':
                    do
                    {
                        sortmenu();//调用排序子菜单
                        printf("                              请输入序号:");
                        sortch=getchar();
                        switch(sortch)
                        {
                        case '1':AsceSort(stu,stunum);break;
                        case '2':DropSort(stu,stunum);break;
                        case '0':
                            system("cls");
                            printf("\n\n\n\n\n\n                          操作结束,返回上级菜单!");
                            getch();
                            system("cls");
                            break;
                        }
                    }while(sortch!='0');
                     break;
                case '4':NotElig(stu,stunum);break;
                case '0':
                    system("cls");
                    printf("\n\n\n\n\n\n                          操作结束,返回上级菜单!");
                    getch();
                    system("cls");
                    break;
                }
            }while(dispch!='0');
            break;
        case '5':
            do
            {
                compmenu();//调用计算子菜单
                printf("                             请输入序号:");
                compch=getchar();
                switch(compch)
                {
                case '1':compsum(stu,stunum);break;
                case '2':compmax(stu,stunum);break;
                case '3':compmin(stu,stunum);break;
                case '0':
                    system("cls");
                    printf("\n\n\n\n\n\n                          操作结束,返回上级菜单!");
                    getch();
                    system("cls");
                    break;
                }
            }while(compch!='0');
            break;
        case '0'://退出系统
            system("cls");
            printf("\n\n\n\n\n\n                             操作结束,退出系统!");
            getch();
            system("cls");
            exit(0);
        }
    }
}

void mainmenu()
{
    system("cls"); //C++清屏函数
    printf("\n\n\n");
    printf("                    |* * * * * 学生成绩管理系统 * * * * *|\n");
    printf("                    |....................................|\n");
    printf("                    |         请选择菜单序号(0~5)        |\n");
    printf("                    |....................................|\n");
    printf("                    |           1----打开文件            |\n");
    printf("                    |           2----保存文件            |\n");
    printf("                    |           3----编辑数据            |\n");
    printf("                    |           4----显示数据            |\n");
    printf("                    |           5----数据计算            |\n");
    printf("                    |           0----退出系统            |\n");
    printf("                    |....................................|\n");
}

void editmenu()//编辑子菜单
{
    getchar();
    system("cls");
    printf("\n\n\n");
    printf("                    |* * * * * * * 编辑子菜单 * * * * * *|\n");
    printf("                    |....................................|\n");
    printf("                    |         请选择菜单序号(0~3)        |\n");
    printf("                    |....................................|\n");
    printf("                    |           1----增加记录            |\n");
    printf("                    |           2----删除记录            |\n");
    printf("                    |           3----修改记录            |\n");
    printf("                    |           0----返回上级菜单        |\n");
    printf("                    |....................................|\n");

}

void dispmenu()//查看子菜单
{
    system("cls");
    printf("\n\n\n");
    printf("                    |* * * * * * * 查看子菜单 * * * * * *|\n");
    printf("                    |....................................|\n");
    printf("                    |         请选择菜单序号(0~3)        |\n");
    printf("                    |....................................|\n");
    printf("                    |           1----查看选定记录        |\n");
    printf("                    |           2----显示全部记录        |\n");
    printf("                    |           3----显示排序记录        |\n");
    printf("                    |           4----显示不及格记录      |\n");
    printf("                    |           0----返回上级菜单        |\n");
    printf("                    |....................................|\n");

}

void compmenu()//计算子菜单
{
    system("cls");
    printf("\n\n\n");
    printf("                    |* * * * * * * 计算子菜单 * * * * * *|\n");
    printf("                    |....................................|\n");
    printf("                    |         请选择菜单序号(0~3)        |\n");
    printf("                    |....................................|\n");
    printf("                    |     1----计算总成绩和平均成绩      |\n");
    printf("                    |     2----计算最高分                |\n");
    printf("                    |     3----计算最低分                |\n");
    printf("                    |     0----返回上级菜单              |\n");
    printf("                    |....................................|\n");
}

void sortmenu()//排序子菜单
{
    system("cls");
    printf("\n\n\n");
    printf("                    |* * * * * * * 排序子菜单 * * * * * *|\n");
    printf("                    |....................................|\n");
    printf("                    |         请选择菜单序号(0~2)        |\n");
    printf("                    |....................................|\n");
    printf("                    |           1----按升序排序          |\n");
    printf("                    |           2----按降序排序          |\n");
    printf("                    |           0----返回上级菜单        |\n");
    printf("                    |....................................|\n");

}

void compsum(struct student stu[],int stusize)
{
    int i,j;
    float sumscore;
    system("cls");
    if(stusize<=0)
    {
        gotoxy(22,5);
        printf("数组中没有学生记录或文件没有打开,不能计算总成绩和平均成绩!");
        getch();
    }
    else
    {
        for(i=0;i<stusize;i++)
        {
            sumscore=0;
            for(j=0;j<3;j++)
            {
                sumscore+=stu[i].stuscore[j];
            }
            stu[i].stuscore[3]=sumscore;
            stu[i].stuscore[4]=sumscore/3.0f;
        }
        gotoxy(20,5);
        printf("计算总成绩和平均成绩成功,按任意键返回上级菜单!");
        getch();
    }
}

void compmax(struct student stu[],int stusize)
{
    float sum;
    int i,loop;
    if(stusize<=0)
    {
        system("cls");
        gotoxy(33,2);
        printf("总成绩最高记录(只找一个)");
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能进行计算操作!");
        getch();
    }
    else
    {
        for(i=0;i<stusize;i++)
        {
            if(stu[i].stuscore[3]>sum)
            {
                sum=stu[i].stuscore[3];
                loop=i;
            }
        }
        DispMaxMin(stu[loop],"总成绩最高记录(只找一个)");
    }
}

void DispMaxMin(struct student stu,char str[])//显示最高分和最低分记录
{
    int i;
    system("cls");
    gotoxy(33,2);
    printf("%s\n",str);
    gotoxy(5,4);
    printf("学号     姓名     语文      数学      英语     总成绩   平均成绩");
    gotoxy(5,6);
    printf("%-5d",stu.stunum);
    printf("%8s",stu.stuname);
    for(i=0;i<5;i++)
    {
        printf("%10.1f",stu.stuscore[i]);
    }
    printf("\n");
   
    gotoxy(25,8);
    printf("显示成功,按任意键返回上级菜单!");
    getch();

}

void compmin(struct student stu[],int stusize)
{
    float sum;
    int i,loop;
    if(stusize<=0)
    {
        system("cls");
        gotoxy(33,2);
        printf("总成绩最低记录(只找一个)");
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能进行计算操作!");
        getch();
    }
    else
    {
        sum=stu[0].stuscore[3];
        for(i=1;i<stusize;i++)
        {
            if(stu[i].stuscore[3]<sum)
            {
                sum=stu[i].stuscore[3];
                loop=i;
            }
        }
        DispMaxMin(stu[loop],"总成绩最低记录(只找一个)");
    }
}

int  add(struct student stu[],int *size)
{
    int i,j;
    int stunum;
    int number;
    system("cls");
    if(*size>=40)
    {
        gotoxy(30,2);
        printf("数组已满,不能再增加记录!");
        return 0;
    }
    else
    {
        do
        {
            gotoxy(30,2);
            printf("请输入增加的记录个数:");
            scanf("%d",&number);
            if(number<0 || number>=40)
            {
                gotoxy(30,2);
                printf("输入增加记录个数错,请重新输入!");
            }
        }while(number<0 || number>=40);
        stunum=*size+number;
        system("cls");
        gotoxy(33,2);
        printf("学生信息输入!");
        for(i=*size;i<stunum;i++)
        {
            gotoxy(15,5);
            printf("请输入第%d个学生学号:",i+1);
            gotoxy(15,7);
            printf("请输入第%d个学生姓名:",i+1);
            gotoxy(15,9);
            printf("请输入语文成绩:");
            gotoxy(15,11);
            printf("请输入数学成绩:");
            gotoxy(15,13);
            printf("请输入英语成绩:");
            gotoxy(37,5);
            scanf("%d",&stu[i].stunum);
            gotoxy(37,7);
            scanf("%s",stu[i].stuname);
            for(j=0;j<3;j++)
            {
                gotoxy(32,9+j*2);
                scanf("%f",&stu[i].stuscore[j]);
            }
        }
        *size=stunum;
        gotoxy(33,15);
        printf("按任意键返回上级菜单!");
        getch();
        return 1;
    }
}

void Open(struct student stu[],int *size)
{
    int i=0;
    FILE *fp;
    system("cls");
    if((fp=fopen("stuscore","rb"))==NULL)
    {
        printf("文件不能正常打开!\n");
        exit(0);
    }
    else
    {
        while(!feof(fp))
        {
            fread(&stu[i],sizeof(struct student),1,fp);
            i++;
        }
    fclose(fp);
        
    }
    gotoxy(25,5);
    printf("打开文件成功!");
    *size=i-1;//文件中数据个数
    getch();
}

void Save(struct student stu[],int n)
{
    FILE *fp;
    int i;
    system("cls");
    if((fp=fopen("stuscore","wb"))==NULL)
    {
        printf("文件不能正常打开!\n");
        exit(0);
    }
    else
    {
        for(i=0;i<n;i++)
        {
            fwrite(&stu[i],sizeof(struct student),1,fp);
        }
        fclose(fp);

    }
    gotoxy(25,5);
    printf("保存文件成功,按任意键返回上级菜单!");
    getch();

}

void Disp(struct student stu[],int n,char str[])
{
    int i,j;
    system("cls");
    gotoxy(30,2);
    printf("%s\n",str);
    gotoxy(5,4);
    printf("学号     姓名     语文      数学      英语     总成绩   平均成绩");
    for(i=0;i<n;i++)
    {
        gotoxy(5,6+i);
        printf("%-5d",stu[i].stunum);
        printf("%8s",stu[i].stuname);
        for(j=0;j<5;j++)
        {
            printf("%10.1f",stu[i].stuscore[j]);
        }
        printf("\n");

    }
    gotoxy(33,7+n);
    printf("按任意键返回上级菜单!");
    getch();
}

void AsceSort(struct student stu[],int stusize)//按升序排列
{
    int i,j;
    struct student sort[41],s;
    system("cls");
    gotoxy(33,2);
    printf("总成绩按升序排序");
    if(stusize<=0)
    {
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能进行排序操作!");
        getch();
    }
    else
    {
        for(i=0;i<stusize;i++)
            sort[i]=stu[i];
        printf("\n\n");
        for(i=0;i<stusize-1;i++)
        {
            for(j=0;j<stusize-i-1;j++)
            {
                if(sort[j].stuscore[3]>sort[j+1].stuscore[3])
                {
                    s=sort[j];
                    sort[j]=sort[j+1];
                    sort[j+1]=s;
                }
            }
        }
        Disp(sort,stusize,"总成绩按升序排序");
    }
}


void DropSort(struct student stu[],int stusize)//按降序排列
{
    int i,j;
    struct student sort[41],s;
    system("cls");
    gotoxy(33,2);
    printf("总成绩按降序排序");
    if(stusize<=0)
    {
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能进行排序操作!");
        getch();
    }
    else
    {
        for(i=0;i<stusize;i++)
            sort[i]=stu[i];
        printf("\n\n");
        for(i=0;i<stusize-1;i++)
        {
            for(j=0;j<stusize-i-1;j++)
            {
                if(sort[j].stuscore[3]<sort[j+1].stuscore[3])
                {
                    s=sort[j];
                    sort[j]=sort[j+1];
                    sort[j+1]=s;
                }
            }
        }
        Disp(sort,stusize,"总成绩按降序排序");
    }


}


int del(struct student stu[],int *stusize)
{
    int i,k;
    int number;
    int loop=0;//学号输入正确标志
    system("cls");
    gotoxy(33,2);
    printf("删除学生记录!\n");
    if(*stusize<=0)
    {
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能删除记录!");
        getch();
        return 0;
    }
    else
    {
        do
        {
            system("cls");
            gotoxy(33,2);
            printf("删除学生记录!\n");
            gotoxy(28,4);
            printf("请输入被删除学生的学号:");
            scanf("%d",&number);
            for(i=0,k=0;i<*stusize;i++)
            {
                if(number==stu[i].stunum)
                {
                    loop=1;
                    k=i;//被删除记录的下标
                    break;
                }
            }
            if(loop!=1)
            {
                gotoxy(25,6);
                printf("输入学生学号出错,按任意键重新输入!");
                getch();
            }
        }while(loop!=1);
    }
    for(i=k;i<*stusize;i++)//删除操作
    {
        stu[i]=stu[i+1];
    }
    gotoxy(25,6);
    printf("删除成功,按任意键返回上级菜单!");
    *stusize=*stusize-1;
    getch();
    return 1;
}

int modify(struct student stu[],int *stusize)//修改程序
{
    int i,k;
    int number;
    int loop=0;//学号输入正确标志
    system("cls");
    gotoxy(33,2);
    printf("修改学生记录!\n");
    if(*stusize<=0)
    {
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能修改记录!");
        getch();
        return 0;
    }
    else
    {
        do
        {
            system("cls");
            gotoxy(33,2);
            printf("修改学生记录!\n");
            gotoxy(28,4);
            printf("请输入被修改学生的学号:");
            scanf("%d",&number);
            for(i=0,k=0;i<*stusize;i++)
            {
                if(number==stu[i].stunum)
                {
                    loop=1;
                    k=i;//被修改记录的下标
                    break;
                }
            }
            if(loop!=1)
            {
                gotoxy(25,6);
                printf("输入学生学号出错,按任意键重新输入!");
                getch();
            }
        }while(loop!=1);
    }
    system("cls");
    gotoxy(33,2);
    printf("修改学生记录!\n");
    gotoxy(28,4);
    printf("学号:%d",stu[k].stunum);
    gotoxy(28,6);
    printf("姓名:%s",stu[k].stuname);
    gotoxy(28,8);
    printf("语文:%.1f",stu[k].stuscore[0]);
    gotoxy(28,10);
    printf("数学:%.1f",stu[k].stuscore[1]);
    gotoxy(28,12);
    printf("英语:%.1f",stu[k].stuscore[2]);
    gotoxy(34,4);
    scanf("%d",&stu[k].stunum);
    gotoxy(34,6);
    scanf("%s",&stu[k].stuname);
    gotoxy(35,8);
    scanf("%f",&stu[k].stuscore[0]);
    gotoxy(35,10);
    scanf("%f",&stu[k].stuscore[1]);
    gotoxy(35,12);
    scanf("%f",&stu[k].stuscore[2]);
    gotoxy(25,14);
    printf("修改成功,按任意键返回上级菜单!");
    getch();
    return 1;
}

void DispOne(struct student stu[],int n,char str[])
{
    int i,k;
    int number;
    int loop=0;//学号输入正确标志
    if(n<=0)
    {
        system("cls");
        gotoxy(33,2);
        printf("%s\n",str);
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能删除记录!");
        getch();
    }
    else
    {
        do
        {
            system("cls");
            gotoxy(33,2);
            printf("%s\n",str);
            gotoxy(28,4);
            printf("请输入被显示学生的学号:");
            scanf("%d",&number);
            for(i=0,k=0;i<n;i++)
            {
                if(number==stu[i].stunum)
                {
                    loop=1;
                    k=i;//被删除记录的下标
                    break;
                }
            }
            if(loop!=1)
            {
                gotoxy(25,6);
                printf("输入学生学号出错,按任意键重新输入!");
                getch();
            }
        }while(loop!=1);
        system("cls");
        gotoxy(33,2);
        printf("显示单个学生记录!\n");
        gotoxy(5,4);
        printf("学号     姓名     语文      数学      英语     总成绩   平均成绩");
        gotoxy(5,6);
        printf("%-5d",stu[k].stunum);
        printf("%8s",stu[k].stuname);
        for(i=0;i<5;i++)
        {
            printf("%10.1f",stu[k].stuscore[i]);
        }
        printf("\n");
        
        gotoxy(25,8);
        printf("显示成功,按任意键返回上级菜单!");
        getch();
    }
}

void NotElig(struct student stu[],int stusize)//显示不及格记录
{
    int i,j,k=0;
    int loop,notnum=0;
    system("cls");
    if(stusize<=0)
    {
        gotoxy(20,4);
        printf("数组中没有学生记录或文件没有打开,不能显示记录!");
        getch();
    }
    else
    {
        system("cls");
        gotoxy(33,2);
        printf("显示不及格学生记录!\n");
        gotoxy(5,4);
        printf("学号     姓名     语文      数学      英语     总成绩   平均成绩");
        for(i=0;i<stusize;i++)
        {
            loop=0;
            for(j=0;j<3;j++)
            {
                if(stu[i].stuscore[j]<60)
                {
                    loop=1;
                    notnum++;
                    break;
                }
            }
            if(loop==1)
            {
                gotoxy(5,6+k);
                printf("%-5d",stu[i].stunum);
                printf("%8s",stu[i].stuname);
                for(j=0;j<5;j++)
                {
                    printf("%10.1f",stu[i].stuscore[j]);
                }
                k++;
            }
        }
        gotoxy(25,7+k);
        printf("共有%d记录不及格,按任意键返回上级菜单!",notnum);
        getch();
    }
}
搜索更多相关主题的帖子: include modify 子菜单 c语言 记录 
2013-06-21 17:26
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6809
专家分:42393
注 册:2010-12-16
得分:4 
   ...

我行我乐
我的博客:
http://blog.yuccn. net
2013-06-21 17:46
tremere
Rank: 6Rank: 6
来 自:火星
等 级:侠之大者
帖 子:223
专家分:432
注 册:2013-3-11
得分:4 
还能再长点么?

极品菜鸟,来学习啦,啦啦啦啦啦啦啦。。。
2013-06-21 18:31
wp231957
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:4 

DO IT YOURSELF !
2013-06-21 18:32
VRML_0504
Rank: 2
等 级:论坛游民
威 望:1
帖 子:23
专家分:81
注 册:2013-6-7
得分:4 
我想弱弱的问一句,这是楼主自己写的吗?如果楼主能写出来就不会找不到错误原因啦。
2013-06-22 22:49
q13678986740
Rank: 4
等 级:业余侠客
帖 子:114
专家分:245
注 册:2012-7-7
得分:4 
估计是网上复制过来但运行不了的吧
2013-06-23 12:58
q13678986740
Rank: 4
等 级:业余侠客
帖 子:114
专家分:245
注 册:2012-7-7
得分:0 
稍浏览了下,gotoxy.h头文件没有吧
2013-06-23 13:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415757-1-1.html




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

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