学生管理信息系统c++
时间: 2023-06-20 09:06:04 浏览: 50
学生管理信息系统是一个常见的项目,可以使用 C++ 来实现。以下是一个简单的学生管理信息系统的示例代码:
```c++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 学生类
class Student {
public:
Student(string name, int age, int id) {
this->name = name;
this->age = age;
this->id = id;
}
string getName() {
return name;
}
int getAge() {
return age;
}
int getId() {
return id;
}
private:
string name;
int age;
int id;
};
// 学生管理类
class StudentManager {
public:
void addStudent(Student student) {
students.push_back(student);
}
void showStudents() {
for (int i = 0; i < students.size(); i++) {
cout << "Name: " << students[i].getName() << ", Age: " << students[i].getAge() << ", ID: " << students[i].getId() << endl;
}
}
private:
vector<Student> students;
};
int main() {
// 创建学生管理器
StudentManager manager;
// 添加学生
manager.addStudent(Student("Tom", 18, 1001));
manager.addStudent(Student("Jerry", 19, 1002));
manager.addStudent(Student("Alice", 20, 1003));
// 显示学生信息
manager.showStudents();
return 0;
}
```
在这个示例中,我们定义了一个 `Student` 类来表示学生,其中包含学生的姓名、年龄和学号。然后,我们定义了一个 `StudentManager` 类来管理学生信息。在 `StudentManager` 类中,我们使用 `vector` 来存储学生对象,并提供了添加学生和显示学生信息的方法。在 `main` 函数中,我们创建了一个学生管理器,并添加了三个学生对象,最后显示了所有学生的信息。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)