#include
#include
using namespace std;
class student{
string p;
int num;
float math, english;
static float z, m, e;
public:
student(string s, int n, float a, float b)
{
p = s, num = n, math = a, english = b;
z = m = e = 0;
}
student(){}
void input();
void output();
float sum();
static void outputsum();
float average();
~student(){}
};
void student::input()
{
cout << "输入姓名:";
string s;
cin.sync();
getline(cin, s);
cout << "输入学号:";
int n;
cin >> n;
float x, b;
cout << "输入数学成绩:";
cin >> x;
cout << "输入英语成绩:";
cin >> b;
student(s, n, x, b);
}
void student::output()
{
cout << "姓名:" << p << "\n学号:" << num << endl
<< "数学成绩:" << math << endl << "英语成绩:" << english
<< endl << "总成绩:" << this->sum() << endl << "平均成绩:" << this->average() << endl;
}
float student::sum()
{
z += math + english, m += math, e += english;
return math + english;
}
void student::outputsum()
{
cout << "所有学生的总成绩:" << z << '\n' << "所有学生的数学成绩:" << m
<< endl << "所有学生的英语成绩:" << e << endl;
}
float student::average()
{
return (this->sum()) / 2;
}
int main()
{
int n;
cout << "students' number:";
cin >> n;
student *s = new student[n];
if (NULL == s)
return 1;
for (int i = 0; i < n; i++)
s[i].input();
for (int i = 0; i < n; i++)
s[i].output();
s->outputsum();
delete[]s;
system("pause");
return 0;
}