| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 558 人关注过本帖
标题:有没人可以帮我改改?
只看楼主 加入收藏
awdclijn
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-1
收藏
 问题点数:0 回复次数:4 
有没人可以帮我改改?
自己写的学生成绩管理系统,蛮多错误不知怎么改。请高手帮帮手。
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#define TOTAL 30
void menu();
int save();
int read();
void input();
void count();
void order();
void check();
void insert();
void modify();
void del();
struct student
    {int cla[20];
    int num;
    char name[8];
    float math;
    float c_prog;
    float eng;
    float polity;
    float sport;
    float ave;
    int order;
    };
    struct student stu[TOTAL];
void main()
{menu();}
void menu()
{        
printf("*************学生成绩管理系统*************\n");
printf("******************************************\n");
printf("**               1输入                 ***\n");
printf("**               2统计                 ***\n");
printf("**               3排序                 ***\n");
printf("**               4查询                 ***\n");
printf("**               5插入                 ***\n");
printf("**               6修改                 ***\n");
printf("**               7删除                 ***\n");
printf("**               0退出                 ***\n");
printf("******************************************\n");
printf("******************************************\n");
int choice;
printf("请选择(0-7):");
scanf("%d",&choice);
switch(choice)
    {    case 0:exit(0);break;
    case 1:input();break;
    case 2:count();break;
    case 3:order();break;
    case 4:check();break;
    case 5:insert();break;
    case 6:modify();break;
    case 7:del();break;
    }
}


int save(int n)
{
    FILE * fp;
    int i;
    if((fp=fopen("stu.txt","wb"))==NULL)
    {    printf("\nCan not open\n");
        exit(0);
    }
    printf("FILE'stu.txt':");
        for(i=0;fwrite(&stu[i],sizeof(struct student),1,fp)!=0;i++)
            printf("file write error\n");
            fclose(fp);
            exit(0);
    for(i=0;!feof(fp);i++)
    fread(&stu,sizeof(struct student),1,fp);
    fclose(fp);
    return(i);
}
int read()
{
    FILE*fp;int i;
    if((fp=fopen("stu.txt","wb"))==NULL)
    {    printf("\nCan not open\n");
        return NULL;
    }
        for(i=0;!feof(fp);i++)
        fread(&stu,sizeof(struct student),1,fp);
        fclose(fp);
        return(i-1);
}
void input()
{   int i=1;
    char c;
    do
    {printf("现在录入学生成绩\n输入第%d个学生的信息\n",i);
    printf("请输入姓名:");
    scanf("%s",stu[i].name);
    fflush(stdin);
    printf("请输入班级:");
    scanf("%d",stu[i].cla);
    fflush(stdin);
    printf("请输入学号:");    
    scanf("%d",stu[i].num);
    fflush(stdin);
    printf("请输入数学成绩");
    scanf("%f",stu[i].math);
    fflush(stdin);
    printf("请输入C语言成绩");
    scanf("%f",stu[i].c_prog);
    fflush(stdin);
    printf("请输入英语成绩");
    scanf("%f",stu[i].eng);
    fflush(stdin);
    printf("请输入政绩成绩");
    scanf("%f",stu[i].polity);
    fflush(stdin);
    printf("请输入体育成绩");
    scanf("%f",stu[i].sport);
    fflush(stdin);
    i++;
    printf("是否继续输入?(Y/N)");
    fflush(stdin);
    c=getchar();
    }while(c=='y'&&c=='Y');
    system("cls");


}
void count()
{   int i;
    float sum;
    for(i=0;i<TOTAL;i++)
    sum+=stu[i].math+stu[i].c_prog+stu[i].eng+stu[i].polity+stu[i].sport;
    stu[i].ave=sum/5;
}
void order()
{  
    float temp;int Q,i,j;
    for(i=0;i<Q;i++)
        for(j=i+1;j<Q;j++)
            if(stu[i].ave<stu[j].ave)
            {temp=stu[i].ave;
             stu[i].ave=stu[j].ave;
             stu[j].ave=temp;}
}
void cheak()
{
    int i;
    printf("\n\tNo\t\tName\t\tMath\t\tc_prog\t\tEng\t\tPolity\t\tSport\t\n");
    for(i=0;i<TOTAL;i++)
        void count();
        printf("%12d%12s%7f%7f%7f%7f%7f%10.2f",
            stu[i].num,stu[i].name,stu[i].math,stu[i].c_prog,stu[i].eng,stu[i].polity,stu[i].sport);
 
}
void insert()
{
    FILE*fp,*fp1;
    int i,t,n;
        printf("\n请输入学号:");
        scanf("%s",stu[i].num);
        fflush(stdin);
        printf("请输入姓名:");
        scanf("%s",stu[i].name);
        fflush(stdin);
        printf("请输入班级:");
        scanf("%d",stu[i].cla);
        fflush(stdin);
        printf("请输入数学成绩");
        scanf("%f",stu[i].math);
        fflush(stdin);
        printf("请输入C语言成绩");
        scanf("%f",stu[i].c_prog);
        fflush(stdin);
        printf("请输入英语成绩");
        scanf("%f",stu[i].eng);
        fflush(stdin);
        printf("请输入政绩成绩");
        scanf("%f",stu[i].polity);
        fflush(stdin);
        printf("请输入体育成绩");
        scanf("%f",stu[i].sport);
        fflush(stdin);
        
        if((fp=fopen("stu.txt","wb"))==NULL)
            {printf("\nCan not open\n");
        exit(0);
            }
        printf("Originaldata:\n");
        for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
        {
            printf("\n%12d%12s",stu[i].num,stu[i].name);
            printf("%4d",stu[i].cla);
            printf("%4f",stu[i].math);
            printf("%4f",stu[i].c_prog);
            printf("%4f",stu[i].eng);
            printf("%4f",stu[i].polity);
            printf("%4f",stu[i].sport);
            printf("%6.2f",stu[i].ave);
        }
        n=i;for(t=0;stu[t].ave>stu[n].ave&&t<n;t++)
            printf("\nNOw:\n");
            fp1=fopen("stu.txt","w");
            for(i=0;i<t;i++)
            {
                fwrite(&stu[i],sizeof(struct student),1,fp1);
                printf("\n%12d%12s",stu[i].num,stu[i].name);
                printf("%4d",stu[i].cla);
                printf("%4f",stu[i].math);
                printf("%4f",stu[i].c_prog);
                printf("%4f",stu[i].eng);
                printf("%4f",stu[i].polity);
                printf("%4f",stu[i].sport);
                printf("%6.2f",stu[i].ave);
            }
            fwrite(&stu[i],sizeof(struct student),1,fp1);
            printf("\n%12d%12s%7d%7d%7d%7d%7d%10.2f",stu[i].num,stu[i].name,stu[i].math,stu[i].c_prog,stu[i].eng,stu[i].polity,stu[i].sport,stu[i].ave);
            for(i=t;i<n;i++)
            {
                fwrite(&stu[i],sizeof(struct student),1,fp1);
                printf("\n%12d%12s",stu[i].num,stu[i].name);
                printf("%4d",stu[i].cla);
                printf("%4f",stu[i].math);
                printf("%4f",stu[i].c_prog);
                printf("%4f",stu[i].eng);
                printf("%4f",stu[i].polity);
                printf("%4f",stu[i].sport);
                printf("10.2f",stu[i].ave);
            }
            printf("\n");
            fclose(fp);
            fclose(fp1);
}
void modify()
{
    int i;char str[20];
    printf("输入需要修改的学生的姓名:");
    gets(str);
    for(i=0;i<TOTAL;i++)
    {if(str==stu[i].name)
    {
        printf("请输入学号:");
        scanf("%d",&stu[i].num);
        printf("请输入班级:");
        scanf("%d",stu[i].cla);
        fflush(stdin);
        printf("请输入数学成绩");
        scanf("%f",stu[i].math);
        fflush(stdin);
        printf("请输入C语言成绩");
        scanf("%f",stu[i].c_prog);
        fflush(stdin);
        printf("请输入英语成绩");
        scanf("%f",stu[i].eng);
        fflush(stdin);
        printf("请输入政绩成绩");
        scanf("%f",stu[i].polity);
        fflush(stdin);
        printf("请输入体育成绩");
        scanf("%f",stu[i].sport);
        fflush(stdin);
    }
    else printf("查无此人,请重新输入:");
    }
}
void del()
{   int i,j,n,flag;char name[20];FILE*fp;
    if((fp=fopen("stu.txt","wb"))==NULL)
    {printf("\nCan not open\n");
    exit(0);
    }
    printf("\noriginal data:\n");
    for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
        printf("\n%12d%12s",stu[i].num,stu[i].name);
        printf("%4d",stu[i].cla);
        printf("%7f",stu[i].math);
        printf("%7f",stu[i].c_prog);
        printf("%7f",stu[i].eng);
        printf("%7f",stu[i].polity);
        printf("%7f",stu[i].sport);
        printf("10.2f",stu[i].ave);
            fclose(fp);
        n=i;
        printf("请输入要删除的姓名\n");
        scanf("%s",name);
            for(flag=1,i=0;flag&&i<n;i++)
            {
                if(strcmp(name,stu[i].name)==0)
                {
                    for(j=i;j<n-1;j++)
                    {
                        strcpy(stu[j].name,stu[j+1].name);
                        stu[j].num=stu[j+1].num;
                    
                        stu[j].math=stu[j+1].math;
                        stu[j].c_prog=stu[j+1].c_prog;
                        stu[j].eng=stu[j+1].eng;
                        stu[j].polity=stu[j+1].polity;
                        stu[j].sport=stu[j+1].sport;
                        stu[j].ave=stu[j+1].ave;
                    }flag=0;
                }
            }
            if(flag!=0)
                n=n-1;
            else printf("\nNOt found!");
            printf("\nNow,the content of file:\n");
            if((fp=fopen("stu.txt","wb"))==NULL)
            {
                printf("Can not open\n");
                exit(0);
            }
            for(i=0;i<n;i++)
                fwrite(&stu[i],sizeof(struct student),1,fp);
            fclose(fp);
            fp=fopen("stu.txt","r");
            for(i=0;fread(&stu[i],sizeof(struct student),1,fp)!=0;i++)
                printf("\n%12d%12s",stu[i].num,stu[i].name);
                printf("%4d",stu[i].cla);
                printf("%7f",stu[i].math);
                printf("%7f",stu[i].c_prog);
                printf("%7f",stu[i].eng);
                printf("%7f",stu[i].polity);
                printf("%7f",stu[i].sport);
                printf("10.2f",stu[i].ave);
                    printf("\n");
                fclose(fp);                
}
搜索更多相关主题的帖子: 改改 
2008-10-01 17:36
沼泽
Rank: 4
等 级:业余侠客
威 望:8
帖 子:291
专家分:228
注 册:2008-9-15
收藏
得分:0 
从表面上是你的函数名 void check写成了void cheak
2008-10-02 16:51
Q_Q
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-4-17
收藏
得分:0 
嗯,就是
2008-10-02 17:06
yizishashou
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2008-10-2
收藏
得分:0 
1
void menu()
{    .....     
switch(choice)
    {    case 0:exit(0);break;
    case 1:input();break;
    case 2:count();break;
    case 3:order();break;
    case 4:check();break;
    case 5:insert();break;
    case 6:modify();break;
    case 7:del();break;
    default: ... ;
    }
}
switch语句中查询完以后最好加一行:default:输出报错或者是一个跳转循环语句
因为你的choice可能输入0-7这之外的数,这样写更严谨一点,而且不会因输错重新运行程序
2008-10-02 19:31
yizishashou
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2008-10-2
收藏
得分:0 
2
你的order()函数里面的Q有值吗,Q应该是成绩表里学生的个数,它是怎样得到的?
还有你的成绩表即结构体里struct student stu[TOTAL]要不要赋一些初值,我要是直接统计或者排序怎么办,会输出什么?一点小的建议

[[it] 本帖最后由 yizishashou 于 2008-10-2 21:44 编辑 [/it]]
2008-10-02 20:10
快速回复:有没人可以帮我改改?
数据加载中...
 
   



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

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