十四周任务二

来源:互联网 发布:linux dd u盘 编辑:程序博客网 时间:2024/05/01 10:45

第14周报告2:
实验目的:学会使用循环控制语句解决实际问题
实验内容:用循环控制语句编写程序,完成表达式的计算

* 程序头部注释开始(为避免提交博文中遇到的问题,将用于表明注释的斜杠删除了)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:                             
* 作    者: 董宝文                            
* 完成日期:     2011    年   11    月     25   日
* 版 本 号:         

* 对任务及求解方法的描述部分
* 输入描述:学生人数和成绩
* 问题描述:(函数及数组的简单应用) 在数组score中将要存储某小组C++程序设计的成绩,请设计完成下面功能函数,并将它们组合成一个完整的应用:
(1)输入小组人数及成绩;
(2)输出该小组的最高成绩、最低成绩、平均成绩和成绩的标准偏差;
(3)输出考得最高成绩和最低成绩的同学的人数及对应的学号(设成绩对应的下标即学号,可能有相同的成绩)
* 程序输出:小组的最高成绩、最低成绩、平均成绩和成绩的标准偏差;最高成绩和最低成绩的同学的人数及对应的学号
* 问题分析:……
* 算法设计:……
* 程序头部的注释结束(此处也删除了斜杠)

#include <iostream>#include<Cmath>using namespace std;                            //在这个问题中,成绩和人数是核心数据,适合作为全局变量处理int score[50];               //将score设为全局变量,在各个函数中可以直接使用int n;                     //小组人数也设为全局变量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 main(void){  int max_score,min_score;  cout<<"小组共有多少名同学?";  cin>>n;  cout<<endl<<"请输入学生成绩:"<<endl;  input_score();  //要求成绩在0-100之间  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);     system("PAUSE");  return 0;}// input_score函数提供给同学们参考//input_score函数的功能是输入小组成员的成绩void input_score()void input_score(){    int i;    for(i=0;i<n;i++)       do       {          cout<<"输入第 "<<i<<" 位同学的成绩:";          cin>>score[i];       }while(score[i]<0||score[i]>100);    return; }// get_max_score()函数的功能是求出num名同学的最高成绩int get_max_score(){ int a=0,i=0; do {  if(score[i]>a)   a=score[i];  i++; }while(i<=n); return a;}// get_min_score()函数的功能是求出num名同学的最低成绩int get_min_score(){  int b=101,i=0; for(i=0;i<n;i++) {  if(score[i]<b)  {   b=score[i];  } } return b;}// get_avg_score()函数的功能是求出num名同学的平均成绩double get_avg_score(){ int i; double aver,sum=0; for(i=0;i<n;i++)  sum=sum+score[i]; aver=sum/n; return aver;}// get_ stdev _score()函数的功能是求出num名同学成绩的标准偏差double get_stdev_score(){ int i=0; double t,j,sum=0,m; t=get_avg_score(); for(j=0;j<=n;j++)  sum=sum+(score[i]-t)*(score[i]-t); m=sqrt(sum); return m;}// count(int s)函数的功能是返回值score数组中为s的元素的个数int count(int s){ int i,m=0; for(i=0;i<n;i++) {  if(score[i]==s)  m++; } return m;}// output_index函数的功能是输出score数组中值为s的元素的下标(index)//注意:值为s的元素可能有多个void output_index(int s){  int i,m=0; for(i=0;i<n;i++) {  if(score[i]==s)  {   cout<<i<<',';  } }}




 

第14周报告2:

经验积累:
1.错误出现一个解决一个
上机感言:要学会享受学习到新知识的快乐。。。和朋友们一起享受。。。

原创粉丝点击