C++ 职工信息管理系统项目的二次开发 2252423 雍文轩

来源:同学大二下的期末大作业:职工工资信息管理系统项目。
运行环境:VisualStudio 2022

①项目结构:

②运行结果截图:

主菜单界面:

功能选择界面:

工资总额输出界面:

平均工资输出界面:

显示输出界面:

增加正式员工界面:

增加临时员工界面:

修改数据界面:

③主要问题:
查询功能未完善,有时会出现乱码

④详细代码:

点击查看代码
#include<iostream>
#include<stdio.h>
#include"employee.h"
#include"function.h"
#include"print.h"
using namespace std;

int main() {
	listpoint1 *temp1, *head1;
	listpoint2 *temp2, *head2;

	temp1 = head1 = (listpoint1*)malloc(sizeof(listpoint1));
	temp2 = head2 = (listpoint2*)malloc(sizeof(listpoint2));

	while (true) {
		readCsv(temp1);
		readCsv(temp2);

		printFunction();
		
		int flag;
		cin >> flag;
		
		system("cls");

		if (flag == 8) {
			exit(1);
		}

		int i, j;
		switch (flag)
		{
		case 1://匹配数据
			printFunction1();
			cin >> i;
			system("cls");
			if (i == 1 || i == 2) {
				printFunction1(head1, i);
				printFunction1(head2, i);
			}
			else
			{
				cout << "                                                       输入错误,请重新输入\n";
			}
			cout << "                                                 ";
			system("pause");
			break;
		case 2://按照实发工资排序输出
			printFunction2(head1, head2);
			cout << "                                                 ";
			system("pause");
			break;
		case 3://增加新员工
			printFunction3();
			cin >> i;
			if (i == 1) {
				addEmployee(temp1);
			}
			else if (i == 2) {
				addEmployee(temp2);
			}
			else {
				cout << "                                                       输入错误,请重新输入\n";
			}
			break;
		case 4://修改记录
			printFunction4();
			cin >> i;
			system("cls");
			changeEmplpoyee(i, head1, head2);
			cout << "\n                                                   ";
			system("pause");
			break;
		case 5://删除记录
			printFunction4();
			cin >> i;//要选择删除的员工类型
			printFunction6();
			cin >> j;//要选择删除的方式
			deleteEmplpoyee(i, j, head1, head2);
			cout << "\n                                                   ";
			system("pause");
			break;
		case 6:
			cout << "                                **********************************************************\n";
			cout << endl;
			cout << "                                                   正式员工:" << endl;
			printEmployees(head1);
			cout << endl;
			cout << "                                **********************************************************\n" << endl;
			cout << "                                                   临时员工:" << endl;
			printEmployees(head2);
			cout << endl;
			cout << "                                **********************************************************\n";
			cout << "                                                   ";
			system("pause");
			break;
		default:
			cout << "                                                       输入错误,请重新输入\n";
			break;
		}
		system("cls");
		saveEmployee(head1);
		saveEmployee(head2);
	}

	return 0;
}

⑤主要功能函数代码:

点击查看代码
#ifndef FUNCTION_H_
#define FUNCTION_H_
#include<fstream>
#include"employee.h"
using namespace std;
//typedef struct listpoint1 listpoint1;//用链表的形式暂存正式员工
//typedef struct listpoint2 listpoint2;//用链表的形式暂存临时员工
typedef struct listpoint1 {
	fullTimeEmployee *e;
	bool fireEmployee = false;
	struct listpoint1 *next;
	struct listpoint1 *last;
}listpoint1;
typedef struct listpoint2 {
	temporaryEmployee *e;
	bool fireEmployee = false;
	struct listpoint2 *next;
	struct listpoint2 *last;
}listpoint2;
void addEmployee(listpoint1 *head);//增加正式员工
void addEmployee(listpoint2 *head);//增加临时员工
void writeCsv(fullTimeEmployee e);
void writeCsv(temporaryEmployee e);
void readCsv(listpoint1 *temp);//读取csv文件
void readCsv(listpoint2 *temp);//读取Csv文件
void update(listpoint1 *temp);
void update(listpoint2 *temp);
void printWages(listpoint1 *temp, int i);
void printWages(listpoint2 *temp, int i);
void printEmployee(listpoint1 *temp);
void printEmployee(listpoint2 *temp);
void print(listpoint1 *flag);
void print(listpoint2 *flag);
void printEmployees(listpoint1 *head);
void printEmployees(listpoint2 *head);
listpoint1* findEmplpoyee(listpoint1 *head, int i);
listpoint2* findEmplpoyee(listpoint2 *head, int i);
void printEmplpoyee(int i, int j, listpoint1 *head1, listpoint2 *head2);
void changeEmplpoyee(int i,listpoint1 *head1,listpoint2 *head2);
void deleteEmplpoyee(int i, int j, listpoint1 *head1, listpoint2 *head2);
void saveEmployee(listpoint1 *head);
void saveEmployee(listpoint2 *head);
#endif // !FUNCTION_H_

#pragma once

⑥改进新代码

增加新查询功能,详细代码:

点击查看代码
listpoint1* findEmplpoyee(listpoint1 *head, int i) {
	listpoint1 *temp = head->next;
	string name;

	switch (i)
	{
	case 1:
		int num;
		cout << "                                                   请输入编号:";
		cin >> num;
		for (; temp; temp = temp->next) {
			if (abs(temp->e->getNum()) == num) {
				return temp;
			}
		}
		break;
	case 2:
		cout << "                                                   请输入姓名:";
		cin >> name;
		for (; temp; temp = temp->next) {
			if (temp->e->getName() == name) {
				return temp;
			}
		}
		break;
	case 3:
		int money;
		cout << "                                                   请输入工资:";
		cin >> money;
		for (; temp; temp = temp->next) {
			if (temp->e->getSumMoney() == money) {
				return temp;
			}
		}
		break;
	default:
		cout << "                                                   输入格式有误,请重新输入";
		break;
	}

	return NULL;
}
listpoint2* findEmplpoyee(listpoint2 *head, int i) {
	listpoint2 *temp = head->next;
	string name;

	switch (i)
	{
	case 1:
		int num;
		cout << "                                                   请输入编号:";
		cin >> num;
		for (; temp; temp = temp->next) {
			if (abs(temp->e->getNum()) == num) {
				return temp;
			}
		}
		break;
	case 2:
		cout << "                                                   请输入姓名:";
		cin >> name;
		for (; temp; temp = temp->next) {
			if (temp->e->getName() == name) {
				return temp;
			}
		}
		break;
	case 3:
		int money;
		cout << "                                                   请输入工资:";
		cin >> money; 
		for (; temp; temp = temp->next) {
			if (temp->e->getSumMoney() == money) {
				return temp;
			}
		}
		break;
	default:
		cout << "                                                   输入格式有误,请重新输入";
		break;
	}

	return NULL;
}

void printEmplpoyee(int i, int j, listpoint1 *head1, listpoint2 *head2) {
	if (i == 1) {
		listpoint1 *flag = findEmplpoyee(head1, j);
		if (flag == NULL) {
			cout << "                                                   未找到目标职员或目标以全部输出";
		}
		else{
			print(flag);
		}
		if (j == 3 && flag->next) {
			printEmplpoyee(1, 3, flag, head2);
		}
	}
	else if(i == 2){
		listpoint2 *flag = findEmplpoyee(head2, j);
		if (flag == NULL) {
			cout << "                                                   未找到目标职员或目标以全部输出";
		}
		else {
			print(flag);
		}
		if (j == 3 && flag->next) {
			printEmplpoyee(1, 3, head1, flag);
		}
	}
	else{
		cout << "                                                   输入员工类型有误";
	}
}

功能截图:

⑦总结

二次开发的过程是对开发过程的深入理解和灵活运用的过程,需要理解原有系统的架构、功能、数据结构等,这要求开发者对开发工作有更深入的理解。同时,二次开发需要解决原有系统存在的问题,这要求开发者具备灵活的思维和解决问题的能力。

posted on 2024-03-05 17:18  Decoi  阅读(57)  评论(0)    收藏  举报