个人信息管理系统c++
时间: 2023-12-02 19:42:44 浏览: 41
以下是一个简单的个人信息管理系统的C++代码,其中包括了学生类和教师类,可以实现添加、删除、修改和查询个人信息的功能:
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
class people {
public:
string name;
string id;
bool isGril;
int totalHours;
int fixedPerWeekHours;
virtual void print() {
cout << "姓名:" << name << endl;
cout << "编号:" << id << endl;
cout << "性别:" << (isGril ? "女" : "男") << endl;
cout << "总学时数:" << totalHours << endl;
cout << "每周固定学时数:" << fixedPerWeekHours << endl;
}
};
class student : virtual public people {
public:
student() {}
friend istream& operator>>(istream& in, student& p);
void print() {
cout << "学生信息:" << endl;
people::print();
}
};
istream& operator>>(istream& in, student& p) {
cout << "请分别输入姓名、编号、性别(女:1,男:0)、身份证号、总学时数以及每周固定学时数(Tips:每项空格隔开)\n";
in >> p.name >> p.id >> p.isGril >> p.id >> p.totalHours >> p.fixedPerWeekHours;
return in;
}
class teacher : virtual public people {
public:
teacher() {}
friend istream& operator>>(istream& in, teacher& p);
void print() {
cout << "教师信息:" << endl;
people::print();
}
};
istream& operator>>(istream& in, teacher& p) {
cout << "请分别输入姓名、编号、性别(女:1,男:0)、身份证号、总学时数以及每周固定学时数(Tips:每项空格隔开)\n";
in >> p.name >> p.id >> p.isGril >> p.id >> p.totalHours >> p.fixedPerWeekHours;
return in;
}
vector<people*> peopleList;
void addPeople() {
int type;
cout << "请选择要添加的人员类型(1:学生,2:教师):" << endl;
cin >> type;
if (type == 1) {
student* p = new student();
cin >> *p;
peopleList.push_back(p);
}
else if (type == 2) {
teacher* p = new teacher();
cin >> *p;
peopleList.push_back(p);
}
else {
cout << "输入有误!" << endl;
}
}
void deletePeople() {
string id;
cout << "请输入要删除的人员编号:" << endl;
cin >> id;
for (auto it = peopleList.begin(); it != peopleList.end(); it++) {
if ((*it)->id == id) {
delete* it;
peopleList.erase(it);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该人员!" << endl;
}
void modifyPeople() {
string id;
cout << "请输入要修改的人员编号:" << endl;
cin >> id;
for (auto it = peopleList.begin(); it != peopleList.end(); it++) {
if ((*it)->id == id) {
cin >> *(*it);
cout << "修改成功!" << endl;
return;
}
}
cout << "未找到该人员!" << endl;
}
void queryPeople() {
string id;
cout << "请输入要查询的人员编号:" << endl;
cin >> id;
for (auto it = peopleList.begin(); it != peopleList.end(); it++) {
if ((*it)->id == id) {
(*it)->print();
return;
}
}
cout << "未找到该人员!" << endl;
}
int main() {
while (true) {
cout << "请选择操作(1:添加,2:删除,3:修改,4:查询,0:退出):" << endl;
int op;
cin >> op;
if (op == 1) {
addPeople();
}
else if (op == 2) {
deletePeople();
}
else if (op == 3) {
modifyPeople();
}
else if (op == 4) {
queryPeople();
}
else if (op == 0) {
break;
}
else {
cout << "输入有误!" << endl;
}
cin.clear();
cin.ignore(1024, '\n');
}
return 0;
}
```