.创建一个学生对象student,包含属性id,name,score(学号、姓名、成绩); 再创建一个学生管理类studentmanager,包含属性map<string,student>m
时间: 2023-05-01 14:02:03 浏览: 107
题目中要求我们创建一个学生对象,包含属性id、name、score(学号、姓名、成绩),并再创建一个学生管理类studentmanager,包含属性map<string,student>。
具体操作如下:
1. 首先定义学生类,包含id、name、score属性:
```cpp
class student{
private:
string id;
string name;
int score;
public:
student(){}
student(string id, string name, int score){
this->id = id;
this->name = name;
this->score = score;
}
void set_id(string id){this->id = id;}
void set_name(string name){this->name = name;}
void set_score(int score){this->score = score;}
string get_id(){return id;}
string get_name(){return name;}
int get_score(){return score;}
};
```
2. 接下来创建学生管理类studentmanager,其包含属性map<string,student>:
```cpp
class studentmanager {
private:
map<string, student> stu_map;
public:
studentmanager(){}
void add_student(student stu){stu_map[stu.get_id()] = stu;}
void remove_student(string id){stu_map.erase(id);}
student get_student(string id){return stu_map[id];}
map<string, student> get_stu_map(){return stu_map;}
};
```
这样,我们就实现了题目中要求的学生对象和学生管理类,并且可以通过学生管理类对学生对象进行添加、删除、查询等操作。