来源:同学大二下的期末大作业:网上购书系统项目。
运行环境: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;
}
⑤改进新代码
增加新查询功能,详细代码:
点击查看代码
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 << " 输入员工类型有误";
}
}
功能截图:
⑥总结
二次开发的过程是对开发过程的深入理解和灵活运用的过程,需要理解原有系统的架构、功能、数据结构等,这要求开发者对开发工作有更深入的理解。同时,二次开发需要解决原有系统存在的问题,这要求开发者具备灵活的思维和解决问题的能力。
标签:case,cout,temp,int,C++,next,flag,二次开发,ywx From: https://www.cnblogs.com/Decoi/p/18054476