第十三周项目3 成绩统计函数版本

来源:互联网 发布:淘宝如何图片搜索 编辑:程序博客网 时间:2024/06/05 01:53
/**Copyright (c)2014,烟台大学计算机与控制工程学院*All rights reserved.*文件名称:test.cpp*作    者:anGelovEr 王坤*完成日期:2014年11月23日*版 本 号:v1.0**问题描述:成绩统计(函数版)*程序输出:最高分最低分平均分标准差等。*/#include<iostream>#include<cstdio>#include<cmath>using namespace std;void input_score(int s[], int n); //将小组中n名同学的成绩输入数组sint get_max_score(int s[], int n);  //返回数组s中n名同学的最高成绩值int get_min_score(int s[], int n);  //返回数组s中n名同学的最低成绩值double get_avg_score(int s[], int n);  //返回数组s中n名同学的平均成绩值double get_stdev_score(int s[], int n); //返回数组s中n名同学成绩值的标准偏差int count(int x, int s[], int n);  //返回在数组s中n名同学中有多少人得x分(实参给出最高/低时,可以求最高/低成绩的人数)void output_index(int x, int s[], int n); //在函数中输出数组s中n名同学中得x分的学号(下标)int main(void){    int score[50]; //将score设为局部变量,通过数组名作函数参数,传递数组首地址,在函数中操作数组    int num;       //小组人数也设为局部变量,将作为函数的实际参数    int max_score,min_score;    cout<<"小组共有多少名同学?";    cin>>num;    cout<<endl<<"请输入学生成绩:"<<endl;    input_score(score, num);  //要求成绩在0-100之间    max_score=get_max_score(score, num);    cout<<endl<<"最高成绩为:"<<max_score<<",共有 "<<count(max_score, score, num )<<" 人。";    min_score=get_min_score(score, num);    cout<<endl<<"最低成绩为:"<<min_score<<",共有 "<<count(min_score,score, num )<<" 人。";    cout<<endl<<"平均成绩为:"<<get_avg_score(score, num);    cout<<endl<<"标准偏差为:"<<get_stdev_score(score, num);    cout<<endl<<"获最高成绩的学生(学号)有:";    output_index(max_score,score, num);    cout<<endl<<"获最低成绩的学生(学号)有:";    output_index(min_score,score, num);    cout<<endl;    return 0;}void input_score(int s[], int n)  //将小组中n名同学的成绩输入数组s{    int i=1;    while(i<=n) //输入num名同学的成绩    {        cout<<"请输入第"<<i<<"位同学的成绩:";        cin>>s[i];        if(s[i]>=0&&s[i]<=100)  //成绩范围为0-100            ++i;        else            cout<<"请检查数据并重新输入学生成绩(0-100):"<<endl;  //输入错误后要重新输入    }}int get_max_score(int s[], int n)  //返回数组s中n名同学的最高成绩值{    int max,j;    max=-1;    for(j=1; j<=n; j++)    {        if(s[j]>max)            max=s[j];    }    return (max);}int get_min_score(int s[], int n)  //返回数组s中n名同学的最低成绩值{    int min,j;    min=101;    for(j=1; j<=n; j++)    {        if(s[j]<min)            min=s[j];    }    return (min);}double get_avg_score(int s[], int n)  //返回数组s中n名同学的平均成绩值{    int j;    double sum=0;    for(j=1; j<=n; j++)        sum+=s[j];    return (sum/n);}double get_stdev_score(int s[], int n)  //返回数组s中n名同学成绩值的标准偏差{    double m=0;    int x,y,j;    for(j=1; j<=n; j++)    {        x=s[j]-(get_avg_score(s, n));        y=x*x;        m+=y;    }    return (sqrt(m/(n-1)));}int count(int x, int s[], int n)  //返回在数组s中n名同学中有多少人得x分(实参给出最高/低时,可以求最高/低成绩的人数){    int j,count=0;    for(j=1; j<=n; j++) //求出并输出考得最高成绩和最低成绩人数    {        if(s[j]==x)            count++;    }    return (count);}void output_index(int x, int s[], int n)  //在函数中输出数组s中n名同学中得x分的学号(下标){    int j;    for(j=1; j<=n; j++)  //再次筛选出考得最高成绩和最低成绩的学号    {        if(s[j]==x)            cout<<j<<" ";    }}

知识点总结:太长了……

学习心得:太费事了……果然需要team啊

0 0