#ifndef MAIN_H
#include
#include
using namespace std;
#endif
class Student
{
public:
Student();
friend void ShowAverage(Student Stu);
private:
int ID;
string Name;
double Score;
static double TotalScore;
static int TotalStudent;
};
double Student::TotalScore = 0;
int Student::TotalStudent = 0;
Student::Student()
{
TotalStudent++;
cout << "请输入第" << TotalStudent
<< "个学生的信息!" << endl;
cout << "请输入学号: ";
cin >> ID;
cout << "请输入姓名: ";
cin >> Name;
cout << "请输入成绩: ";
cin >> Score;
cout << endl;
TotalScore += Score;
}
void ShowAverage(Student Stu)
{
cout << "---------------------------" << endl;
cout << "全部学生的总分为: " << Stu.TotalScore << endl;
cout << "全部学生的平均分为: " << Stu.TotalScore / Stu.TotalStudent << endl;
cout << endl;
}
int main()
{
Student *Sp;
Sp = new Student[3];
ShowAverage(*Sp);
system("pause");
return 0;
}
运行结果: