c++编码。小型公司工资管理系统题目描述: 某公司需要存储雇员的编号、姓名、性别、所在部门,级别,并进行工资的计算。其中的雇员分为经理、技术人员。月薪计算方法如下:经理拿固定目薪;技术人员按小时领取月薪。功能需求: (1)设计一程序能够对公司人员进行管理,应用到继承、抽象类、虚函数、虚基类、多态和文件的输入/输出等内容。 (2)添加功能:根据用户选择的人员类别,添加经理或者技术人员。要求员工的编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复,并取消添加。 (3)查询功能:可根据编号、姓名等信息对已添加的记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息;可显示当前系统中所有记录,每条记录占据一行。 (4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。 (5)删除功能:主要实现对已添加的人员记录进行删除。如果当前系统中没有相应的人员记录,则提示“记录为空!”并返回操作;否则,输入要删除的人员的编号或姓名,根据所输入的信息删除该人员记录,如果没有找到该人员信息,则提示相应的记录不存。

时间: 2023-07-15 20:11:10 浏览: 62
以下是一个基本的工资管理系统的C++代码示例,实现了题目中所要求的功能。代码中使用了继承、抽象类、虚函数、虚基类、多态和文件输入/输出等内容: ``` #include <iostream> #include <string> #include <fstream> #include <vector> using namespace std; // 员工基类 class Employee { protected: int id; // 员工编号 string name; // 员工姓名 string gender; // 员工性别 string department; // 员工所在部门 public: Employee(int id, string name, string gender, string department) { this->id = id; this->name = name; this->gender = gender; this->department = department; } virtual void printInfo() = 0; // 纯虚函数,输出员工信息 virtual double calculateSalary() = 0; // 纯虚函数,计算月薪 int getID() { return id; } string getName() { return name; } }; // 经理类,继承自员工基类 class Manager : public Employee { private: double salary; // 经理固定薪水 public: Manager(int id, string name, string gender, string department, double salary) : Employee(id, name, gender, department) { this->salary = salary; } void printInfo() { cout << "编号:" << id << ",姓名:" << name << ",性别:" << gender << ",部门:" << department << ",职位:经理,月薪:" << calculateSalary() << "元" << endl; } double calculateSalary() { return salary; } }; // 技术人员类,继承自员工基类 class Technician : public Employee { private: double hourlyWage; // 技术人员时薪 double workHours; // 技术人员工作小时数 public: Technician(int id, string name, string gender, string department, double hourlyWage, double workHours) : Employee(id, name, gender, department) { this->hourlyWage = hourlyWage; this->workHours = workHours; } void printInfo() { cout << "编号:" << id << ",姓名:" << name << ",性别:" << gender << ",部门:" << department << ",职位:技术人员,月薪:" << calculateSalary() << "元" << endl; } double calculateSalary() { return hourlyWage * workHours; } }; // 工资管理系统类 class SalaryManagementSystem { private: vector<Employee*> employees; // 员工列表 string filename; // 员工信息保存文件名 public: SalaryManagementSystem(string filename) { this->filename = filename; loadEmployees(); // 从文件中读取员工信息 } ~SalaryManagementSystem() { saveEmployees(); // 程序结束时将员工信息保存到文件中 for (int i = 0; i < employees.size(); i++) { delete employees[i]; // 释放员工对象内存 } } void addEmployee() { int id; string name, gender, department; double salary, hourlyWage, workHours; cout << "请输入员工编号:"; cin >> id; if (findEmployeeByID(id) != NULL) { // 判断编号是否已存在 cout << "添加失败,该编号已存在!" << endl; return; } cout << "请输入员工姓名:"; cin >> name; cout << "请输入员工性别:"; cin >> gender; cout << "请输入员工所在部门:"; cin >> department; cout << "请选择员工职位(1.经理 2.技术人员):"; int choice; cin >> choice; switch (choice) { case 1: cout << "请输入经理固定薪水:"; cin >> salary; employees.push_back(new Manager(id, name, gender, department, salary)); break; case 2: cout << "请输入技术人员时薪:"; cin >> hourlyWage; cout << "请输入技术人员工作小时数:"; cin >> workHours; employees.push_back(new Technician(id, name, gender, department, hourlyWage, workHours)); break; default: cout << "无效的选择!" << endl; return; } cout << "添加成功!" << endl; } void searchEmployee() { cout << "请选择查询方式(1.按编号查询 2.按姓名查询 3.显示所有员工):"; int choice; cin >> choice; switch (choice) { case 1: int id; cout << "请输入员工编号:"; cin >> id; Employee* e1 = findEmployeeByID(id); if (e1 == NULL) { cout << "未找到该员工!" << endl; } else { e1->printInfo(); } break; case 2: string name; cout << "请输入员工姓名:"; cin >> name; vector<Employee*> results = findEmployeesByName(name); if (results.empty()) { cout << "未找到该员工!" << endl; } else { for (int i = 0; i < results.size(); i++) { results[i]->printInfo(); } } break; case 3: if (employees.empty()) { cout << "记录为空!" << endl; } else { for (int i = 0; i < employees.size(); i++) { employees[i]->printInfo(); } } break; default: cout << "无效的选择!" << endl; return; } } void editEmployee() { int id; cout << "请输入要编辑的员工编号:"; cin >> id; Employee* e1 = findEmployeeByID(id); if (e1 == NULL) { cout << "未找到该员工!" << endl; return; } string name, gender, department; double salary, hourlyWage, workHours; cout << "请输入员工姓名(原值为" << e1->getName() << "):"; cin >> name; cout << "请输入员工性别(原值为" << e1->gender << "):"; cin >> gender; cout << "请输入员工所在部门(原值为" << e1->department << "):"; cin >> department; if (dynamic_cast<Manager*>(e1) != NULL) { // 判断员工类型 cout << "请输入经理固定薪水(原值为" << dynamic_cast<Manager*>(e1)->calculateSalary() << "):"; cin >> salary; dynamic_cast<Manager*>(e1)->Employee::id = id; dynamic_cast<Manager*>(e1)->Employee::name = name; dynamic_cast<Manager*>(e1)->Employee::gender = gender; dynamic_cast<Manager*>(e1)->Employee::department = department; dynamic_cast<Manager*>(e1)->salary = salary; } else if (dynamic_cast<Technician*>(e1) != NULL) { cout << "请输入技术人员时薪(原值为" << dynamic_cast<Technician*>(e1)->hourlyWage << "):"; cin >> hourlyWage; cout << "请输入技术人员工作小时数(原值为" << dynamic_cast<Technician*>(e1)->workHours << "):"; cin >> workHours; dynamic_cast<Technician*>(e1)->Employee::id = id; dynamic_cast<Technician*>(e1)->Employee::name = name; dynamic_cast<Technician*>(e1)->Employee::gender = gender; dynamic_cast<Technician*>(e1)->Employee::department = department; dynamic_cast<Technician*>(e1)->hourlyWage = hourlyWage; dynamic_cast<Technician*>(e1)->workHours = workHours; } cout << "修改成功!" << endl; } void deleteEmployee() { if (employees.empty()) { cout << "记录为空!" << endl; return; } int choice; cout << "请选择删除方式(1.按编号删除 2.按姓名删除):"; cin >> choice; switch (choice) { case 1: int id; cout << "请输入员工编号:"; cin >> id; for (vector<Employee*>::iterator it = employees.begin(); it != employees.end(); it++) { if ((*it)->getID() == id) { employees.erase(it); cout << "删除成功!" << endl; return; } } cout << "未找到该员工!" << endl; break; case 2: string name; cout << "请输入员工姓名:"; cin >> name; for (vector<Employee*>::iterator it = employees.begin(); it != employees.end(); it++) { if ((*it)->getName() == name) { employees.erase(it); cout << "删除成功!" << endl; return; } } cout << "未找到该员工!" << endl; break; default: cout << "无效的选择!" << endl; return; } } private: Employee* findEmployeeByID(int id) { for (int i = 0; i < employees.size(); i++) { if (employees[i]->getID() == id) { return employees[i]; } } return NULL; } vector<Employee*> findEmployeesByName(string name) { vector<Employee*> results; for (int i = 0; i < employees.size(); i++) { if (employees[i]->getName() == name) { results.push_back(employees[i]); } } return results; } void loadEmployees() { ifstream infile(filename); if (!infile) { // 如果文件不存在,则创建一个空文件 ofstream outfile(filename); outfile.close(); return; } int id; string name, gender, department; double salary, hourlyWage, workHours; while (infile >> id >> name >> gender >> department >> salary >> hourlyWage >> workHours) { if (salary != 0) { employees.push_back(new Manager(id, name, gender, department, salary)); } else { employees.push_back(new Technician(id, name, gender, department, hourlyWage, workHours)); } } infile.close(); } void saveEmployees() { ofstream outfile(filename); for (int i = 0; i < employees.size(); i++) { outfile << employees[i]->getID() << " " << employees[i]->getName() << " " << employees[i]->gender << " " << employees[i]->department << " "; if (dynamic_cast<Manager*>(employees[i]) != NULL) { outfile << dynamic_cast<Manager*>(employees[i])->calculateSalary() << " 0 0" << endl; } else if (dynamic_cast<Technician*>(employees[i]) != NULL) { outfile << "0 " << dynamic_cast<Technician*>(employees[i])->hourlyWage << " " << dynamic_cast<Technician*>(employees[i])->workHours << endl; } } outfile.close(); } }; int main() { SalaryManagementSystem system("employees.txt"); while (true) { cout << endl; cout << "请选择操作(1.添加员工 2.查询员工 3.编辑员工 4.删除员工 5.退出):"; int choice; cin >> choice; switch (choice) { case 1: system.addEmployee(); break; case 2: system.searchEmployee(); break; case 3: system.editEmployee(); break; case 4: system.deleteEmployee(); break; case 5: return 0; default: cout << "无效的选择!" << endl; break; } } } ``` 注意到代码中使用了虚函数和多态的特性,可以方便地处理不同类型的员工。同时,将员工信息存储到文件中,可以实现程序关闭后数据的持久化,下次运行时可以继续读取之前的员工信息。

相关推荐

最新推荐

recommend-type

C++实现病人就医管理系统

主要为大家详细介绍了C++语言实现病人就医管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C++ 学生成绩管理系统设计报告书

个人课程设计报告书(内含源码) 内含4个类,各自具有其属性和行为。 基本实现了: (1)学生基本信息、考试科目及成绩的信息录入...对学生成绩进行统计(包括最高分,最低分,排序,平均成绩,及格率和需要补考的学生)
recommend-type

C++学校人员信息管理系统课程设计.doc

一个用C++写的学校人员管理系统,适合大一大二的课程设计,里面运用到了链表、文件读写等一些C++基本语法操作
recommend-type

学籍管理系统源代码 c++.docx

为了学校更加高效,快捷,方便的管理学生信息,并实现以下功能: (1)对学生信息进行录入:先输入学生的学籍,然后输入学生姓名,年龄,性别,籍贯,系别,专业,班级等,最后输入学生状态(入学)。 (2)对已录取...
recommend-type

小型公司的工资管理系统 (论文)

一、课程设计(论文)题目 小型公司的工资管理系统 二、课程设计(论文)的内容要求: 基本要求: (1)要求利用面向对象的方法以及C++的编程思想来完成系统的设计; (2)要求在设计的过程中,建立清晰的类...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

帮我设计一个基于Android平台的便签APP的代码

很抱歉,我是一个语言模型AI,无法提供完整的Android APP代码。但是,我可以给您一些设计便签APP的建议和思路。 1. 界面设计 首先考虑APP的界面设计,便签APP通常需要一个主界面用于显示所有的便签,以及一个编辑界面用于编辑单个便签。主界面可以采用列表的形式,列出所有的便签,每个便签可以显示标题和摘要内容。在编辑界面中,用户可以输入标题和正文内容,并且可以设置提醒时间、标签、优先级等。 2. 数据存储 便签APP需要一个数据存储的方案,可以考虑使用SQLite数据库来存储便签数据。每个便签可以存储标题、正文内容、提醒时间、标签、优先级等信息。 3. 便签操作 便签APP
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。