C++小型公司工资管理系统

敬请T期待 Lv3

课题要求

“小型公司工资管理系统设计”

1问题描述

某公司需要存储雇员的编号、姓名、性别、所在部门,级别,并进行工资的计算。其中,雇员分为经理、技术人员、销售人员和销售经理。四类人员的月薪计算方法如下:经理拿固定月薪;技术人员按小时领取月薪;销售人员按其当月销售额的提成领取工资;销售经理既拿固定月薪也领取销售提成。

设计一程序能够对公司人员进行管理,应用到继承、抽象类、虚函数、虚基类、多态和文件的输入/输出等内容。

2功能要求

(1)添加功能:程序能够任意添加上述四类人员的记录,可提供选择界面供用户选择所要添加的人员类别,要求员工的编号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加。

(2)查询功能:可根据编号、姓名等信息对已添加的记录进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息;

(3)显示功能:可显示当前系统中所有记录,每条记录占据一行。

(4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。

(5)删除功能:主要实现对已添加的人员记录进行删除。如果当前系统中没有相应的人员记录,则提示“记录为空!”并返回操作;否则,输入要删除的人员的编号或姓名,根据所输入的信息删除该人员记录,如果没有找到该人员信息,则提示相应的记录不存。

(6)统计功能:能根据多种参数进行人员的统计。例如,统计四类人员数量以及总数,

或者统计男、女员工的数量,或者统计平均工资、最高工资、最低工资等信息。

(7)保存功能:可将当前系统中各类人员记录存入文件中,存入方式任意。

(8)读取功能:可将保存在文件中的人员信息读入到当前系统中,供用户进行使用。

3问题的解决方案

根据系统功能要求,可以将问题解决分为以下步骤:

(1)应用系统分析,建立该系统的功能模块框图以及界面的组织和设计;

(2)分析系统中的各个实体及它们之间的关系;

(3)根据问题描述,设计系统的类层次;

(4)完成类层次中各个类的描述;

(5)完成类中各个成员函数的定义;

(6)完成系统的应用模块;

(7)功能调试;

(8)完成系统总结报告。

main.cpp

1
2
3
4
5
6
7
8
9
10
11
#include"employee.h"

int main()
{
init_list();
load();
system("pause");
system("cls");
menu();
return 0;
}

employee.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include <windows.h>
#include<stdlib.h>
using namespace std;

class Employee_base {
public:
Employee_base();
Employee_base(int i, string n, string g, string d, string l, double s,string t) :id(i), name(n), gender(g), department(d), level(l), Salary(s),type(t) {};
virtual double calculateSalary() const = 0;
int getId();
string getname();
string getgender();
string getdepartment();
string getlevel();
double getsalary();
string gettype();
protected:
int id;//编号
string name;//姓名
string gender;//性别
string department;//部门
string level;//级别
double Salary;
string type;//类型
};
class Manager:virtual public Employee_base
{
public:
Manager();
Manager(int i, string n, string g, string d, string l, double s,double m,string t) :Employee_base(i,n,g,d,l,s,t),MonthSalary(m){}
double calculateSalary() const;
void addmanager();
protected:
double MonthSalary;//月薪
};
class Salesperson :virtual public Employee_base
{
public:
Salesperson();
Salesperson(int i, string n, string g, string d, string l, double s,double sa,double c,string t) :Employee_base(i, n, g, d, l, s,t) ,SalesAmount(sa),commision(c){}
double calculateSalary()const;
void addsalesperson();
protected:
double SalesAmount;//销售额
double commision;//提成率
};
class SalesManager :virtual public Employee_base
{
public:
SalesManager();
SalesManager(int i, string n, string g, string d, string l, double s,double m,double sa,double c,string t) :Employee_base(i, n, g, d, l, s,t),MonthSalary(m),SalesAmount(sa),commision(c) {}
double calculateSalary()const;
void addsalesmanager();
protected:
double MonthSalary;
double SalesAmount;
double commision;
};
class Technician :virtual public Employee_base
{
public:
Technician();
Technician(int i, string n, string g, string d, string l, double s,double t,double h,string ty) :Employee_base(i, n, g, d, l, s,ty),time(t),hourlyWage(h){}
double calculateSalary()const;
void addtechnician();
protected:
double time;//工作时间
double hourlyWage;//时薪
};
class Employees:virtual public Manager, virtual public Salesperson, virtual public SalesManager, virtual public Technician
{
public:
void add_employee();
double calculateSalary()const;
void showEmployees();
void modifyname();//修改姓名
void modifygender();//修改性别
void modifydepartment();//修改部门
void modifylevel();//修改级别
void modifysalary();//修改工资
void saveid(int Id);
void savename(string Name);
void savegender(string gender);
void savedepartment(string department);
void savelevel(string level);
void savesalary(double salary);
};
typedef struct Node
{
Manager m;
Salesperson s;
SalesManager sm;
Technician t;
Employees e;
Node* next;
}Node,*Linklist;

int Ide(int Id);
int listlength();
void clear_buffer();
void init_list();
void menu();
void add_employee();
void query_employee();
void display_all();
void modify_employee();
void delete_employee();
void static_employee();
void save();
void load();

employee.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#include"employee.h"
Linklist head = NULL;

/*基类抽象函数*/
Employee_base::Employee_base()
{
id = NULL;
name = "NULL";
gender = "NULL";
department = "NULL";
level = "NULL";
Salary = NULL;
type = "NULL";
}
int Employee_base::getId() {
return id;
}
string Employee_base::getname() {
return name;
}
string Employee_base::getgender() {
return gender;
}
string Employee_base::getdepartment() {
return department;
}
string Employee_base::getlevel() {
return level;
}
double Employee_base::getsalary() {
//Salary = calculateSalary();
return Salary;
}
string Employee_base::gettype() {
return type;
}

/*派生类构造函数*/
Manager::Manager()
{
id = NULL;
name = "NULL";
gender = "NULL";
department = "NULL";
level = "NULL";
Salary = NULL;
MonthSalary = NULL;
type = "经理";
}
Salesperson::Salesperson()
{
id = NULL;
name = "NULL";
gender = "NULL";
department = "NULL";
level = "NULL";
Salary = NULL;
SalesAmount = NULL;
commision = NULL;
type = "销售人员";
}
SalesManager::SalesManager()
{
id = NULL;
name = "NULL";
gender = "NULL";
department = "NULL";
level = "NULL";
Salary = NULL;
MonthSalary = NULL;
SalesAmount = NULL;
commision = NULL;
type = "销售经理";
}
Technician::Technician()
{
id = NULL;
name = "NULL";
gender = "NULL";
department = "NULL";
level = "NULL";
Salary = NULL;
time = NULL;
hourlyWage = NULL;
type = "技术人员";
}

/*派生类成员添加函数*/
void Manager::addmanager() {
int Id;
cout << "请输入经理编号:";
cin >> Id;
id=Ide(Id);
cout << "请输入经理姓名:";
cin >> name;
cout << "请输入经理性别【男|女】:";
cin >> gender;
cout << "请输入经理部门【销售部、技术部、人事部】:";
cin >> department;
cout << "请输入经理级别【初级、中级、高级】:";
cin >> level;
cout << "请输入经理的月薪:";
cin >> MonthSalary;
Salary = MonthSalary;
}
void Salesperson::addsalesperson() {
int Id;
cout << "请输入销售人员编号:";
cin >> Id;
id = Ide(Id);
cout << "请输入销售人员姓名:";
cin >> name;
cout << "请输入销售人员性别【男|女】:";
cin >> gender;
cout << "请输入销售人员部门【销售部、技术部、人事部】:";
cin >> department;
cout << "请输入销售人员级别【初级、中级、高级】:";
cin >> level;
cout << "请输入销售人员销售额:";
cin >> SalesAmount;
cout << "请输入销售人员提成率:";
cin >> commision;
Salary = SalesAmount * commision;
}
void SalesManager::addsalesmanager() {
int Id;
cout << "请输入销售经理编号:";
cin >> Id;
id = Ide(Id);
cout << "请输入销售经理姓名:";
cin >> name;
cout << "请输入销售经理性别【男|女】:";
cin >> gender;
cout << "请输入销售经理部门【销售部、技术部、人事部】:";
cin >> department;
cout << "请输入销售经理级别【初级、中级、高级】:";
cin >> level;
cout << "请输入销售经理的月薪:";
cin >> MonthSalary;
cout << "请输入销售经理销售额:";
cin >> SalesAmount;
cout << "请输入销售经理提成率:";
cin >> commision;
Salary = (SalesAmount * commision)+ MonthSalary;
}
void Technician::addtechnician() {
int Id;
cout << "请输入技术人员编号:";
cin >> Id;
id = Ide(Id);
cout << "请输入技术人员姓名:";
cin >> name;
cout << "请输入技术人员性别【男|女】:";
cin >> gender;
cout << "请输入技术人员部门【销售部、技术部、人事部】:";
cin >> department;
cout << "请输入技术人员级别【初级、中级、高级】:";
cin >> level;
cout << "请输入技术人员的时薪:";
cin >> hourlyWage;
cout << "请输入技术人员的工作时间:";
cin >> time;
Salary = time * hourlyWage;
}
void Employees::add_employee()
{
int Id;
cout << "请输入员工编号:";
cin >> Id;
id = Ide(Id);
cout << "请输入员工姓名:";
cin >> name;
cout << "请输入员工性别【男|女】:";
cin >> gender;
cout << "请输入员工部门【销售部、技术部、人事部】:";
cin >> department;
cout << "请输入员工级别【初级、中级、高级】:";
cin >> level;
}
/*派生类工资计算函数*/
double Manager::calculateSalary()const {
return MonthSalary;
}
double Salesperson::calculateSalary() const {
return SalesAmount * commision;
}
double SalesManager::calculateSalary() const {
return (SalesAmount * commision) + MonthSalary;
}
double Technician::calculateSalary()const {
return hourlyWage * time;
}
//Employees功能函数
double Employees::calculateSalary()const {
if (type == "经理") {
return Manager::calculateSalary();
}
if (type == "销售人员") {
return Salesperson::calculateSalary();
}
if (type == "销售经理") {
return SalesManager::calculateSalary();
}
if (type == "技术人员") {
return Technician::calculateSalary();
}
}
void Employees::showEmployees() {
cout << "\t" << id << "\t\t" << name << "\t\t" << gender << "\t\t" << department << "\t\t" << level << "\t\t" << Salary << endl;
}
void Employees::modifyname() {
cout << "请输入需要修改的姓名:";
cin >> name;
}
void Employees::modifygender() {
cin >> gender;
cout << "请输入需要修改的性别:";
}
void Employees::modifydepartment(){
cout << "请输入需要调换的部门:";
cin >> department;
}
void Employees::modifylevel() {
cout << "请输入需要更新的级别:";
cin >> level;
}
void Employees::modifysalary() {
cout << "请输入修改后工资:";
cin >> Salary;
}
//Employees保存函数
void Employees::saveid( int Id) {
id = Id;
}
void Employees::savename(string Name) {
name = Name;
}
void Employees::savegender(string Gender) {
gender = Gender;
}
void Employees::savedepartment(string Department) {
department = Department;
}
void Employees::savelevel(string Level) {
level = Level;
}
void Employees::savesalary(double salary) {
Salary = salary;
}

/*功能函数*/
int listlength(){
int length=0;
Linklist current = head->next;
while (current != NULL)
{
length++;
current = current->next;
}
return length;
}
void init_list()
{
head = new Node;
head->next = NULL;
}
void clear_buffer()
{
char ch;
while ((ch = getchar()) != '\n' && ch != EOF);
}
void menu()
{
char choose;
while (true) {
cout << "\t\t\t\t╔═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ <小型公司工资管理系统设计> ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ 1. 添加职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 2. 查询职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 3. 显示职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 4. 编辑职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 5. 删除职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 6. 统计职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 7. 保存职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 8. 读取职工信息 ‖" << endl;
cout << "\t\t\t\t‖ 0. 结束进程 ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t╚═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╝" << endl;
cout << "\t\t\t\t请输入数字执行对应的功能:";
choose = getchar();
clear_buffer();
switch (choose)
{
case '1': {//添加职员信息
system("CLS");
add_employee();
break;
}
case '2': {//查询职工信息
system("CLS");
query_employee();
break;
}
case '3': {//显示职工信息
system("CLS");
display_all();
break;
}
case '4': {//编辑员工信息
system("CLS");
modify_employee();
break;
}
case '5': {//删除员工信息
delete_employee();
break;
}
case '6': {//统计员工信息
system("CLS");
static_employee();
break;
}
case '7': {//保存员工信息
save();
cout << "\t\t\t\t保存成功!"<<endl;
break;
}
case '8': {//读取员工信息
cout << "读取成功!"<<endl;
load();
break;
}
case '0': {//退出
cout << "\t\t\t\t**********退出成功!**********" << endl;
exit(0);
break;
}
default:
break;
}
clear_buffer();
system("pause");
system("cls");
}
}
int Ide(int Id){
Linklist temp = head->next;
while (temp != NULL)
{
if(temp->e.getId() == Id)
{
cout << "该编号已存在!请重新输入:" << endl;
cin >> Id;
}
temp = temp->next;
}
return Id;
}
void add_employee()
{
char choose;
Linklist current, newNode = new Node;
newNode->next = NULL;
{//添加职工信息
cout << "\t\t\t\t╔═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ****人员类型**** ‖" << endl;
cout << "\t\t\t\t‖ 1、经理 ‖" << endl;
cout << "\t\t\t\t‖ 2、销售人员 ‖" << endl;
cout << "\t\t\t\t‖ 3、销售经理 ‖" << endl;
cout << "\t\t\t\t‖ 4、技术人员 ‖" << endl;
cout << "\t\t\t\t‖ 0、返回主菜单 ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t╚═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╝" << endl;
cout << "\t\t\t\t请输入数字选择需要添加的人员类型:";
choose = getchar();
clear_buffer();
system("CLS");
switch (choose) {
case '1': {//添加经理
newNode->e.addmanager();
break;
}
case '2': {//添加销售人员
newNode->e.addsalesperson();
break;
}
case '3': {//添加销售经理
newNode->e.addsalesmanager();
break;
}
case '4': {//添加技术人员
newNode->e.addtechnician();
break;
}
case '0':break;
default: {
cout << "无效的选择!\n";
break;
}
}
}
while (true)
{
if (head->next == NULL) {
head->next = newNode;
break;
}
else {
current = head->next;
while (current->next != NULL)
{
current = current->next;
}
current->next = newNode;
break;
}
}
save();
}
void query_employee()
{
int queryid;
string queryname;
bool flag = false;
char input = '0';
Linklist current = head->next;
system("CLS");
cout << "\t\t\t\t╔═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ****公司员工工资信息查询系统**** ‖" << endl;
cout << "\t\t\t\t‖ 请选择您的查询方式 ‖" << endl;
cout << "\t\t\t\t‖ 1、编号查询 ‖" << endl;
cout << "\t\t\t\t‖ 2、姓名查询 ‖" << endl;
cout << "\t\t\t\t‖ 0、返回主菜单 ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t╚═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╝" << endl;
cout << "\t\t\t\t请输入数字选择查询的方式:";
cin >> input;
clear_buffer();
if (input == '1') {//按编号查询
cout << "\t\t\t\t请输入需要查询的员工编号:";
cin >> queryid;
cout << "\t========================================================================================" << endl;
cout << "\t" << "编号" << "\t\t" << "姓名" << "\t\t" << "性别" << "\t\t" << "部门" << "\t\t" << "级别" << "\t\t" << "工资" << endl;
while (current != NULL) {
if (current->e.getId() == queryid) {
current->e.showEmployees();
flag = true;
}
current = current->next;
}
if (flag == false)
{
cout << "\t未能查询到该编号!" << endl;
}
cout << endl;
}
else if (input == '2') {//按姓名查询
cout << "\t\t\t\t请输入需要查询的员工姓名:";
cin >> queryname;
cout << "\t========================================================================================" << endl;
cout << "\t" << "编号" << "\t\t" << "姓名" << "\t\t" << "性别" << "\t\t" << "部门" << "\t\t" << "级别" << "\t\t" << "工资" << endl;
while (current != NULL) {
if (current->e.getname() == queryname) {
current->e.showEmployees();
flag = true;
}
current = current->next;
}
if (flag == false) {
cout << "\t未能查询到该员工!" << endl;
}
cout << endl;
}
else if (input == '0');
else
cout << "\t\t\t\t无效的选择!" << endl;

}
void display_all()
{
Linklist current = head->next;
cout << "\t\t\t\t************员工信息展示************" << endl;
cout << "\t==================================================================================================" << endl;
cout << "\t" << "编号" << "\t\t" << "姓名" << "\t\t" << "性别" << "\t\t" << "部门" << "\t\t" << "级别" << "\t\t" << "工资" << endl;
while (current != NULL)
{
current->e.showEmployees();
current = current->next;
}
cout << "\t===========================================END=====================================================" << endl;
cout << "\t";
}
void modify_employee()
{
int modifyid;
bool flag = false;
char item;
Linklist current = head->next;
cout << "请输入需要修改的员工编号:";
cin >> modifyid;
while (current != NULL)
{
if (current->e.getId() == modifyid) {
current->e.showEmployees();
cout << "请输入需要修改的项目的序号【1-姓名|2-性别|3-部门|4-级别|5-工资】:";
cin >> item;
clear_buffer();
switch (item) {
case '1': current->e.modifyname(); break;
case '2':current->e.modifygender(); break;
case '3':current->e.modifydepartment(); break;
case '4':current->e.modifylevel(); break;
case '5':current->e.modifysalary(); break;
}
flag = true;
}
current = current->next;
}
save();
if (flag == false)
{
cout << "未查找到该编号的员工!" << endl;
}
}
void delete_employee()
{
Linklist current = head->next;
Linklist current_2 = head;
int id;
bool flag = true;
cout << "\t\t\t\t请输入需要删除的员工编号:";
cin >> id;
clear_buffer();
while (current != NULL)
{
if (current->e.getId() == id)
{
current_2->next = current->next;
current = NULL;
cout << endl << "\t\t\t\t删除成功!" << endl << endl;
flag = false;
break;
}
current_2 = current;
current = current->next;
}
if (flag == true)
{
cout << endl << "记录为空!\n" << endl;
}
}
void static_employee()
{
char choose;
int allnum = 0;
int mnum = 0, spnum = 0, smnum = 0, tenum = 0;
int bnum = 0, gnum = 0;
Linklist current = head->next, current_2 = head->next;
system("cls");
cout << "\t\t\t\t╔═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╗" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t‖ ****统计方式**** ‖" << endl;
cout << "\t\t\t\t‖ 1、统计所有员工数量 ‖" << endl;
cout << "\t\t\t\t‖ 2、统计各类员工数量 ‖" << endl;
cout << "\t\t\t\t‖ 3、统计员工性别 ‖" << endl;
cout << "\t\t\t\t‖ 0、返回主菜单 ‖" << endl;
cout << "\t\t\t\t‖ ‖" << endl;
cout << "\t\t\t\t╚═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═ ═╝" << endl;
cout << "\t\t\t\t请输入数字选择统计的方式:";
cin >> choose;
clear_buffer();
if (choose == '1') {
while (current != NULL) {
allnum++;
current = current->next;
}
cout << "\t\t\t\t本公司共有:【" << allnum << "】员工!" << endl;
}
else if (choose == '2') {
while (current != NULL)
{
if (current->e.gettype() == "经理") { mnum++;current = current->next; continue; }
if (current->e.gettype() == "销售人员") { spnum++; current = current->next; continue; }
if (current->e.gettype() == "销售经理") { smnum++; current = current->next; continue; }
if (current->e.gettype() == "技术人员") { tenum++; current = current->next; continue; }
}
cout << "\t\t\t\t本公司共有:【" << mnum << "】经理!" << endl;
cout << "\t\t\t\t本公司共有:【" << spnum << "】销售人员!" << endl;
cout << "\t\t\t\t本公司共有:【" << smnum << "】销售经理!" << endl;
cout << "\t\t\t\t本公司共有:【" << tenum << "】技术人员!" << endl;
}
else if (choose == '3') {
while (current != NULL)
{
if (current->e.getgender() == "男" || current->e.getgender() == "M" || current->e.getgender() == "m") { bnum++; current = current->next; continue; }
if (current->e.getgender() == "女" || current->e.getgender() == "F" || current->e.getgender() == "f") { gnum++; current = current->next; continue; }
}
cout << "\t\t\t\t本公司共有:【" << bnum << "】男员工!" << endl;
cout << "\t\t\t\t本公司共有:【" << gnum << "】女员工!" << endl;
}
else if (choose == '0');
else {
cout << "\t\t\t\t无效的统计选择!" << endl;
cout << "\t\t\t\t";
}
}
void save(){
Linklist current = head->next;
ofstream outfile;
outfile.open("employee.txt", ios::trunc | ios::out);
if (!outfile) { //打开失败
cout << "error opening source file." << endl;
return ;
}
for (int i = 0; i < listlength();i++ ) {
outfile << current->e.getId() << " " << current->e.getname() << " "<< current->e.getgender() << " " << current->e.getdepartment() << " "<< current->e.getlevel() << " " << current->e.getsalary() << endl;
current = current->next;
}
outfile.close();/*循环结束后,关闭输出文件流 outfile*/
}
void load(){
Linklist current = new Node;
current->next = NULL;
Linklist H = current;
Linklist p = H;
bool flag = true;
int Id=NULL;
string Name;
string Gender;
string Department;
string Level;
double salary;
ifstream infile("employee.txt",ios::in );
if (!infile) {
cout << "error opening source file." << endl;
return;
}
while(infile >> Id>>Name >> Gender >> Department >> Level >> salary)
{
flag =false;
current->e.saveid(Id);
current->e.savename(Name);
current->e.savegender(Gender);
current->e.savedepartment(Department);
current->e.savelevel(Level);
current->e.savesalary(salary);
p->next = current;
p = current;
Linklist newNode = new Node;
newNode->next = NULL;
current->next = newNode;
current = newNode;
}
delete current;
p->next = NULL;
if (flag)
{
cout << "文件为空!";
}
infile.close();
head->next = H;
}
//有误存储
//void save()
//{
// ofstream f("employee.dat", ios::trunc | ios::out | ios::binary);
// Linklist current = head->next;
// if (!f)
// {
// cerr << "open error!" << endl;
// abort();
// }
// while (current != NULL)
// {
// f.write(reinterpret_cast<char*>(&current->e), sizeof(current->e));
// current = current->next;
// }
// f.close();
//}
//void load()
//{
// ifstream f("employee.dat", ios::in | ios::binary);
// if (!f)
// {
// cerr << "open error!" << endl;
// abort();
// }
// Linklist current = new Node;
// current->next = NULL;
// Linklist H = current;
// Linklist p = H;
// bool flag = true;
// while (f.read(reinterpret_cast<char*>(&current->e), sizeof(current->e))) {
// flag = false;
// p->next = current;
// p = current;
// Linklist newNode = new Node;
// newNode->next = NULL;
// current->next = newNode;
// current = newNode;
// }
// delete current;
// p->next = NULL;
// if (flag)
// {
// cout << "文件为空!";
// exit(0);
// }
// f.close();
// head->next = H;
//}

  • Title: C++小型公司工资管理系统
  • Author: 敬请T期待
  • Created at : 2024-01-17 23:13:11
  • Updated at : 2024-01-21 13:58:37
  • Link: https://kingwempity.github.io/2024/01/17/小型公司工资管理系统cpp/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
C++小型公司工资管理系统