Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int WEEK_WORK_HOURS = 40;
- const double SALARY_PER_HOUR = 10.0;
- struct Worker {
- char name[32];
- int hours_per_week;
- double salary;
- bool stay;
- };
- void calculate_salary(Worker *worker, bool stay = false) {
- if(worker->hours_per_week <= WEEK_WORK_HOURS) {
- if (stay) {
- worker->salary = (SALARY_PER_HOUR * (20 / 100)) * worker->hours_per_week;
- cout << worker->salary;
- } else {
- worker->salary = SALARY_PER_HOUR * worker->hours_per_week;
- cout << worker->salary;
- }
- } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 3) {
- if (stay) {
- worker->salary = (SALARY_PER_HOUR * (15 / 100)) * worker->hours_per_week;
- cout << worker->salary;
- } else {
- worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (5 / 100))) * worker->hours_per_week;
- cout << worker->salary;
- }
- } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 5) {
- if (stay) {
- worker->salary = (SALARY_PER_HOUR * (12 / 100)) * worker->hours_per_week;
- cout << worker->salary;
- } else {
- worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (8 / 100))) * worker->hours_per_week;
- cout << worker->salary;
- }
- } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 10) {
- if (stay) {
- worker->salary = (SALARY_PER_HOUR * (13 / 100)) * worker->hours_per_week;
- cout << worker->salary;
- } else {
- worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (7 / 100))) * worker->hours_per_week;
- cout << worker->salary;
- }
- } else {
- if (stay) {
- worker->salary = (SALARY_PER_HOUR * (14 / 100)) * worker->hours_per_week;
- cout << worker->salary;
- } else {
- worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (6 / 100))) * worker->hours_per_week;
- cout << worker->salary;
- }
- }
- }
- int main() {
- Worker *worker[5];
- unsigned int count;
- string answer;
- cout << "Enter a number between 3 and 5";
- cin >> count;
- for (size_t i = 0; i < count; i++) {
- cout << "Enter worker's name";
- cin >> worker[i]->name;
- cout << "Enter worker's hours per week";
- cin >> worker[i]->hours_per_week;
- cout << "Does the worker stay? (yes/no)";
- cin >> answer;
- if (strcmp(answer.c_str(), "yes") || strcmp(answer.c_str(), "Yes") || strcmp(answer.c_str(), "YES") || strcmp(answer.c_str(), "y") || strcmp(answer.c_str(), "Y")) {
- worker[i]->stay = true;
- } else {
- worker[i]->stay = false;
- }
- }
- for (size_t i = 0; i < count; i++) {
- calculate_salary(worker[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement