使用C++编写一个班级学生成绩统计的程序要求如下:-1-学生课程包括英语数学物理化学;-2-学生的成绩存储在队列里面;-3-学生信息包括学号姓名年龄;4班级学生总人数为50人;-5要求能够录入班级所有学生的信息成绩能够统计学生成绩排名。
#include
using namespace std;
// 学生信息结构体 struct Student { string id; // 学号 string name; // 姓名 int age; // 年龄 double english_score; // 英语成绩 double math_score; // 数学成绩 double physics_score; // 物理成绩 double chemistry_score; // 化学成绩 double total_score; // 总成绩 bool operator < (const Student& s) const { // 重载小于运算符,用于排序 return total_score > s.total_score; } };
// 全局变量:班级学生总人数为50人 const int MAX_STUDENT_NUM = 50;
// 学生队列
queue
// 录入学生信息 void input_student_info() { for (int i = 1; i <= MAX_STUDENT_NUM; i++) { Student s; cout << "请输入第" << i << "个学生的信息:" << endl; cout << "学号:"; cin >> s.id; cout << "姓名:"; cin >> s.name; cout << "年龄:"; cin >> s.age; cout << "英语成绩:"; cin >> s.english_score; cout << "数学成绩:"; cin >> s.math_score; cout << "物理成绩:"; cin >> s.physics_score; cout << "化学成绩:"; cin >> s.chemistry_score; s.total_score = s.english_score + s.math_score + s.physics_score + s.chemistry_score; student_queue.push(s); } }
// 统计学生成绩排名
void rank_student_score() {
vector
int main() { input_student_info(); rank_student_score(); return 0; }
原文地址: http://www.cveoy.top/t/topic/qV9 著作权归作者所有。请勿转载和采集!