第14週目項目増加string name[]出力点数の最高、最低、平均、総得点
3737 ワード
:
/*
*Copyright (c)2014,
*All rights reserved
* :
* :2014 12 1
* :v1.0
*
* : string name[] ,
* : ,
* ;
*/
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
void input(double s[][4],string name [],int n); //
void output(double s[][4],string name [],int n); //
double max(double s[][4],int n,int i); // i ,i=3
double min(double s[][4],int n,int i); // i
double avg(double s[][4],int n,int i); // i
void outputByscore (double s[][4],string name [],int n,int i,double si);
int main()
{
int i,num;
string temp;
double score[100][4]; // 100 ,
string name [100];
string course[4]= {" "," ","C++"," "};
cout<<" :";
cin>>num;
//
input (score,name,num);
//
output (score,name,num);
// , ,
for (i=0; i<4; i++)
{
cout <<course[i]<<" :"<<max(score,num,i)<<", ";
cout <<" "<<min(score,num,i)<<", ";
cout <<" "<<avg(score,num,i)<<", ";
cout <<endl;
}
for (i=0; i<4; i++)
{
cout <<course[i]<<" :";
outputByscore(score,name,num,i,max(score,num,i)) ;
cout <<endl;
}
return 0;
}
void input (double s[][4],string name [],int n)
{
cout <<" ( , , ,c++) :"<<endl;
for (int i=0; i<n; i++)
{cin>>name [i]>>s[i][0]>>s[i][1]>>s[i][2];
s[i][3]=s[i][0]+s[i][1]+s[i][2];}
}
void output (double s[][4],string name [],int n)
{
cout <<" :"<<endl;
cout << " \t \t \t \tc++\t "<<endl;
for (int i=0; i<n; i++)
{
cout <<i<<'\t'<<name[i]<<'\t';
cout <<s[i][0]<<'\t';
cout <<s[i][1]<<'\t';
cout <<s[i][2]<<'\t';
cout <<s[i][3]<<'\t'<<endl;
}
}
double max (double s[][4],int n,int j)
{
double m=s[0][j];
for (int i=1; i<n; i++)
if (m<s[i][j])
m=s[i][j];
return m;
}
double min (double s[][4],int n,int j)
{
double m=s[0][j];
for (int i=1; i<n; i++)
if (m>s[i][j])
m=s[i][j];
return m;
}
double avg (double s[][4],int n,int j)
{
double sum=s[0][j];
for (int i=1; i<n; i++)
sum+=s[i][j];
return sum/n;
}
void outputByscore(double s[][4],string name [],int n,int i,double si)
{
for (int j=0; j<n; j++)
{
if (abs(s[j][i]-si)<1e-7)
cout <<name [j]<<" ";
}
return;
}
実行結果:
***やっと一字も残さずに書き上げた
勉強の心得:まだまだ頑張るところがたくさんあります