⑴ C++编程题,用数组建立成绩表,要求平均分、总分和排名.
#include <iostream>
using namespace std;
#define N 10
int main(int argc,char *argv[]){
int stu[N][8],i,j,k;
cout << "Please enter the " << N << " students scores... ";
for(stu[k=i=0][7]=0;i<N;i++){//输入数据并输出平均成绩
for(stu[i][7]=j=0;j<7;cin >> stu[i][j],stu[i][7]+=stu[i][j++]);
if(stu[k][7]<stu[i][7])//求部分最大者
k=i;
}
cout << " STUDENT AVERAGE TOTAL ======================= ";
cout.precision(2);cout.setf(ios::fixed);
for(i=0;i<N;cout << " STU" << 1+i++ << " " << stu[i][7]/7.0 << " " << stu[i][7] << endl);
cout << " THE HIGHEST: " << "STU" << k+1 << " " << stu[k][7] << endl;
return 0;
}
代码格式和运行样例图片: