IT 7.小型公司工资管理系统题目描述: 某公司需要存储雇员的编号、姓名、性别、所在部门,级别,并进行工资的计算。其中的雇员分为经理、技术人员。月薪计算方法如下:经理拿固定目薪;技术人员按小时领取月薪。功能需求: (1)设计一程序能够对公司人员进行管理,应用到继承、抽象类、虚函数、虚基类、多态和文件的输入/输出等内容。 (2)添加功能:根据用户选择的人员类别,添加经理或者技术人员。要求员工的编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复,并取消添加。 (3)查询功能:可根据编号、姓名等信息对已添加的记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息;可显示当前系统中所有记录,每条记录占据一行。 (4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。 (5)删除功能:主要实现对已添加的人员记录进行删除。如果当前系统中没有相应的人员记录,则提示“记录为空!”并返回操作;否则,输入要删除的人员的编号或姓名,根据所输入的信息删除该人员记录,如果没有找到该人员信息,则提示相应的记录不存。 (6)统计功能:能根据多种参数进行人员的统计。
时间: 2023-07-15 16:11:21 浏览: 76
针对该题目的需求,可以设计以下类:
1.员工类 Employee
- 属性:编号、姓名、性别、所在部门、级别
- 方法:虚函数,计算月薪
2.经理类 Manager,继承自员工类 Employee
- 属性:固定目薪
- 方法:重写计算月薪方法
3.技术人员类 Technician,继承自员工类 Employee
- 属性:小时工资
- 方法:重写计算月薪方法
4.工资管理系统类 SalaryManagementSystem
- 属性:员工列表
- 方法:添加员工、查询员工、编辑员工、删除员工、统计员工
其中,员工类 Employee 是一个抽象类,包含计算月薪的虚函数。经理类 Manager 和技术人员类 Technician 分别继承自员工类 Employee,并重写计算月薪的方法。
工资管理系统类 SalaryManagementSystem 包含员工列表属性和对应的操作方法,包括添加员工、查询员工、编辑员工、删除员工、统计员工等。
在主函数中,可以根据用户输入的选择,调用相应的操作方法,实现工资管理系统的功能。同时,可以将员工信息保存到文件中,以便下次启动程序时可以读取员工信息。
相关问题
c++编码。某公司需要存储雇员的编号、姓名、性别、所在部门,级别,并进行工资的计算。其中的雇员分为经理、技术人员。月薪计算方法如下:经理拿固定目薪;技术人员按小时领取月薪。功能需求: (1)设计一程序能够对公司人员进行管理,应用到继承、抽象类、虚函数、虚基类、多态和文件的输入/输出等内容。
以下是一份基本的实现代码,实现了上述功能需求:
```c++
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
// 雇员类
class Employee {
protected:
int id;
string name;
char gender;
string department;
int level;
public:
Employee() {}
Employee(int i, string n, char g, string d, int l) : id(i), name(n), gender(g), department(d), level(l) {}
virtual void printInfo() {}
virtual double getSalary() { return 0; }
};
// 经理类
class Manager : public virtual Employee {
protected:
double salary;
public:
Manager() {}
Manager(int i, string n, char g, string d, int l, double s) : Employee(i, n, g, d, l), salary(s) {}
void printInfo() {
cout << "经理信息:" << endl;
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "性别:" << gender << endl;
cout << "部门:" << department << endl;
cout << "级别:" << level << endl;
cout << "工资:" << salary << endl;
}
double getSalary() { return salary; }
};
// 技术人员类
class Technician : public virtual Employee {
protected:
double hourlyPay;
int hoursWorked;
public:
Technician() {}
Technician(int i, string n, char g, string d, int l, double h, int hw) : Employee(i, n, g, d, l), hourlyPay(h), hoursWorked(hw) {}
void printInfo() {
cout << "技术人员信息:" << endl;
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "性别:" << gender << endl;
cout << "部门:" << department << endl;
cout << "级别:" << level << endl;
cout << "工资:" << getSalary() << endl;
}
double getSalary() { return hourlyPay * hoursWorked; }
};
// 经理兼技术人员类
class ManagerTechnician : public Manager, public Technician {
public:
ManagerTechnician() {}
ManagerTechnician(int i, string n, char g, string d, int l, double s, double h, int hw) : Employee(i, n, g, d, l), Manager(i, n, g, d, l, s), Technician(i, n, g, d, l, h, hw) {}
void printInfo() {
cout << "经理兼技术人员信息:" << endl;
cout << "编号:" << id << endl;
cout << "姓名:" << name << endl;
cout << "性别:" << gender << endl;
cout << "部门:" << department << endl;
cout << "级别:" << level << endl;
cout << "工资:" << getSalary() << endl;
}
double getSalary() { return Manager::getSalary() + Technician::getSalary(); }
};
// 公司类
class Company {
private:
vector<Employee*> employees;
public:
void addEmployee(Employee* e) {
employees.push_back(e);
}
void printAllInfo() {
for (auto e : employees) {
e->printInfo();
cout << endl;
}
}
void saveToFile(string filename) {
ofstream file(filename);
for (auto e : employees) {
file << e->getSalary() << "," << e->id << "," << e->name << "," << e->gender << "," << e->department << "," << e->level << endl;
}
file.close();
}
void loadFromFile(string filename) {
ifstream file(filename);
if (!file.is_open()) {
cout << "文件打开失败!" << endl;
return;
}
string line;
while (getline(file, line)) {
double salary;
int id, level;
string name, department;
char gender;
sscanf(line.c_str(), "%lf,%d,%[^,],%c,%[^,],%d", &salary, &id, &name[0], &gender, &department[0], &level);
if (level == 0) {
Manager* m = new Manager(id, name, gender, department, level, salary);
addEmployee(m);
}
else if (level == 1) {
Technician* t = new Technician(id, name, gender, department, level, salary, 0);
addEmployee(t);
}
else {
double h;
int hw;
sscanf(line.c_str(), "%lf,%d,%[^,],%c,%[^,],%d,%lf,%d", &salary, &id, &name[0], &gender, &department[0], &level, &h, &hw);
ManagerTechnician* mt = new ManagerTechnician(id, name, gender, department, level, salary, h, hw);
addEmployee(mt);
}
}
file.close();
}
};
int main() {
Company c;
Employee* e1 = new Manager(1001, "张三", 'M', "市场部", 0, 8000);
Employee* e2 = new Technician(1002, "李四", 'F', "技术部", 1, 100, 120);
Employee* e3 = new ManagerTechnician(1003, "王五", 'M', "生产部", 2, 10000, 120, 200);
c.addEmployee(e1);
c.addEmployee(e2);
c.addEmployee(e3);
c.printAllInfo();
c.saveToFile("employees.txt");
c.loadFromFile("employees.txt");
c.printAllInfo();
return 0;
}
```
这个程序定义了一个`Employee`雇员类,以及它的两个子类:`Manager`经理类和`Technician`技术人员类。其中,经理类有一个固定的月薪,技术人员类按小时领取月薪。为了实现经理兼技术人员这种情况,定义了`ManagerTechnician`类,继承了经理类和技术人员类。
程序还定义了一个`Company`公司类,负责管理所有的雇员。它提供了添加雇员、打印所有雇员信息、将雇员信息保存到文件、从文件中加载雇员信息等功能。
在`main`函数中,首先创建了三个雇员对象,并添加到公司中。然后打印所有雇员信息,并将雇员信息保存到文件。最后从文件中加载雇员信息,并再次打印所有雇员信息,以验证文件读写功能是否正常。
C++为某公司设计雇员工资发放系统
为某公司设计雇员工资发放系统需要考虑以下几个方面:
1. 员工信息的存储与管理:可以使用数据库来存储员工信息,包括姓名、工号、职位、工资等。
2. 工资计算:需要根据员工的职位、工作时长、加班情况、绩效等因素计算工资,并生成工资单。
3. 工资发放:可以通过银行转账或现金方式发放工资,并记录发放记录。
4. 数据分析:可以对员工工资数据进行分析,了解公司的工资结构和员工绩效情况。
在 C++ 中,可以使用类来表示员工和工资单,使用文件操作来存储和读取员工信息和工资单数据,使用算法和数据结构来计算工资和进行数据分析。同时,需要考虑数据安全性和异常处理等问题,确保系统的稳定性和可靠性。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)