-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass.cpp
More file actions
180 lines (172 loc) · 4.4 KB
/
Class.cpp
File metadata and controls
180 lines (172 loc) · 4.4 KB
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
#include <iostream>
#include <string>
using namespace std;
//Àáñòðàêòíèé êëàñ
class Person
{
public:
virtual~Person(){};
virtual void Show()=0;
};
class Profession
{
string profession_name; // íàçâà ïðîôåñ³¿
double basic_salary; // áàçîâà ñòàâêà çàðïëàòí³
public:
Profession() // Êîíñòðóêòîð çà çàìîâ÷óâàííÿì
{
profession_name = "None";
basic_salary = 0;
}
Profession(string prof, double salary) // Êîíñòðóêòîð
{
profession_name = prof;
basic_salary = salary;
}
double get_salary()
{
return basic_salary;
}
string get_name ()
{
return profession_name;
}
};
class Equipment
{
string equipment_name; // íàçâà îáëàäíàííÿ
double equipment_cost; // âàðò³ñòü îáëàäíàííÿ
public:
Equipment()
{
equipment_name = "None";
equipment_cost = 0;
}
Equipment(string equipm, double cost)
{
equipment_name = equipm;
equipment_cost = cost;
}
string get_name()
{
return equipment_name;
}
double get_cost()
{
return equipment_cost;
}
void set_cost()
{
double cost;
cout << "Set equipment cost: ";
cin >> cost;
equipment_cost = cost;
}
};
class Product
{
string product_name; // íàçâà âèðîáó
double product_cost; // âàðò³ñòü âèðîáó
unsigned product_quantity;
public:
Product ()
{
product_name = "None";
product_cost = 0.0;
}
Product (string prname, unsigned prquantity, double prcost)
{
product_name = prname;
product_quantity = prquantity;
product_cost = prcost;
}
string get_name()
{
return product_name;
}
double get_cost()
{
return product_cost;
}
unsigned get_quantity()
{
return product_quantity;
}
void set_quantity()
{
double quantity;
cout <<"Set product quantity: ";
cin>>quantity;
product_quantity = quantity;
}
void set_cost()
{
double cost;
cout <<"Set product cost: ";
cin>>cost;
product_cost = cost;
}
};
/*class Head // Êëàñ êåð³âíèê
{
};*/
class Worker : public Person// êëàñ Ðîá³òíèê, íàùàäîê àáñòðàêòíîãî êëàñó Person
{
public:
Worker(string name, unsigned age, Profession prof, Equipment eq, Product pr, unsigned exp)
{
worker_name = name;
worker_age = age;
profes = prof;
equipm = eq;
prod = pr;
experience = exp;
}
string get_name()
{
return worker_name;
}
void set_age()
{
double age;
cout <<"Set worker age: ";
cin>>age;
worker_age = age;
}
double salary()
{
double surcharge;
if (experience < 1)
surcharge = 0.0;
else if (experience <=5)
surcharge = 0.15;
else surcharge = 0.25;
return (profes.get_salary()*(1.+surcharge)+prod.get_quantity()*prod.get_cost()*0.01);
}
void Show ()
{
cout << "Worker name is " << worker_name << endl;
cout << "Worker age is " << worker_age << endl;
cout << "Worker profession is " << profes.get_name() << endl;
}
protected:
string worker_name; //³ì’ÿ
unsigned worker_age; //â³ê
Profession profes;
Equipment equipm;
Product prod;
unsigned experience;
};
int main()
{
Profession pr1 = Profession("profession_1",5500.0); // ïðèêëàäè
Profession pr2 = Profession("profession_2",7200.0);
Profession pr3 = Profession("profession_3",9000.0);
Equipment eq1 = Equipment ("equipment_1",10000.0);
Equipment eq2 = Equipment ("equipment_2",25000.0);
Product prod1 = Product ("product_1",10,100);
Worker wrk1 = Worker ("Ivan Petrov",39,pr2,eq2,prod1,10);
wrk1.Show();
cout << "Worker salary is " << wrk1.salary();
return 0;
}