#include
using namespace std;
const int COURSE_NUM = 3;
const int STUDENT_NUM = 3;
class student //类名:学生
{
public:
void input();//输入函数
void output();//输出函数
private:
char name[20];//姓名
char number[20];
char coursename[COURSE_NUM][20];
float marks[COURSE_NUM];
};
void student::input()
{
int i;
cout << "请输入姓名:";
cin >> name;
cout << "请输入学号:";
cin >> number;
for (i = 0; i < COURSE_NUM; i++)
{
cout << "请输入第 " << i + 1 << " 门成绩名:";
cin >> coursename[i];
cout << "请输入第 " << i + 1 << " 门成绩:";
cin >> marks[i];
}
}
void student::output()
{
int i;
float ave = 0;
cout << "姓名:" << name << endl;
cout << "学号:" << number << endl;
for (i = 0; i < COURSE_NUM; i++)
{
cout << coursename[i] << ":" << marks[i] << endl;
ave += marks[i];
}
ave /= COURSE_NUM;
cout << "平均成绩:" << ave << endl;
}
int main()
{
student stu[STUDENT_NUM];
int i;
for (i = 0; i < STUDENT_NUM; i++)
{
stu[i].input();
}
for (i = 0; i < STUDENT_NUM; i++)
{
stu[i].output();
}
return 0;
}