求数组的中位数,平均数和众数的代码!

#include
#include
using namespace std;

void mean (const int [],int);
void median (int [],int);
void mode (int [],int [],int);
void bubbleSort (int [],int);
void printArray(const int[],int);

int main()
{
 const int responseSize=99;

 int frequency[10]={0};

 int response[responseSize]=
 {6,7,8,9,8,7,8,9,8,9,
  6,7,8,9,3,9,8,7,8,7,
   6,7,8,9,3,9,8,7,8,7,
     7,8,9,8,9,8,9,7,8,9,
  6,7,8,7,8,7,9,8,9,2,
  7,8,9,8,9,8,9,7,5,3,
  5,6,7,2,5,3,9,4,6,4,
  7,8,9,6,8,7,8,9,7,8,
  7,4,4,2,5,3,8,7,5,6,
  4,5,6,1,6,5,7,8,7,};

 mean(response,responseSize);
 median(response,responseSize);
 mode(frequency,response,responseSize);

 return 0;
}

void mean(const int answer[],int arraySize)
{
 int total=0;

 cout<<"********/n mean/n********/n";

 for(int i=0;i  total+=answer[i];
 cout< cout<<"元素个数是:"< cout<<"元素总和是:"< cout<<"平均值是:"<}

void median(int answer[],int size)
{
 cout<<"/n********/n Median/n********/n"
  <<"未排序的数组是";

 printArray(answer,size);
 bubbleSort(answer,size);

 cout<<"/n/n排序后的数组是:";
 printArray(answer,size);

 cout<<"/n/n在这"<}

void mode(int freq[],int answer[],int size)
{
 int largest=0;
 int modeValue=0;

 cout<<"/n********/n Mode/n********/n";

 for(int i=1;i<10;i++)
  freq[i]=0;

 for(int j=0;j  ++freq[answer[j]];

 cout<<"Response"<  <<"Histogram/n/n"<  <

 for(int rating=1;rating<10;rating++){
  cout<

  if(freq[rating]>largest){
   largest=freq[rating];
   modeValue=rating;}

  for(int k=1;k<=freq[rating];k++)
   cout<<"*";
  cout<<"/n";
 }

 cout<<"数据处理直方图"< cout<<"这组数据中,出现次数最多的是:"< cout<<"一共出现了"<}

void bubbleSort(int a[],int size)
{
 int hold;

 for(int pass=1;pass  for(int j=0;j   if(a[j]>a[j+1]){
    hold=a[j];
    a[j]=a[j+1];
    a[j+1]=hold;
   }
  }
 }
}

void printArray(const int a[],int size)
{
 for(int i=0;i  if(i%20==0)
   cout<  cout< }
}

 

 

你可能感兴趣的:(自学编程的奋斗过程,include)