-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkerClass.cpp
120 lines (92 loc) · 2.86 KB
/
WorkerClass.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
//
// Created by 贾智超 on 2024/7/22.
//
#include"WorkerClass.h"
#include<iostream>
// 静态成员函数实现
std::unique_ptr<Person> Person::deserialize(std::istream& is) {
int kind;
is >> kind;
switch (kind) {
case Person::Worker:
return Worker::fromStream(is);
case Person::Manager:
return Manager::fromStream(is);
case Person::Boss:
return Boss::fromStream(is);
default:
throw std::runtime_error("Unknown worker kind.");
}
}
void Worker::ShowNumber() {
std::cout<<"The Worker's number is "<<Number()<<std::endl;
}
void Worker::ShowName() {
std::cout<<"The Worker's Name is "<<Name()<<std::endl;
}
void Worker::ShowSpace() {
std::cout<<"The Person's position is Worker!"<<std::endl;
}
void Worker::ShowDuty() {
std::cout<<"The Worker's duty is complete the tasks "
"assigned by the manager!"<<std::endl;
}
void Worker::read(std::istream& is) {
int kind;
int n;
std::string Name;
is >> kind >> n >> Name;
if (kind != static_cast<int>(Person::Worker)) {
throw std::runtime_error("Incorrect worker kind.");
}
ChangeNumber(n);
ChangeName(Name);
}
void Manager::ShowNumber() {
std::cout<<"The Manager's number is "<<Number()<<std::endl;
}
void Manager::ShowName() {
std::cout<<"The Manager's Name is "<<Name()<<std::endl;
}
void Manager::ShowSpace() {
std::cout<<"The Person's position is Manager!"<<std::endl;
}
void Manager::ShowDuty() {
std::cout<<"The Manager's duty is complete the tasks assigned by the boss,"
" and disassemble and distribute to the staff"<<std::endl;
}
void Manager::read(std::istream& is) {
int kind;
int n;
std::string Name;
is >> kind >> n >> Name;
if (kind != static_cast<int>(Person::Manager)) {
throw std::runtime_error("Incorrect worker kind.");
}
ChangeNumber(n);
ChangeName(Name);
}
void Boss::ShowNumber() {
std::cout<<"The Boss's number is "<<Number()<<std::endl;
}
void Boss::ShowName() {
std::cout<<"The Boss's Name is "<<Name()<<std::endl;
}
void Boss::ShowSpace() {
std::cout<<"The Person's position is Boss!"<<std::endl;
}
void Boss::ShowDuty() {
std::cout<<"The Manager's duty is overall management "
"of all business affairs"<<std::endl;
}
void Boss::read(std::istream& is) {
int kind;
int n;
std::string Name;
is >> kind >> n >> Name;
if (kind != static_cast<int>(Person::Boss)) {
throw std::runtime_error("Incorrect worker kind.");
}
ChangeNumber(n);
ChangeName(Name);
}