第14週報告2:計算グループの成績

4271 ワード

    :                
    :           ,        

*         (             ,             )
*             
* Copyright (c) 2011,            
* All rights reserved.
*     :                                    
*       :                                
*     :2011   11   24  
*    :x1.0         

*              
*     :       
*     :(          )    score        C++       ,           ,              :
(1)         ;
(2)          、    、            ;
(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 main(void)
{
  int max_score,min_score;
  cout<<"         ?";
  cin>>num;
  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()
{
    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()
{
 double max=score[0];
    int i;
    for(i=0;i<num;i++)
    {
  if(score[i]>max)
   max=score[i];
 }
    return max;
}
// get_min_score()        num        
int get_min_score()
{
    int min=score[0],i;
    for(i=0;i<num;i++)
    {
  if(score[i]<min)
   min=score[i];
 }
    return min;
}

// get_avg_score()        num        
double get_avg_score()
{
 double aver;
    int i,sum=0;
    for(i=0;i<num;i++)
 {
  sum=sum+score[i];
  aver=double(sum)/num;
 }
 return aver;
}

// get_ stdev _score()        num          
double get_stdev_score()
{
 double s,m,y,h;
    int i,sum=0;
 m=get_avg_score();
    for(i=0;i<num;i++)
 {
  y=(score[i]-m)*(score[i]-m);
        sum=sum+y;
  h=sum/(num-1);
        s=sqrt(h);
 }
 return s;
}

// count(int s)         score    s      
int count(int s)
{
 int m=0,i;
    for(i=0;i<num;i++)
 {
  if (score[i]==s)
   m++;
 }
 return m;
}


// output_index        score     s      (index)
//  :  s        
void output_index(int s)
{
 int m,i;
    for(i=0;i<num;i++)
 {
  if (score[i]==s)
  {
   m=i;
      cout<<m<<'\t';
  }
 }
}
実行結果:
経験の蓄積:1.まじめに考えて、教科書をよく見なさい.2.コミュニケーションをとる.
上机感言:このプログラムは少し难しいですね.私は长い间やっても结果が出ませんでした.ずっと理解していませんでした.int count(int s)という関数はどのように最大値と最小値の个数を返すことができますか.それから、クラスメートの一点を経て、私はまた上のプログラムを见て、私ははっと悟りました.この感じはとても爽やかで、もとはこんなに简単でした.これが関数の魅力ですね.