用C++设计一个小型企业工资管理系统。 设计说明:该小型企业的员工主要有 4 类:经理、技术员、销售员和计时工。要求存储员工的工号、姓名、岗位、月工资等基本信息。 工资计算方法: 1经理:领取固定月薪 8800 元 2技术员:分高级、中级、初级三类,其中高级固定每月 7700 元,中级 固定每月 6600 元,初级固定每月 5500 元 3销售员:底薪 2500+销售额*2%提成 4计时工:工作时间*每小时 66 元 该企业员工的类层次结构为:员工包含经理,技术员,销售员,计时工 要有一个菜单,用于选择各项功能: 1数据录入:输入各种数据(其中每类员工不能少于 3 人) 2数据查询:能根据工号或姓名查询工资信息 3职工信息的删除、修改 4工资计算:能对各类员工进行工资计算 5数据输出:能按类别输出员工信息及工资信息(包括计算工资时所用到 的相关数据,例如:销售员的销售额) 6设置登录本系统的用户名和密码,通过用户名和密码登录
时间: 2023-07-16 15:11:58 浏览: 174
下面是一个用C++设计的小型企业工资管理系统的示例代码,包含了菜单选项和各项功能的实现:
```c++
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// 员工类
class Employee {
public:
Employee(int id, string name, string position) :
m_id(id), m_name(name), m_position(position), m_monthSalary(0) {}
virtual void input() {
cout << "请输入员工基本信息:" << endl;
cout << "工号:";
cin >> m_id;
cout << "姓名:";
cin >> m_name;
cout << "岗位:";
cin >> m_position;
}
virtual void output() const {
cout << "工号:" << m_id << ",姓名:" << m_name
<< ",岗位:" << m_position << ",月工资:" << m_monthSalary << endl;
}
virtual void calculateSalary() {}
int getId() const { return m_id; }
string getName() const { return m_name; }
string getPosition() const { return m_position; }
int getMonthSalary() const { return m_monthSalary; }
protected:
int m_id; // 工号
string m_name; // 姓名
string m_position; // 岗位
int m_monthSalary; // 月工资
};
// 经理类
class Manager : public Employee {
public:
Manager(int id, string name, string position) :
Employee(id, name, position) {}
virtual void calculateSalary() {
m_monthSalary = 8800;
}
};
// 技术员类
class Technician : public Employee {
public:
Technician(int id, string name, string position) :
Employee(id, name, position), m_level(0) {}
virtual void input() {
Employee::input();
cout << "级别(1-高级,2-中级,3-初级):";
cin >> m_level;
}
virtual void output() const {
Employee::output();
cout << "级别:" << m_level << endl;
}
virtual void calculateSalary() {
switch (m_level) {
case 1:
m_monthSalary = 7700;
break;
case 2:
m_monthSalary = 6600;
break;
case 3:
m_monthSalary = 5500;
break;
default:
break;
}
}
private:
int m_level; // 级别
};
// 销售员类
class Salesman : public Employee {
public:
Salesman(int id, string name, string position) :
Employee(id, name, position), m_sales(0) {}
virtual void input() {
Employee::input();
cout << "销售额:";
cin >> m_sales;
}
virtual void output() const {
Employee::output();
cout << "销售额:" << m_sales << endl;
}
virtual void calculateSalary() {
m_monthSalary = 2500 + m_sales * 0.02;
}
private:
int m_sales; // 销售额
};
// 计时工类
class HourlyWorker : public Employee {
public:
HourlyWorker(int id, string name, string position) :
Employee(id, name, position), m_hours(0) {}
virtual void input() {
Employee::input();
cout << "工作时间(小时):";
cin >> m_hours;
}
virtual void output() const {
Employee::output();
cout << "工作时间(小时):" << m_hours << endl;
}
virtual void calculateSalary() {
m_monthSalary = m_hours * 66;
}
private:
int m_hours; // 工作时间
};
// 员工管理类
class EmployeeManager {
public:
EmployeeManager() {}
~EmployeeManager() {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
delete *it;
}
}
void addEmployee(Employee* employee) {
m_employeeList.push_back(employee);
}
void deleteEmployee(int id) {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getId() == id) {
delete *it;
m_employeeList.erase(it);
break;
}
}
}
void modifyEmployee(int id) {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getId() == id) {
(*it)->input();
break;
}
}
}
void searchEmployee(int id) const {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getId() == id) {
(*it)->output();
break;
}
}
}
void searchEmployee(const string& name) const {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getName() == name) {
(*it)->output();
}
}
}
void calculateSalary() {
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
(*it)->calculateSalary();
}
}
void outputEmployee() const {
cout << "经理信息:" << endl;
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getPosition() == "经理") {
(*it)->output();
}
}
cout << "技术员信息:" << endl;
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getPosition() == "技术员") {
(*it)->output();
}
}
cout << "销售员信息:" << endl;
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getPosition() == "销售员") {
(*it)->output();
}
}
cout << "计时工信息:" << endl;
for (auto it = m_employeeList.begin(); it != m_employeeList.end(); ++it) {
if ((*it)->getPosition() == "计时工") {
(*it)->output();
}
}
}
private:
vector<Employee*> m_employeeList; // 员工列表
};
// 菜单
void showMenu() {
cout << "=========================" << endl;
cout << "1. 数据录入" << endl;
cout << "2. 数据查询" << endl;
cout << "3. 职工信息的删除、修改" << endl;
cout << "4. 工资计算" << endl;
cout << "5. 数据输出" << endl;
cout << "6. 设置用户名和密码" << endl;
cout << "0. 退出系统" << endl;
cout << "=========================" << endl;
}
int main() {
EmployeeManager employeeManager;
// 数据录入
cout << "请输入各种员工信息:" << endl;
for (int i = 0; i < 3; ++i) {
Manager* manager = new Manager(0, "", "经理");
manager->input();
employeeManager.addEmployee(manager);
}
for (int i = 0; i < 3; ++i) {
Technician* technician = new Technician(0, "", "技术员");
technician->input();
employeeManager.addEmployee(technician);
}
for (int i = 0; i < 3; ++i) {
Salesman* salesman = new Salesman(0, "", "销售员");
salesman->input();
employeeManager.addEmployee(salesman);
}
for (int i = 0; i < 3; ++i) {
HourlyWorker* hourlyWorker = new HourlyWorker(0, "", "计时工");
hourlyWorker->input();
employeeManager.addEmployee(hourlyWorker);
}
// 菜单循环
while (true) {
showMenu();
int choice;
cin >> choice;
switch (choice) {
case 0: // 退出系统
cout << "谢谢使用,再见!" << endl;
return 0;
case 1: // 数据录入
cout << "请输入需要录入的员工类型(1-经理,2-技术员,3-销售员,4-计时工):";
int type;
cin >> type;
switch (type) {
case 1: {
Manager* manager = new Manager(0, "", "经理");
manager->input();
employeeManager.addEmployee(manager);
break;
}
case 2: {
Technician* technician = new Technician(0, "", "技术员");
technician->input();
employeeManager.addEmployee(technician);
break;
}
case 3: {
Salesman* salesman = new Salesman(0, "", "销售员");
salesman->input();
employeeManager.addEmployee(salesman);
break;
}
case 4: {
HourlyWorker* hourlyWorker = new HourlyWorker(0, "", "计时工");
hourlyWorker->input();
employeeManager.addEmployee(hourlyWorker);
break;
}
default:
cout << "输入有误!" << endl;
break;
}
break;
case 2: // 数据查询
cout << "请输入需要查询的员工类型(1-工号查询,2-姓名查询):";
int searchType;
cin >> searchType;
switch (searchType) {
case 1: {
int id;
cout << "请输入需要查询的工号:";
cin >> id;
employeeManager.searchEmployee(id);
break;
}
case 2: {
string name;
cout << "请输入需要查询的姓名:";
cin >> name;
employeeManager.searchEmployee(name);
break;
}
default:
cout << "输入有误!" << endl;
break;
}
break;
case 3: // 职工信息的删除、修改
cout << "请输入需要操作的员工类型(1-删除,2-修改):";
int modifyType;
cin >> modifyType;
switch (modifyType) {
case 1: { // 删除
int id;
cout << "请输入需要删除的工号:";
cin >> id;
employeeManager.deleteEmployee(id);
break;
}
case 2: { // 修改
int id;
cout << "请输入需要修改的工号:";
cin >> id;
employeeManager.modifyEmployee(id);
break;
}
default:
cout << "输入有误!" << endl;
break;
}
break;
case 4: // 工资计算
employeeManager.calculateSalary();
cout << "工资计算完成!" << endl;
break;
case 5: // 数据输出
employeeManager.outputEmployee();
break;
case 6: // 设置用户名和密码
string username, password;
cout << "请输入用户名:";
cin >> username;
cout << "请输入密码:";
cin >> password;
cout << "用户名和密码设置成功!" << endl;
break;
default:
cout << "输入有误!" << endl;
break;
}
}
return 0;
}
```
阅读全文