用C++编写:员工信息包括ID,姓名,所在公司,管理员信息包括ID,姓名,编写系统,功能包括:注册员工信息,注册管理员信息,员工登录,管理员登录
时间: 2023-07-01 16:09:31 浏览: 46
以下是用C++编写的员工信息管理系统,包括员工和管理员信息的注册、登录功能:
```cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 员工类
class Employee {
private:
string id; // 员工ID
string name; // 员工姓名
string company; // 所在公司
public:
Employee(string id, string name, string company) {
this->id = id;
this->name = name;
this->company = company;
}
string getID() const { return id; }
string getName() const { return name; }
string getCompany() const { return company; }
};
// 管理员类
class Admin {
private:
string id; // 管理员ID
string name; // 管理员姓名
string system; // 编写系统
public:
Admin(string id, string name, string system) {
this->id = id;
this->name = name;
this->system = system;
}
string getID() const { return id; }
string getName() const { return name; }
string getSystem() const { return system; }
};
// 员工信息管理系统类
class EmployeeManagementSystem {
private:
vector<Employee> employees; // 员工信息列表
vector<Admin> admins; // 管理员信息列表
public:
// 注册员工信息
void registerEmployee(string id, string name, string company) {
employees.push_back(Employee(id, name, company));
}
// 注册管理员信息
void registerAdmin(string id, string name, string system) {
admins.push_back(Admin(id, name, system));
}
// 员工登录
bool employeeLogin(string id) {
for (Employee emp : employees) {
if (emp.getID() == id) {
cout << "欢迎员工 " << emp.getName() << " 登录系统!" << endl;
return true;
}
}
cout << "员工ID不存在!" << endl;
return false;
}
// 管理员登录
bool adminLogin(string id) {
for (Admin adm : admins) {
if (adm.getID() == id) {
cout << "欢迎管理员 " << adm.getName() << " 登录系统!" << endl;
return true;
}
}
cout << "管理员ID不存在!" << endl;
return false;
}
};
int main() {
EmployeeManagementSystem system;
// 注册员工信息
system.registerEmployee("001", "张三", "ABC公司");
system.registerEmployee("002", "李四", "DEF公司");
system.registerEmployee("003", "王五", "GHI公司");
// 注册管理员信息
system.registerAdmin("001", "管理员1", "系统1");
system.registerAdmin("002", "管理员2", "系统2");
// 员工登录
system.employeeLogin("001");
system.employeeLogin("004");
// 管理员登录
system.adminLogin("001");
system.adminLogin("003");
return 0;
}
```
运行结果:
```
欢迎员工 张三 登录系统!
员工ID不存在!
欢迎管理员 管理员1 登录系统!
管理员ID不存在!
```