怎样用C语言写出下面的题目
《有五个学生,每个学生有三门课的成绩,从键盘输入以上的数据(包括学生号、姓名,三门课的成绩)计算出每个学生的平均成绩及每门课的平均成绩,并将原有的数据和计算出的平均分数以矩阵的形式输出》。
#include "stdafx.h" #include <conio.h> #include <IOSTREAM> #include <STRING> using namespace std;
struct student{ int munber; string name; double scoreA; double scoreB; double scoreC; };
double studentscore(student v) { double p; p = (v.scoreA + v.scoreB + v.scoreC)/3; return p; }
int main(int argc, char* argv[]) { student mun[5]; for(int i = 0;i < 5;i++) { cout<<"please input munber"<<endl; cin >> mun[i].munber; cout<<endl; if(!mun[i].munber) exit(0); cout<<"please input name"<<endl; cin >> mun[i].name; cout<<endl; if(mun[i].name == "") exit(0); cout<<"please input scoreA"<<endl; cin >> mun[i].scoreA; cout<<endl; if(!mun[i].scoreA) exit(0); cout<<"please input scoreB"<<endl; cin >> mun[i].scoreB; cout<<endl; if(!mun[i].scoreB) exit(0); cout<<"please input scoreC"<<endl; cin >> mun[i].scoreC; cout<<endl; if(!mun[i].scoreC) exit(0); } double hh[5]; for(int t = 0;t < 5;t++) { hh[t] = studentscore(mun[t]); } cout<<"munber"<<"\t"<<"name"<<"\t"<<"Averagescore"<<endl; for(int f = 0;f < 5;f++) { cout<<mun[f].munber<<"\t"<<mun[f].name<<"\t"<<hh[f]<<endl; } return 0; }
(经VC6.0++编译通过)
我帮你写了一个,不知道是否符合你的要求,以后自己先写写看,多练才能进步.