| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2225 人关注过本帖
标题:我想写一个学生成绩录入系统,用结构体写,主程序和函数的传递出了问题,我 ...
取消只看楼主 加入收藏
coolnanlove
Rank: 1
等 级:新手上路
帖 子:17
专家分:7
注 册:2011-12-5
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:1 
我想写一个学生成绩录入系统,用结构体写,主程序和函数的传递出了问题,我实在无法检查出错误在哪,求高手帮忙
#include<stdio.h>
#include<string.h>
#define N 3
struct student
{
    int num[20];
    char name[30];
    float chinese,math,english;
};
int login();                                                       //登录模块
void menu();                                                       //菜单
int input(struct student stu[],int length);                        //输入模块
void output(struct student stu[],int length);                      //输出模块
void querybyname(struct student stu[],int length,char *name );          //通过姓名搜索
void statistic(struct student stu[],int length);                   //统计模块
void foundmax(struct student stu[],int length);                    //查找最大值  
void sort(struct student *p,int length);                           //排序模块
int main()
{
    int p,n,m;
    struct student stu[60];
    char queryname[30];
    p=login();
        if(p==1)
    {
            while(1)
        {
                menu();
                scanf("%d",&n);
                switch(n)
                {
                    case 1:    m=input(stu,60);
                            printf("已输入%d",m);
                            break;
                    case 2:output(stu,m);
                           break;
                    case 3:printf("请输入查询姓名:/n");
                           puts(queryname);
                           querybyname(stu,m,queryname );
                           break;
                    case 4:foundmax(stu,m);
                              output(stu,m);
                           break;
                    case 5:statistic(stu,m);
                           break;
                    case 6:foundmax(stu,m);
                           break;
               
                }
        }
    }
    return 0;

}
int login()
{
    char password[20];
    int i=0,n=0;
    printf("请输入密码:");
    while(i<3&&n!=1)
    {
        scanf("%s",password);
            if(strcmp(password,"coolnan")==0||strcmp(password,"love")==0)
        {
                n=1;
        }
            else
                i++;
    }
    return n;
}

void menu()
{
    int n;
    printf(" |            学生成绩管理系统V2.0              |\n");
    printf(" |  ******************************************  |\n");
    printf(" |  ***************1.成绩输入*****************  |\n");
    printf(" |  ***************2.成绩输出*****************  |\n");
    printf(" |  ***************3.成绩查询*****************  |\n");
    printf(" |  ***************4.成绩排序*****************  |\n");
    printf(" |  ***************5.成绩统计*****************  |\n");
    printf(" |  ***************6.成绩查询最大值***********  |\n");
    printf(" |  ******************************************  |\n");
    printf("请输入操作顺序:");
int input(struct student stu[],int length)                                                                                 //输入模块
{
    int i;
    printf("请分别输入学号,姓名,语文 数学 英语成绩:\n");
    for(i=0;i<length;i++)
    {
        scanf("%s%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].chinese,&stu[i].math,&stu[i].english);
        if(strcmp(stu[i].name,"none")==0)
            return i;
        
    }

}
void output(struct student stu[],int length)                                                                              //输出模块
{
    int i;
    printf("姓名,学号,语文 数学 英语成绩:\n");
    for(i=0;i<length;i++)
    {
        scanf("%s\n%s\n%f\n%f\n%f\n",&stu[i].num,stu[i].name,&stu[i].chinese,&stu[i].math,&stu[i].english);
    }
}
void querybyname(struct student stu[],int length,char *name )
{
    int i;
    for(i=0;i<length;i++)
    {
        if(    strcmp(stu[i].name,name)==0)
        {
        scanf("%s\n%s\n%f\n%f\n%f\n",&stu[i].num,stu[i].name,&stu[i].chinese,&stu[i].math,&stu[i].english);
        }
   
    }
}
void sort(struct student *p,int length)                                                                                   //排序模块
{
    int i,j;
    struct student t;
    for(i=0;i<length;i++)
    {
        for(j=0;j<length-i-1;i++)
        {
        if(p[j].chinese>p[j+1].chinese)
        {
            t=p[j];
            p[j]=p[j+1];
            p[j+1]=p[j];
        }
        }

    }
}
void statistic(struct student stu[],int length)                                                                           //统计模块
{
    int i,result[5]={0};
    for(i=0;i<length;i++)
    {
    if(p[i].chinese>=0&&p[i].chinese<=59)
        resulr[0]++;
     else if(p[i].chinese>=60&&p[i].chinese<=69)
        result[1]++;
        else if(p[i].chinese>=70&&p[i].chinese<=79)
            result[2]++;
            else if(p[i].chinese>=80&&p[i].chinese<=89)
                result[3]++;
                else if(p[i].chinese>=90&&p[i].chinese<=99)
                    result[4]++;
    }
    {
        printf("0-59分的人数为%d\n",result[0]);
        printf("60-69分的人数为%d\n",result[1]);
        printf("70-79分的人数为%d\n",result[2]);
        printf("80-89分的人数为%d\n",result[3]);
        printf("90-99分的人数为%d\n",result[4]);
    }
}
void foundmax(struct student stu[],int length)                                                                           //查询成绩最大值模块
{
    int max1=0,max2=0,max3=0;
    int i,j;
    for(i=0;i<length;i++)
    {
        for(i=0;i<length-1;i++)
        {
        if(stu[i].chinese>max1)
        {
        stu[i].chinese=max1;
        }
        }
        printf("语文成绩排序:\n")
        printf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].chinese);
    }


        for(i=0;i<length;i++)
    {
        for(i=0;i<length-1;i++)
        {
        if(stu[i].math>max1)
        {
        stu[i].math=max1;
        }
        }
        printf("数学成绩排序:\n")
        printf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].math);
    }



        for(i=0;i<length;i++)
    {
        for(i=0;i<length-1;i++)
        {
        if(stu[i].english>max1)
        {
        stu[i].english=max3;
        }
        }
        printf("英语成绩排序:\n")
        printf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].english);
    }
    return 0;
}
  
搜索更多相关主题的帖子: 检查 english include 结构体 主程序 
2011-12-27 23:17
coolnanlove
Rank: 1
等 级:新手上路
帖 子:17
专家分:7
注 册:2011-12-5
收藏
得分:0 
这样是没有问题了,可是输入过程怎么输入none停不住呢
2011-12-28 00:42
快速回复:我想写一个学生成绩录入系统,用结构体写,主程序和函数的传递出了问题 ...
数据加载中...
 
   



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

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