设为首页 加入收藏

TOP

mistake-输出前三名成绩(一)
2013-02-08 14:32:19 】 浏览:1485
Tags:mistake- 输出 成绩

    [cpp]

    /*

    【项目2- 成绩处理】在数组score中将要存储某小组C++(www.cppentry.com)程序设计的成绩,请设计完成下面的各功能函数,并将它们组合成一个完整的应用:

    (1)输入小组人数及成绩;

    (2)输出该小组的最高成绩、最低成绩、平均成绩和成绩的标准偏差(标准偏差公式:,其中为样本,为均值,为样本数目);

    (3)输出考得最高成绩和最低成绩的同学的人数及对应的学号(设成绩对应的下标即学号,可能有相同的成绩)

    (4)(选做)输出前3名同学的学号--可以先不考虑有并列名次的情况,再考虑有并列的情况。

    */

    #include <iostream>

    #include<Cmath>

    using namespace std;

    //在这个问题中,成绩和人数是核心数据,适合作为全局变量处理

    int score[50];    //将score设为全局变量,在各个函数中可以直接使用

    int num;        //小组人数也设为全局变量

    void input_score();

    int get_max_score();

    int get_min_score();

    double get_avg_score();

    double get_stdev_score();

    int count(int);

    void output_index(int);

    int firstthree(int);

    int max_score,min_score,i,max,min,mean_score;

    int main(void)

    {

    cout《"小组共有多少名同学?";

    cin》num;

    for(i=0;i<num;i++){

    cout《"请输入第"《i《"位学生成绩:"《endl;

    cin》score[i];

    }

    input_score();

    if((score[i]<0)||(score[i]>100)){

    cout《"error"《endl;}

    //要求成绩在0-100之间

    else

    {

    max_score=get_max_score();

    cout《endl《"最高成绩为:"《max_score《",共有 "《count(max_score )《" 人。";

    min_score=get_min_score();

    cout《endl《"最低成绩为:"《min_score《",共有 "《count(min_score )《" 人。";

    cout《endl《"平均成绩为:"《get_avg_score();

    cout《endl《"标准偏差为:"《get_stdev_score();

    cout《endl《"获最高成绩的学生(学号)有:";

    output_index(max_score);

    cout《endl《"获最低成绩的学生(学号)有:";

    output_index(min_score);

    cout《endl《"前三名成绩:";

    }

    return 0;

    }

    //input_score函数提供给同学们参考

    //input_score函数的功能是输入小组成员的成绩

    void input_score()

    {

    int i;

    for(i=0;i<num;i++)

    do

    {

    cout《"输入第 "《i《" 位同学的成绩:";

    cin》score[i];

    }while(score[i]<0||score[i]>100);

    return;

    }

    // get_max_score()函数的功能是求出num名同学的最高成绩

    int get_max_score()

    {

    max=-1;

    for(i=0;i<num;i++)

    if(max<score[i])

    max=score[i];

    return max;

    }

    // get_min_score()函数的功能是求出num名同学的最低成绩

    int get_min_score()

    {

    min=100;

    for(i=0;i<num;i++)

    if(min>score[i])

    min=score[i];

    return min;

    }

     

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇颜色对话框使用实例 下一篇A Round Peg in&n..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目