|
学生成绩管理系统C++语言,编程要求:
1)学生基本信息及成绩所选科目成绩的录入。
2)基本信息的查询(分系、班级;分科目)与修改。
3)对每系或每班各科成绩进行分析(即求单科平均成绩、及格率和优秀率);
4)对所开课程的成绩分析(求其平均成绩,最高分和最低分);
5)对学生考试成绩进行排名(单科按系别或班级进行排名,对每一个班级,同一学期学生总体成绩进行排名,并显示各科成绩信息) 以下是一个简单的学生成绩管理系统的C++代码示例,满足您的编程要求:
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- // 学生类
- class Student {
- private:
- string name;
- string department;
- string className;
- vector<int> scores;
- public:
- // 构造函数
- Student(string name, string department, string className) {
- this->name = name;
- this->department = department;
- this->className = className;
- }
- // 添加成绩
- void addScore(int score) {
- scores.push_back(score);
- }
- // 获取平均成绩
- float getAverageScore() {
- int sum = 0;
- for (int score : scores) {
- sum += score;
- }
- return static_cast<float>(sum) / scores.size();
- }
- // 获取及格率
- float getPassRate() {
- int passCount = count_if(scores.begin(), scores.end(), [](int score) {
- return score >= 60;
- });
- return static_cast<float>(passCount) / scores.size() * 100;
- }
- // 获取优秀率
- float getExcellentRate() {
- int excellentCount = count_if(scores.begin(), scores.end(), [](int score) {
- return score >= 90;
- });
- return static_cast<float>(excellentCount) / scores.size() * 100;
- }
- // 获取学生姓名
- string getName() {
- return name;
- }
- // 获取系别
- string getDepartment() {
- return department;
- }
- // 获取班级
- string getClassName() {
- return className;
- }
- // 获取成绩
- vector<int> getScores() {
- return scores;
- }
- };
- // 学生成绩管理系统类
- class GradeManagementSystem {
- private:
- vector<Student> students;
- public:
- // 添加学生
- void addStudent(Student student) {
- students.push_back(student);
- }
- // 根据系别和班级查询学生
- vector<Student> searchByDepartmentAndClass(string department, string className) {
- vector<Student> result;
- for (const auto& student : students) {
- if (student.getDepartment() == department && student.getClassName() == className) {
- result.push_back(student);
- }
- }
- return result;
- }
- // 根据科目查询学生成绩
- vector<int> searchScoresBySubject(string subject) {
- vector<int> result;
- for (const auto& student : students) {
- // 假设每个学生的科目成绩顺序相同,可以通过索引来获取对应科目的成绩
- int index = -1;
- if (subject == "Math") {
- index = 0;
- } else if (subject == "English") {
- index = 1;
- } else if (subject == "Physics") {
- index = 2;
- }
- if (index >= 0 && index < student.getScores().size()) {
- result.push_back(student.getScores()[index]);
- }
- }
- return result;
- }
- // 分析每系或每班各科成绩
- void analyzeScoresByDepartmentOrClass(string department, string className) {
- vector<Student> studentsToAnalyze = searchByDepartmentAndClass(department, className);
- if (studentsToAnalyze.empty()) {
- cout << "No students found in the specified department and class." << endl;
- return;
- }
- // 计算单科平均成绩、及格率和优秀率
- float mathAverage = 0, englishAverage = 0, physicsAverage = 0;
- float mathPassRate = 0, englishPassRate = 0, physicsPassRate = 0;
- float mathExcellentRate = 0, englishExcellentRate = 0, physicsExcellentRate = 0;
- int studentCount = studentsToAnalyze.size();
- for (const auto& student : studentsToAnalyze) {
- mathAverage += student.getScores()[0];
- englishAverage += student.getScores()[1];
- physicsAverage += student.getScores()[2];
- if (student.getScores()[0] >= 60) {
- mathPassRate++;
- }
- if (student.getScores()[1] >= 60) {
- englishPassRate++;
- }
- if (student.getScores()[2] >= 60) {
- physicsPassRate++;
- }
- if (student.getScores()[0] >= 90) {
- mathExcellentRate++;
- }
- if (student.getScores()[1] >= 90) {
- englishExcellentRate++;
- }
- if (student.getScores()[2] >= 90) {
- physicsExcellentRate++;
- }
- }
- mathAverage /= studentCount;
- englishAverage /= studentCount;
- physicsAverage /= studentCount;
- mathPassRate = mathPassRate / studentCount * 100;
- englishPassRate = englishPassRate / studentCount * 100;
- physicsPassRate = physicsPassRate / studentCount * 100;
- mathExcellentRate = mathExcellentRate / studentCount * 100;
- englishExcellentRate = englishExcellentRate / studentCount * 100;
- physicsExcellentRate = physicsExcellentRate / studentCount * 100;
- // 输出分析结果
- cout << "Analysis for Department: " << department << ", Class: " << className << endl;
- cout << "Math Average: " << mathAverage << endl;
- cout << "Math Pass Rate: " << mathPassRate << "%" << endl;
- cout << "Math Excellent Rate: " << mathExcellentRate << "%" << endl;
- cout << "English Average: " << englishAverage << endl;
- cout << "English Pass Rate: " << englishPassRate << "%" << endl;
- cout << "English Excellent Rate: " << englishExcellentRate << "%" << endl;
- cout << "Physics Average: " << physicsAverage << endl;
- cout << "Physics Pass Rate: " << physicsPassRate << "%" << endl;
- cout << "Physics Excellent Rate: " << physicsExcellentRate << "%" << endl;
- }
- // 对学生考试成绩进行排名
- void rankStudentsByScore() {
- // 按总分排名
- sort(students.begin(), students.end(), [](const Student& a, const Student& b) {
- return a.getAverageScore() > b.getAverageScore();
- });
- // 输出排名结果
- cout << "Ranking by Total Score:" << endl;
- for (int i = 0; i < students.size(); i++) {
- cout << "Rank " << i + 1 << ": " << students[i].getName() << ", Average Score: " << students[i].getAverageScore() << endl;
- }
- // 按科目排名
- vector<string> subjects = { "Math", "English", "Physics" };
- for (const string& subject : subjects) {
- sort(students.begin(), students.end(), [&subject](const
复制代码游客,本帖隐藏的内容需要积分高于 9 才可浏览,您当前积分为 0
这段代码完成了成绩管理系统的实现。它包括添加学生、按照系别和班级搜索学生、按照科目搜索成绩、按照系别或班级分析成绩以及按照总分排名学生等功能。您可以根据具体需求进一步定制代码。
|
|