-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
158 lines (149 loc) · 4.78 KB
/
main.cpp
File metadata and controls
158 lines (149 loc) · 4.78 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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Task
{
private:
string name;
public:
int percent_done;
void define_name(int current_task)
{
cout << "Enter current " << current_task << " task name: ";
cin >> this->name;
}
void define_completed_percentage(int current_task)
{
cout << "Enter " << current_task << " task percentage completed: ";
cin >> this->percent_done;
}
};
class Worker
{
private:
string name;
bool master = false;
float basic_salary;
int number_of_tasks;
Task *Tasks = new Task[number_of_tasks];
int number_of_completed_tasks = 0;
int number_of_overcompleted_tasks = 0;
int number_of_undercompleted_tasks = 0;
float payday_salary = 0;
public:
void enter_name()
{
cout << "Enter the worker's full name: " << endl;
cin >> this->name;
}
void enter_qualification()
{
string entered;
cout << "Enter the worker's qualification (master/novice):" << endl;
cout << "Note: master acquires 10% additional basic salary." << endl;
cin >> entered;
if (entered == "master")
{
this->master = true;
}
else if (entered == "novice")
{
this->master = false;
}
else
{
cout << "Error. Try again." << endl;
this->enter_qualification();
}
}
void enter_basic_salary()
{
cout << "Enter the worker's basic salary: " << endl;
cin >> this->basic_salary;
}
void define_static_task_number(int static_task_number)
{
this->number_of_tasks = static_task_number;
}
void cycle_through_tasks()
{
for (int current_task = 0; current_task<number_of_tasks; current_task++)
{
this->Tasks[current_task].define_name(current_task);
this->Tasks[current_task].define_completed_percentage(current_task);
}
}
void confirm_tasks()
{
cout << "Confirming the tasks..." << endl;
for (int i = 0; i<number_of_tasks; i++)
{
if (this->Tasks[i].percent_done == 100)
this->number_of_completed_tasks++;
else if (this->Tasks[i].percent_done > 100)
this->number_of_overcompleted_tasks++;
else if (this->Tasks[i].percent_done < 100)
this->number_of_undercompleted_tasks++;
}
cout << "Done." << endl;
}
void payday()
{
if ((this->number_of_undercompleted_tasks == 0) && (this->number_of_overcompleted_tasks > this->number_of_completed_tasks))
{
this->payday_salary = basic_salary + (basic_salary * 0.1);
cout << "Additional 10% of basic salary acquired due to overcompleted tasks." << endl;
}
else if (this->number_of_undercompleted_tasks > 0)
{
this->payday_salary = basic_salary - (basic_salary * 0.1);
cout << "Additional 10% fee acquired due to undercompleted tasks." << endl;
}
else
{
this->payday_salary = basic_salary;
}
}
void qualification_payday_drift()
{
if (this->master == true)
{
payday_salary = payday_salary + (basic_salary * 0.1);
cout << "Additional 10% of basic salary acquired due to mastership." << endl << endl;
cout << "Payday salary is: " << payday_salary << endl;
}
else
{
cout << "Payday salary is: " << payday_salary << endl;
}
}
};
int main()
{
cout << "Enter the exact number of workers: " << endl;
int number_of_workers;
cin >> number_of_workers;
cout << "Enter the exact number of tasks: " << endl;
int number_of_tasks;
cin >> number_of_tasks;
Worker Workers[number_of_workers];
fstream file("i_want_to.die", ios::out | ios::binary);
file.write((char*)&Workers, sizeof(Workers));
file.close();
fstream input_file("i_want_to.die", ios::in | ios::binary);
Worker Workers_opened[number_of_workers];
input_file.read((char*)&Workers_opened, sizeof(Workers_opened));
for (int i = 0; i < number_of_workers; i++)
{
Workers_opened[i].enter_name();
Workers_opened[i].enter_qualification();
Workers_opened[i].enter_basic_salary();
Workers_opened[i].define_static_task_number(number_of_tasks);
Workers_opened[i].cycle_through_tasks();
Workers_opened[i].confirm_tasks();
Workers_opened[i].payday();
Workers_opened[i].qualification_payday_drift();
}
return 0;
}