第13周项目3-自定义版成绩处理

/*
 *Copyright (c) 2014, 烟台大学计算机学院
 *All rights reserved.
 *文件名称:week13-project3.cpp
 *作者:高赞
 *完成日期:2014年 11 月 22 日
 *版本号:v1.0
 *
 *问题描述:用自定义函数完成项目2
 */
#include <iostream>
#include <cmath>
using namespace std;
void input_score(int s[], int n); //将小组中n名同学的成绩输入数组s
int 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分(实参给出最高/低时,可以求最高/低成绩的人数)
double average;
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<<"小组共有多少名同学?"<< endl;
    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 score[], int num)
{
    for (int i=0; i<num; ++i)
    {
        cout << "请输入学号为" << i << "的同学的成绩:";
        cin >> score[i];
        while(score[i]<0 || score[i]>100)
        {
            cout << "数据错误,成绩应在0-100之内,重新输入:";
            cin >> score[i];
        }
    }
    cout << endl;
}

int get_max_score(int score[], int num)   //返回数组s中n名同学的最高成绩值
{
    int max=0;
    for (int i=0; i<num; ++i)
    {
        if (score[i]>max)
            max=score[i];
    }
    return max;
}

int get_min_score(int score[], int num)   //返回数组s中n名同学的最低成绩值
{
    int min=100;
    for (int i=0; i<num; ++i)
    {
        if (score[i]<min)
            min=score[i];
    }
    return min;
}

double get_avg_score(int score[], int num)   //返回数组s中n名同学的平均成绩值
{
    double sum=0;
    for (int i=0; i<num; ++i)
        sum+=score[i];
    average=sum/num;
    return average;
}

double get_stdev_score(int score[], int num)  //返回数组s中n名同学成绩值的标准偏差
{
    double s=0,S;
    for (int i=0; i<num; ++i)
    {
        double x=pow(score[i]-average,2);
        s+=x;
    }
    S=sqrt(s/(num-1));
    return S;
}

int count(int x, int score[], int num)   //返回在数组s中n名同学中有多少人得x分(实参给出最高/低时,可以求最高/低成绩的人数)
{
    int n=0;
    for (int i=0; i<num; ++i)
    {
        if(x==score[i])
            ++n;
    }
    return n;
}

void output_index(int x, int score[], int num)  //在函数中输出数组s中n名同学中得x分的学号(下标)
{
    for (int i=0; i<num; ++i)
    {
        if(x==score[i])
            cout<<i<<" ";
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的精简博客系统,源码+数据库+毕业论文+视频演示 当下,正处于信息化的时代,许多行业顺应时代的变化,结合使用计算机技术向数字化、信息化建设迈进。以前企业对于博客信息的管理和控制,采用人工登记的方式保存相关数据,这种以人力为主的管理模式已然落后。本人结合使用主流的程序开发技术,设计了一款基于Springboot开发的精简博客系统,可以较大地减少人力、财力的损耗,方便相关人员及时更新和保存信息。本系统主要使用B/S开发模式,在idea开发平台上,运用Java语言设计相关的系统功能模块,MySQL数据库管理相关的系统数据信息,SpringBoot框架设计和开发系统功能架构,最后通过使用Tomcat服务器,在浏览器中发布设计的系统,并且完成系统与数据库的交互工作。本文对系统的需求分析、可行性分析、技术支持、功能设计、数据库设计、功能测试等内容做了较为详细的介绍,并且在本文中也展示了系统主要的功能模块设计界面和操作界面,并对其做出了必要的解释说明,方便用户对系统进行操作和使用,以及后期的相关人员对系统进行更新和维护。本系统的实现可以极大地提高企业的工作效率,提升用户的使用体验,因此在现实生活中运用本系统具有很大的使用价值。 关键词:博客管理;Java语言;B/S结构;MySQL数据库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值