用c++写一个使用顺序表的员工管理系统

时间: 2024-05-15 08:12:51 浏览: 10
好的,以下是一个简单的使用顺序表实现员工管理系统的C++代码: ```cpp #include <iostream> #include <cstring> using namespace std; const int MAX_SIZE = 100; // 最大员工数量 // 员工结构体 struct Employee { int id; // 员工编号 char name[20]; // 员工姓名 int age; // 员工年龄 char gender; // 员工性别 }; // 员工管理系统类 class EmployeeManagementSystem { public: EmployeeManagementSystem() : size(0) {} // 构造函数,初始员工数量为0 ~EmployeeManagementSystem() {} // 析构函数 void addEmployee(); // 添加员工 void deleteEmployee(); // 删除员工 void modifyEmployee(); // 修改员工信息 void searchEmployee(); // 查找员工信息 void displayAllEmployees(); // 显示所有员工信息 private: Employee employees[MAX_SIZE]; // 员工数组 int size; // 员工数量 }; void EmployeeManagementSystem::addEmployee() { if (size >= MAX_SIZE) { cout << "员工数量已达到上限,无法添加新员工!" << endl; return; } Employee e; cout << "请输入员工编号:"; cin >> e.id; cout << "请输入员工姓名:"; cin >> e.name; cout << "请输入员工年龄:"; cin >> e.age; cout << "请输入员工性别(M/F):"; cin >> e.gender; employees[size++] = e; // 将新员工添加到数组末尾 cout << "添加成功!" << endl; } void EmployeeManagementSystem::deleteEmployee() { if (size == 0) { cout << "员工列表为空,无法删除员工!" << endl; return; } int id; cout << "请输入要删除的员工编号:"; cin >> id; int index = -1; for (int i = 0; i < size; i++) { if (employees[i].id == id) { index = i; break; } } if (index == -1) { cout << "未找到要删除的员工!" << endl; return; } for (int i = index; i < size - 1; i++) { employees[i] = employees[i + 1]; // 将后面的员工向前移动 } size--; // 员工数量减1 cout << "删除成功!" << endl; } void EmployeeManagementSystem::modifyEmployee() { if (size == 0) { cout << "员工列表为空,无法修改员工信息!" << endl; return; } int id; cout << "请输入要修改的员工编号:"; cin >> id; int index = -1; for (int i = 0; i < size; i++) { if (employees[i].id == id) { index = i; break; } } if (index == -1) { cout << "未找到要修改的员工!" << endl; return; } Employee e; cout << "请输入员工姓名(原值为" << employees[index].name << "):"; cin >> e.name; cout << "请输入员工年龄(原值为" << employees[index].age << "):"; cin >> e.age; cout << "请输入员工性别(M/F,原值为" << employees[index].gender << "):"; cin >> e.gender; e.id = id; employees[index] = e; // 将修改后的员工信息替换原有信息 cout << "修改成功!" << endl; } void EmployeeManagementSystem::searchEmployee() { if (size == 0) { cout << "员工列表为空,无法查找员工信息!" << endl; return; } int id; cout << "请输入要查找的员工编号:"; cin >> id; int index = -1; for (int i = 0; i < size; i++) { if (employees[i].id == id) { index = i; break; } } if (index == -1) { cout << "未找到要查找的员工!" << endl; return; } Employee e = employees[index]; cout << "员工编号:" << e.id << endl; cout << "员工姓名:" << e.name << endl; cout << "员工年龄:" << e.age << endl; cout << "员工性别:" << e.gender << endl; } void EmployeeManagementSystem::displayAllEmployees() { if (size == 0) { cout << "员工列表为空!" << endl; return; } cout << "员工列表:" << endl; for (int i = 0; i < size; i++) { Employee e = employees[i]; cout << "员工编号:" << e.id << endl; cout << "员工姓名:" << e.name << endl; cout << "员工年龄:" << e.age << endl; cout << "员工性别:" << e.gender << endl; } } int main() { EmployeeManagementSystem ems; while (true) { cout << "请选择操作:" << endl; cout << "1. 添加员工" << endl; cout << "2. 删除员工" << endl; cout << "3. 修改员工信息" << endl; cout << "4. 查找员工信息" << endl; cout << "5. 显示所有员工信息" << endl; cout << "6. 退出" << endl; int choice; cin >> choice; switch (choice) { case 1: ems.addEmployee(); break; case 2: ems.deleteEmployee(); break; case 3: ems.modifyEmployee(); break; case 4: ems.searchEmployee(); break; case 5: ems.displayAllEmployees(); break; case 6: return 0; default: cout << "无效操作!" << endl; } cout << endl; } return 0; } ``` 这个员工管理系统使用顺序表来存储员工信息,可以添加、删除、修改、查找和显示所有员工信息。运行时,会显示一个菜单供用户选择操作,直到用户选择退出为止。

相关推荐

最新推荐

recommend-type

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

内含4个类,各自具有其属性和行为。 基本实现了: (1)学生基本信息、考试科目及成绩的信息录入。 (2)已有学生信息的显示。 (3)学生基本信息的读取和保存输入数据等功能 (4)学生基本信息的查询与修改。可以对已有的...
recommend-type

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

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

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

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

linux系统中c++写日志文件功能分享

主要介绍了linux系统中c++写日志文件功能,简化了glog,只保留了写日志文件的功能,只是改写了linux版本,需要的朋友可以参考下
recommend-type

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

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

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

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