学生成绩管理系统 每条记录包括:学号、姓名、专业和5门课程的成绩; 能够实现添加、删除、修改功能; 能够计算某学生的总分和平均分; 能按照总分排序输出。
时间: 2024-02-01 16:14:05 浏览: 33
可以通过面向对象的方式来设计实现这个学生成绩管理系统,包括以下几个类:
1. Student类:包含学生的基本信息,如学号、姓名、专业等,以及5门课程的成绩,提供计算总分和平均分的方法。
2. GradeSystem类:负责管理学生信息,可以实现添加、删除、修改功能,以及按照总分排序输出的功能。
具体实现可以参考以下伪代码:
```
class Student {
private:
int id;
string name;
string major;
double grades[5]; // 五门课程的成绩
public:
Student(int id, string name, string major, double grades[]) {
this->id = id;
this->name = name;
this->major = major;
for (int i = 0; i < 5; i++) {
this->grades[i] = grades[i];
}
}
double getTotalGrade() {
double total = 0;
for (int i = 0; i < 5; i++) {
total += grades[i];
}
return total;
}
double getAverageGrade() {
return getTotalGrade() / 5;
}
// 省略getter和setter方法
};
class GradeSystem {
private:
vector<Student> students;
public:
void addStudent(Student s) {
students.push_back(s);
}
void deleteStudent(int id) {
for (auto it = students.begin(); it != students.end(); it++) {
if (it->getId() == id) {
students.erase(it);
break;
}
}
}
void modifyStudent(int id, string name, string major, double grades[]) {
for (auto it = students.begin(); it != students.end(); it++) {
if (it->getId() == id) {
it->setName(name);
it->setMajor(major);
for (int i = 0; i < 5; i++) {
it->setGrade(i, grades[i]);
}
break;
}
}
}
void sortByTotalGrade() {
sort(students.begin(), students.end(),
[](const Student& s1, const Student& s2) {
return s1.getTotalGrade() > s2.getTotalGrade();
});
}
// 省略其他方法
};
```
使用时,可以创建一个GradeSystem对象,然后调用其方法来实现对学生信息的管理:
```
GradeSystem gs;
gs.addStudent(Student(1, "张三", "计算机科学", {90, 85, 95, 80, 88}));
gs.addStudent(Student(2, "李四", "软件工程", {85, 80, 90, 85, 92}));
gs.addStudent(Student(3, "王五", "物联网工程", {70, 75, 80, 85, 90}));
// 输出所有学生的总分和平均分
for (auto s : gs.getStudents()) {
cout << s.getId() << " " << s.getName() << " "
<< s.getTotalGrade() << " " << s.getAverageGrade() << endl;
}
// 将学生按照总分排序输出
gs.sortByTotalGrade();
for (auto s : gs.getStudents()) {
cout << s.getId() << " " << s.getName() << " "
<< s.getTotalGrade() << " " << s.getAverageGrade() << endl;
}
// 修改学生信息
gs.modifyStudent(1, "张三丰", "计算机科学与技术", {92, 88, 95, 88, 90});
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)