#include
#include
#include
class student {//学生
public:
int Number;//学号
double Score;//分数
};
class stuManager {//学生管理员
public:
void initStu();//初始化
void createStu();//创建65名学生
void showStu();//展示65名学生及成绩
vector
};
void stuManager::initStu() {
v_student.clear();
}
bool Greater(student s1,student s2) {//比较方式
return s1.Score > s2.Score;
}
void stuManager::createStu() {
srand((unsigned int)time(NULL) + rand());
for (int i = 1; i <= 65;i++) {
vector
for (int i = 0; i < 10; i++) {
double goal = (rand() % 401 + 600) / 10;
v_score.push_back(goal);
}
double avgScore = accumulate(v_score.begin(), v_score.end(),0.0f)/10;//求10位老师的平均数
student s;
s.Number = 10000 + i;
s.Score = avgScore;
v_student.push_back(s);
}
}
void stuManager::showStu() {
sort(v_student.begin(), v_student.end(),Greater);//按成绩高到底排序
cout << "数据结构考试成绩如下:" << endl;
for (vector
cout << "学号:" << it->Number << " " << "分数:" << it->Score << endl;
}
}
int main()
{
stuManager mg;
mg.initStu();
mg.createStu();
mg.showStu();
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)