| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 427 人关注过本帖
标题:这个代码自己借鉴了一下百度,但还是有错啊,求改错和正确代码
只看楼主 加入收藏
GMZ1993
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-6-6
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
这个代码自己借鉴了一下百度,但还是有错啊,求改错和正确代码
有n个学生,每个学生的数据包括:编号、姓名和三门课程的成绩,编写程序实现以下功能:
(1)自动生成这n个学生的数据。
○1 编号:1~n
○2 姓名:3~10个英文字符构成,首字母大写
○3 三门课程的成绩:60~100以内的整数
(2)输出这n个学生的数据。
(3)计算每门课的平均成绩。
(4)找出总成绩最高和最低的学生,输出他们的编号、姓名、三门课程的成绩、平均成绩和总成绩。
#include "math.h"
#define N 10
struct  student
{
int number;
char name[N];
int score[3];
};
Struct  student studata[N];
int Random(int Low, int High)
{
double result=-1.0;
/* function rand() return a integer between -90 and 32767 */
while(result<=0)
result = rand()/32767.0;
result=result*(double)(High-Low+1)+(double)Low;
return result;
}
void GetName(char name[])
{
int len, i=0;
len=Random(3,10);
name[i]=Random(65,90);
for (i=1; i<len; i++)
name[i]=Random(97,122);
name[i]='\0';
}
void GetData()
{
int I;
for (i=0; i<N; i++)
{
studata[i].number = i+1;
GetName(studata[i].name);
studata[i].score[0]=Random(60,100);
studata[i].score[1]=Random(60,100);
studata[i].score[2]=Random(60,100);
}
}
void AverageScore()
{
int i,j;
int sum[3]={0, 0, 0};
for (i=0; i<N; i++)
for (j=0; j<3; j++)
sum[j]+=studata[i].score[j];
printf("\nAverage score of three subjects: %.2f\t%.2f\t%.2f\n", sum[0]/10.0,
sum[1]/10.0, sum[2]/10.0);
}
void FindPeak()
{
int maxbound=0, minbound=0;
int max=0, min=300;
int sum=0, i;
for (i=0; i<N; i++)
{
sum=studata[i].score[0]+studata[i].score[1]+studata[i].score[2];
if (sum>max)
{
maxbound=i;
max=sum;
}
else if (sum<min)
{
minbound=i;
min=sum;
}
}
printf("\nThe highest score:\n");
printf(" Student %d\n", studata[maxbound].number);
printf(" Name: %s\n", studata[maxbound].name);
printf("Scores of three subjects: %d, %d, %d\n",studata[maxbound].score[0],
studata[maxbound].score[1],studata[maxbound].score[2]);
printf(" Total score: %d\n", max);
printf(" Average score: %.2f\n", max/3.0);
printf("\nThe lowest score:\n");
printf(" Student %d\n", studata[minbound].number);
printf(" Name: %s\n", studata[minbound].name);
printf("Scores of three subjects: %d, %d, %d\n", studata[minbound].score[0],
studata[minbound].score[1], studata[minbound].score[2]);
printf(" Total score: %d\n", min);
printf(" Average score: %.2f\n", min/3.0);
}
void PrintData()
{
int i;
for (i=0; i<N; i++)
{
printf("Student %d:\n", studata[i].number);
printf("Name: %s\n", studata[i].name);
printf("Scores of three subjects: %d, %d, %d\n", studata[i].score[0],
studata[i].score[1], studata[i].score[2]);
}
}
void main()
{
GetData();
PrintData();
AverageScore();
FindPeak();
}
搜索更多相关主题的帖子: 总成绩 number 百度 include 编写程序 
2013-06-06 23:35
蚕头燕尾
Rank: 10Rank: 10Rank: 10
来 自:Gryffindo
等 级:贵宾
威 望:12
帖 子:734
专家分:1546
注 册:2013-3-24
收藏
得分:20 
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define N 10

struct  student
{
    int number;
    char name[N];
    int score[3];
};
struct  student studata[N];

int Random(int Low,int High)
 {
    double result=-1.0;
/* function rand() return a integer between -90 and 32767 */
    while(result<=0)
    result = rand()/32767.0;

    result=result*(double)(High-Low+1)+(double)Low;

    return result;
}
void GetName(char name[])
 {
    int len, i=0;
    len=Random(3,10);
    name[i]=Random(65,90);

    for (i=1; i<len; i++)
        name[i]=Random(97,122);
   
    name[i]='\0';
}
void GetData()
 {
    int i;
    for (i=0; i<N; i++)
    {
        studata[i].number = i+1;
        GetName(studata[i].name);
        studata[i].score[0]=Random(60,100);   
        studata[i].score[1]=Random(60,100);
        studata[i].score[2]=Random(60,100);
    }
 }
void AverageScore()
{
    int i,j;
    int sum[3]={0, 0, 0};

    for (i=0; i<N; i++)
        for (j=0; j<3; j++)
            sum[j]+=studata[i].score[j];

    printf("\nAverage score of three subjects: %.2f\t%.2f\t%.2f\n", sum[0]/10.0,sum[1]/10.0, sum[2]/10.0);
}
void FindPeak()
 {
    int maxbound=0, minbound=0;
    int max=0, min=300;
    int sum=0, i;
    for(i=0; i<N; i++)
    {
        sum=studata[i].score[0]+studata[i].score[1]+studata[i].score[2];
        if (sum>max)
        {
            maxbound=i;
            max=sum;
        }
        else if(sum<min)
        {
            minbound=i;
            min=sum;
        }
    }
    printf("\nThe highest score:\n");
    printf(" Student %d\n", studata[maxbound].number);
    printf(" Name: %s\n", studata[maxbound].name);
    printf("Scores of three subjects: %d, %d, %d\n",studata[maxbound].score[0],
    studata[maxbound].score[1],studata[maxbound].score[2]);
    printf(" Total score: %d\n", max);
    printf(" Average score: %.2f\n", max/3.0);
    printf("\nThe lowest score:\n");
    printf(" Student %d\n", studata[minbound].number);
    printf(" Name: %s\n", studata[minbound].name);
    printf("Scores of three subjects: %d, %d, %d\n", studata[minbound].score[0],studata[minbound].score[1], studata[minbound].score[2]);
    printf(" Total score: %d\n", min);
    printf(" Average score: %.2f\n", min/3.0);
}
void PrintData()
{
    int i;
    for(i=0; i<N; i++)
    {
    printf("Student %d:\n", studata[i].number);
    printf("Name: %s\n", studata[i].name);
    printf("Scores of three subjects: %d, %d, %d\n", studata[i].score[0],studata[i].score[1], studata[i].score[2]);
    }
}
void main()
{
    GetData();
    PrintData();
    AverageScore();
    FindPeak();
}

学习编程,为的是表达自己的思想,而不是被别人的思想所禁锢。要先明白自己想干嘛,而不要先问别人让你干嘛。               

                                                                                                                    Black Cat      Hello Tomorrow~
2013-06-06 23:52
快速回复:这个代码自己借鉴了一下百度,但还是有错啊,求改错和正确代码
数据加载中...
 
   



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

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