58 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <vector>
#include <algorithm>
#include "Student_info.h"
#include "grade.h"
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
// 定义常量:及格分数
const double PASS_GRADE = 60.0;
int main() {
vector<Student_info> students;
Student_info record;
// 读取学生信息
cout << "期中成绩占比20%、期末成绩占比40%平时成绩占比40%:" << endl;
cout << "输入学生信息(姓名、期中成绩、期末成绩,平时成绩):" << endl;
cout << "输入Ctrl+z后回车退出。" << endl;
while (read(cin, record)) {
students.push_back(record);
}
// 将学生分为及格和不及格两组
vector<Student_info> pass, fail;
for (const auto& student : students) {
if (grade(student) >= PASS_GRADE) {
pass.push_back(student);
}
else {
fail.push_back(student);
}
}
// 按名字排序
std::sort(pass.begin(), pass.end(), compare);
std::sort(fail.begin(), fail.end(), compare);
// 输出及格学生信息
cout << "合格学生:" << endl;
for (const auto& student : pass) {
cout << student.name << ": 总成绩 = " << grade(student) << endl;
}
// 输出不及格学生信息
cout << "不合格学生:" << endl;
for (const auto& student : fail) {
cout << student.name << ": 总成绩 = " << grade(student) << endl;
}
return 0;
}