#include "Sum.h"
#include <string.h>
#include
using namespace std;
class Stud
{
private:
char no[10];//学号
char name[10];//姓名
double score;//成绩
static double sum;//总分
static int num;//总人数
public:
//给数据成员赋值
void setdata(char* _no, char* _name, double _score) {
strcpy(no, _no);
strcpy(name, _name);
score = _score;
sum += score;
num++;
}
//输出数据成员的值
void disp() {
cout << "学号:" << no << " 姓名:" << name << " 分数:" << score << endl;
}
//计算平均分
static double avg() {
return sum / num;
}
};
double Stud::sum = 0;
int Stud::num = 0;
int main() {
int n;
cout << "请输入学生人数" << endl;
cin >> n;
CStud* stu = new Stud[n];
cout << "请依次输入学生的学号、姓名和分数" << endl;
int i;
for (i = 0; i < n; i++) {
char tno[10];
char tname[10];
double tscore;
cin >> tno;
cin >> tname;
cin >> tscore;
stu[i].setdata(tno, tname, tscore);
}
for (i = 0; i < n; i++) {
stu[i].disp();
}
double a = Stud::avg();
cout << "平均分:" << a << endl;
}