/*
*Copyright (c) 2014, 烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:陈栋梁
*完成日期:2014年 12月 2 日
*版本号:v1.0
*
*问题描述:
*/
#include<iostream>
#include<string>
using namespace std;
void input(double s[][4],int n); //输入成绩
void output(double s[][4],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门课的平均成绩
string course[4]= {"高等数学","英语","C++","总分"};
int main()
{
int i,num;
string temp;
double score[100][4]; //设一个班最多100人,实际按输入来
cout<< "输入学生人数:";
cin>> num;
//(1)输入成绩并求出总分
input(score,num);
//(2)输出成绩
output(score,num);
//(3)输出各门课及总分的最高成绩、最低成绩、平均成绩
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;
}
return 0;
}
void input(double s[][4],int n)
{
double sum;
for (int i=0; i<n; ++i)
{
sum=0;
for(int j=0; j<3; ++j)
{
cout << "学号" << i << "的同学的" << course[j] << "成绩: ";
cin >> s[i][j];
sum+=s[i][j];
}
s[i][3]=sum;
}
}
void output(double s[][4],int n)
{
cout << endl
<< "............统计结果............" << endl;
for (int i=0; i<n; ++i)
{
cout << "学号" << i << "的同学成绩:" << endl;
for(int j=0; j<4; ++j)
cout << course[j] << ": " << s[i][j] << endl;
cout << endl;
}
}
double max(double s[][4],int n,int i)
{
double max=s[0][i];
for (int j=1; j<n; ++j)
{
if(s[j][i]>max)
max=s[j][i];
}
return max;
}
double min(double s[][4],int n,int i)
{
double min=s[0][i];
for (int j=1; j<n; ++j)
{
if(s[j][i]<min)
min=s[j][i];
}
return min;
}
double avg(double s[][4],int n,int i)
{
double ave,sum=0;
for (int j=0; j<n; ++j)
sum+=s[j][i];
ave=sum/n;
return ave;
}
运行结果: