文章来源地址https://www.toymoban.com/news/detail-785662.html
课程设计题目1--链表综合算法设计
一、设计内容
已知简单的人事信息系统中职工记录包含职工编号(no)、职工姓名(name)、部门名称(depname)、职称(title)和工资数(salary)等信息(可以增加其他信息),设计并完成一个简单的人事信息管理系统,要求完成但不限于以下功能:
(1) 增加一个职工信息;
(2) 显示所有职工信息;
(3) 按部门名称分类显示该部门所有职工信息;
(4) 按部门显示各部门职工工资总额;
(5) 删除职工信息(可以删除符合条件的一批记录)
(6) 按职称调整工资;
(7) 可自行增加功能(例如按职工编号排序等其他功能)
二、设计要求
(1)以菜单形式显示,主菜单包括(可以扩展)(1:增加职工信息 2:删除员工信息 3:查找职工信息 4:工资调整 5:统计分析 0:退出)相应的主菜单可以设计子菜单。(根据系统功能的多少评定成绩)
(2)提交设计报告,报告包括代码、设计思路(流程图)和实现界面截图等。
代码实现
#include <iostream>
#include <string>
using namespace std;
// 职工信息结构体
struct Employee {
int no;
string name;
string depname;
string title;
double salary;
Employee* next;
};
// 全局变量,链表头指针
Employee* head = nullptr;
// 操作函数声明
void addEmployee();
void displayAllEmployees();
void displayEmployeesByDepartment();
void displayDepartmentTotalSalary();
void deleteEmployee();
void adjustSalaryByTitle();
void menu();
// 增加一个职工信息
void addEmployee() {
Employee* newEmployee = new Employee;
cout << "请输入职工编号:";
cin >> newEmployee->no;
cout << "请输入职工姓名:";
cin >> newEmployee->name;
cout << "请输入部门名称:";
cin >> newEmployee->depname;
cout << "请输入职称:";
cin >> newEmployee->title;
cout << "请输入工资数:";
cin >> newEmployee->salary;
newEmployee->next = nullptr;
if (head == nullptr) {
head = newEmployee;
}
else {
Employee* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = newEmployee;
}
cout << "职工信息添加成功!" << endl;
}
// 显示所有职工信息
void displayAllEmployees() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
Employee* temp = head;
cout << "所有职工信息:" << endl;
while (temp != nullptr) {
cout << "编号:" << temp->no << endl;
cout << "姓名:" << temp->name << endl;
cout << "部门:" << temp->depname << endl;
cout << "职称:" << temp->title << endl;
cout << "工资:" << temp->salary << endl;
cout << "-------------------------" << endl;
temp = temp->next;
}
}
// 按部门名称分类显示该部门所有职工信息
void displayEmployeesByDepartment() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
string department;
cout << "请输入部门名称:";
cin >> department;
Employee* temp = head;
bool found = false;
cout << "部门" << department << "下的职工信息:" << endl;
while (temp != nullptr) {
if (temp->depname == department) {
cout << "编号:" << temp->no << endl;
cout << "姓名:" << temp->name << endl;
cout << "职称:" << temp->title << endl;
cout << "工资:" << temp->salary << endl;
cout << "-------------------------" << endl;
found = true;
}
temp = temp->next;
}
if (!found) {
cout << "未找到部门" << department << "下的职工信息!" << endl;
}
}
// 按部门显示各部门职工工资总额
void displayDepartmentTotalSalary() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
// 使用一个数组来存储每个部门的工资总额
const int MAX_DEPARTMENTS = 100;
double departmentTotalSalary[MAX_DEPARTMENTS] = { 0.0 };
Employee* temp = head;
while (temp != nullptr) {
departmentTotalSalary[temp->depname.length()] += temp->salary;
temp = temp->next;
}
cout << "各部门职工工资总额:" << endl;
for (int i = 0; i < MAX_DEPARTMENTS; i++) {
if (departmentTotalSalary[i] > 0) {
cout << "部门:" << i << " 工资总额:" << departmentTotalSalary[i] << endl;
}
}
}
// 删除职工信息
void deleteEmployee() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
int employeeNo;
cout << "请输入要删除的职工编号:";
cin >> employeeNo;
Employee* current = head;
Employee* previous = nullptr;
while (current != nullptr) {
if (current->no == employeeNo) {
if (previous == nullptr) {
// 删除头节点
head = current->next;
}
else {
previous->next = current->next;
}
delete current;
cout << "职工信息删除成功!" << endl;
return;
}
previous = current;
current = current->next;
}
cout << "未找到职工编号为" << employeeNo << "的记录!" << endl;
}
// 按职称调整工资
void adjustSalaryByTitle() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
string jobTitle;
cout << "请输入职称:";
cin >> jobTitle;
double salaryAdjustment;
cout << "请输入工资调整金额:";
cin >> salaryAdjustment;
Employee* temp = head;
bool found = false;
while (temp != nullptr) {
if (temp->title == jobTitle) {
temp->salary += salaryAdjustment;
found = true;
}
temp = temp->next;
}
if (found) {
cout << "职称为" << jobTitle << "的职工工资调整成功!" << endl;
}
else {
cout << "未找到职称为" << jobTitle << "的职工!" << endl;
}
}
// 菜单
void menu() {
int choice;
do {
cout << "-------------------------" << endl;
cout << "1. 增加职工信息" << endl;
cout << "2. 显示所有职工信息" << endl;
cout << "3. 按部门分类显示职工信息" << endl;
cout << "4. 按部门显示各部门职工工资总额" << endl;
cout << "5. 删除职工信息" << endl;
cout << "6. 按职称调整工资" << endl;
cout << "0. 退出" << endl;
cout << "请输入您的选择:";
cin >> choice;
switch (choice) {
case 1:
addEmployee();
break;
case 2:
displayAllEmployees();
break;
case 3:
displayEmployeesByDepartment();
break;
case 4:
displayDepartmentTotalSalary();
break;
case 5:
deleteEmployee();
break;
case 6:
adjustSalaryByTitle();
break;
case 0:
cout << "感谢使用人事信息管理系统!" << endl;
break;
default:
cout << "无效的选择!" << endl;
break;
}
} while (choice != 0);
}
int main() {
menu();
return 0;
}
vs代码实现
#include <iostream>
#include <string>
using namespace std;
// 职工信息结构体
struct Employee {
int no;
string name;
string depname;
string title;
double salary;
Employee* next;
};
// 全局变量,链表头指针
Employee* head = nullptr;
// 操作函数声明
void addEmployee();
void displayAllEmployees();
void displayEmployeesByDepartment();
void displayDepartmentTotalSalary();
void deleteEmployee();
void adjustSalaryByTitle();
void menu();
// 增加一个职工信息
void addEmployee() {
Employee* newEmployee = new Employee;
cout << "请输入职工编号:";
cin >> newEmployee->no;
cout << "请输入职工姓名:";
cin >> newEmployee->name;
cout << "请输入部门名称:";
cin >> newEmployee->depname;
cout << "请输入职称:";
cin >> newEmployee->title;
cout << "请输入工资数:";
cin >> newEmployee->salary;
newEmployee->next = nullptr;
if (head == nullptr) {
head = newEmployee;
}
else {
Employee* temp = head;
while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = newEmployee;
}
cout << "职工信息添加成功!" << endl;
}
// 显示所有职工信息
void displayAllEmployees() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
Employee* temp = head;
cout << "所有职工信息:" << endl;
while (temp != nullptr) {
cout << "编号:" << temp->no << endl;
cout << "姓名:" << temp->name << endl;
cout << "部门:" << temp->depname << endl;
cout << "职称:" << temp->title << endl;
cout << "工资:" << temp->salary << endl;
cout << "-------------------------" << endl;
temp = temp->next;
}
}
// 按部门名称分类显示该部门所有职工信息
void displayEmployeesByDepartment() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
string department;
cout << "请输入部门名称:";
cin >> department;
Employee* temp = head;
bool found = false;
cout << "部门" << department << "下的职工信息:" << endl;
while (temp != nullptr) {
if (temp->depname == department) {
cout << "编号:" << temp->no << endl;
cout << "姓名:" << temp->name << endl;
cout << "职称:" << temp->title << endl;
cout << "工资:" << temp->salary << endl;
cout << "-------------------------" << endl;
found = true;
}
temp = temp->next;
}
if (!found) {
cout << "未找到部门" << department << "下的职工信息!" << endl;
}
}
// 按部门显示各部门职工工资总额
void displayDepartmentTotalSalary() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
// 使用一个数组来存储每个部门的工资总额
const int MAX_DEPARTMENTS = 100;
double departmentTotalSalary[MAX_DEPARTMENTS] = { 0.0 };
Employee* temp = head;
while (temp != nullptr) {
departmentTotalSalary[temp->depname.length()] += temp->salary;
temp = temp->next;
}
cout << "各部门职工工资总额:" << endl;
for (int i = 0; i < MAX_DEPARTMENTS; i++) {
if (departmentTotalSalary[i] > 0) {
cout << "部门:" << i << " 工资总额:" << departmentTotalSalary[i] << endl;
}
}
}
// 删除职工信息
void deleteEmployee() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
int employeeNo;
cout << "请输入要删除的职工编号:";
cin >> employeeNo;
Employee* current = head;
Employee* previous = nullptr;
while (current != nullptr) {
if (current->no == employeeNo) {
if (previous == nullptr) {
// 删除头节点
head = current->next;
}
else {
previous->next = current->next;
}
delete current;
cout << "职工信息删除成功!" << endl;
return;
}
previous = current;
current = current->next;
}
cout << "未找到职工编号为" << employeeNo << "的记录!" << endl;
}
// 按职称调整工资
void adjustSalaryByTitle() {
if (head == nullptr) {
cout << "暂无职工信息!" << endl;
return;
}
string jobTitle;
cout << "请输入职称:";
cin >> jobTitle;
double salaryAdjustment;
cout << "请输入工资调整金额:";
cin >> salaryAdjustment;
Employee* temp = head;
bool found = false;
while (temp != nullptr) {
if (temp->title == jobTitle) {
temp->salary += salaryAdjustment;
found = true;
}
temp = temp->next;
}
if (found) {
cout << "职称为" << jobTitle << "的职工工资调整成功!" << endl;
}
else {
cout << "未找到职称为" << jobTitle << "的职工!" << endl;
}
}
// 菜单
void menu() {
int choice;
do {
cout << "-------------------------" << endl;
cout << "1. 增加职工信息" << endl;
cout << "2. 显示所有职工信息" << endl;
cout << "3. 按部门分类显示职工信息" << endl;
cout << "4. 按部门显示各部门职工工资总额" << endl;
cout << "5. 删除职工信息" << endl;
cout << "6. 按职称调整工资" << endl;
cout << "0. 退出" << endl;
cout << "请输入您的选择:";
cin >> choice;
switch (choice) {
case 1:
addEmployee();
break;
case 2:
displayAllEmployees();
break;
case 3:
displayEmployeesByDepartment();
break;
case 4:
displayDepartmentTotalSalary();
break;
case 5:
deleteEmployee();
break;
case 6:
adjustSalaryByTitle();
break;
case 0:
cout << "感谢使用人事信息管理系统!" << endl;
break;
default:
cout << "无效的选择!" << endl;
break;
}
} while (choice != 0);
}
int main() {
menu();
return 0;
}
文章来源:https://www.toymoban.com/news/detail-785662.html
到了这里,关于链表综合算法设计(c++数据结构)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!