首先,我们需要创建一个学生类(Student)来存储学生的基本信息,如姓名、年龄和成绩。然后,我们需要创建一个学生信息管理系统类(StudentManagementSystem),用于管理学生列表。
以下是一个简单的C++代码实现:
```cpp
#include
#include
#include
class Student {
public:
Student(const std::string& name, int age, double score)
: name_(name), age_(age), score_(score) {}
const std::string& GetName() const { return name_; }
int GetAge() const { return age_; }
double GetScore() const { return score_; }
private:
std::string name_;
int age_;
double score_;
};
class StudentManagementSystem {
public:
void AddStudent(const Student& student) {
students_.push_back(student);
}
void PrintAllStudents() const {
for (const auto& student : students_) {
std::cout << "Name: " << student.GetName() << ", Age: " << student.GetAge() << ", Score: " << student.GetScore() << std::endl;
}
}
private:
std::vector
};
int main() {
StudentManagementSystem sms;
// 添加学生信息
sms.AddStudent(Student("张三", 20, 90.5));
sms.AddStudent(Student("李四", 21, 85.0));
sms.AddStudent(Student("王五", 22, 92.0));
// 打印所有学生信息
sms.PrintAllStudents();
return 0;
}
```
这个简单的学生信息管理系统实现了以下功能:
1. 定义了一个`Student`类,用于存储学生的基本信息。
2. 定义了一个`StudentManagementSystem`类,用于管理学生列表。它有两个方法:`AddStudent`用于添加学生,`PrintAllStudents`用于打印所有学生的信息。
3. 在`main`函数中,我们创建了一个`StudentManagementSystem`对象,并添加了三个学生的信息。最后,我们调用`PrintAllStudents`方法打印所有学生的信息。