使用C++编写学生成绩录入统计排序的程序程序要求如下:1-学生信息类学号姓名电话号码;2课程成绩类学号数学、物理、化学英语语文成绩总分;-3两个队列类分别用于保存班级学生信息课程成绩-;3程序应包括主菜单完成学生信息和课程成绩的录入统计和排序功能。
以下是一种可能的实现方式:
#include
using namespace std;
// 学生信息类 class Student { public: string id; string name; string phone; };
// 课程成绩类 class Score { public: string id; int math; int physics; int chemistry; int english; int chinese; int total; };
// 学生信息队列类 class StudentQueue { public: void add(const Student& s) { students.push(s); }
bool empty() const {
return students.empty();
}
int size() const {
return students.size();
}
const Student& front() const {
return students.front();
}
void pop() {
students.pop();
}
private:
queue
// 课程成绩队列类 class ScoreQueue { public: void add(const Score& s) { scores.push(s); }
bool empty() const {
return scores.empty();
}
int size() const {
return scores.size();
}
const Score& front() const {
return scores.front();
}
void pop() {
scores.pop();
}
private:
queue
// 主菜单函数 void showMenu() { cout << "1. 录入学生信息\n"; cout << "2. 录入课程成绩\n"; cout << "3. 统计学生信息\n"; cout << "4. 统计课程成绩\n"; cout << "5. 排序学生信息\n"; cout << "6. 排序课程成绩\n"; cout << "0. 退出程序\n"; }
// 录入学生信息函数 void addStudent(StudentQueue& studentQueue) { while (true) { cout << "请输入学生信息(学号 姓名 电话号码),输入0结束录入:\n"; string id, name, phone; cin >> id; if (id == "0") break; cin >> name >> phone; Student student = { id, name, phone }; studentQueue.add(student); } }
// 录入课程成绩函数 void addScore(ScoreQueue& scoreQueue) { while (true) { cout << "请输入课程成绩(学号 数学 物理 化学 英语 语文),输入0结束录入:\n"; string id; int math, physics, chemistry, english, chinese; cin >> id; if (id == "0") break; cin >> math >> physics >> chemistry >> english >> chinese; Score score = { id, math, physics, chemistry, english, chinese, math + physics + chemistry + english + chinese }; scoreQueue.add(score); } }
// 统计学生信息函数 void showStudentInfo(StudentQueue& studentQueue) { cout << "共有 " << studentQueue.size() << " 个学生信息:\n"; while (!studentQueue.empty()) { const Student& student = studentQueue.front(); cout << "学号:" << student.id << ",姓名:" << student.name << ",电话号码:" << student.phone << "\n"; studentQueue.pop(); } }
// 统计课程成绩函数 void showScoreInfo(ScoreQueue& scoreQueue) { cout << "共有 " << scoreQueue.size() << " 个学生的课程成绩:\n"; while (!scoreQueue.empty()) { const Score& score = scoreQueue.front(); cout << "学号:" << score.id << ",数学:" << score.math << ",物理:" << score.physics << ",化学:" << score.chemistry << ",英语:" << score.english << ",语文:" << score.chinese << ",总分:" << score.total << "\n"; scoreQueue.pop(); } }
// 排序学生信息函数 bool cmpStudent(const Student& s1, const Student& s2) { return s1.id < s2.id; }
void sortStudent(StudentQueue& studentQueue) {
vector
// 排序课程成绩函数 bool cmpScore(const Score& s1, const Score& s2) { return s1.total > s2.total; }
void sortScore(ScoreQueue& scoreQueue) {
vector
int main() { StudentQueue studentQueue; ScoreQueue scoreQueue;
while (true) {
showMenu();
int choice;
cin >> choice;
switch (choice) {
case 0:
return 0;
case 1:
addStudent(studentQueue);
break;
case 2:
addScore(scoreQueue);
break;
case 3:
showStudentInfo(studentQueue);
break;
case 4:
showScoreInfo(scoreQueue);
break;
case 5:
sortStudent(studentQueue);
break;
case 6:
sortScore(scoreQueue);
break;
default:
cout << "无效的选项,请重新选择。\n";
break;
}
}
}
原文地址: https://www.cveoy.top/t/topic/sga 著作权归作者所有。请勿转载和采集!