Advertisement
Garey

Test

Oct 17th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int WEEK_WORK_HOURS = 40;
  7. const double SALARY_PER_HOUR = 10.0;
  8.  
  9. struct Worker {
  10.   char name[32];
  11.   int hours_per_week;
  12.   double salary;
  13.   bool stay;
  14. };
  15.  
  16. void calculate_salary(Worker *worker, bool stay = false) {
  17.     if(worker->hours_per_week <= WEEK_WORK_HOURS) {
  18.       if (stay) {
  19.         worker->salary = (SALARY_PER_HOUR * (20 / 100)) * worker->hours_per_week;
  20.         cout << worker->salary;
  21.       } else {
  22.         worker->salary = SALARY_PER_HOUR  * worker->hours_per_week;
  23.         cout << worker->salary;
  24.       }
  25.     } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 3) {
  26.       if (stay) {
  27.         worker->salary = (SALARY_PER_HOUR * (15 / 100)) * worker->hours_per_week;
  28.         cout << worker->salary;
  29.       } else {
  30.         worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (5 / 100))) * worker->hours_per_week;
  31.         cout << worker->salary;
  32.       }
  33.   } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 5) {
  34.     if (stay) {
  35.       worker->salary = (SALARY_PER_HOUR * (12 / 100)) * worker->hours_per_week;
  36.       cout << worker->salary;
  37.     } else {
  38.       worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (8 / 100))) * worker->hours_per_week;
  39.       cout << worker->salary;
  40.     }
  41.   } else if (worker->hours_per_week <= WEEK_WORK_HOURS + 10) {
  42.     if (stay) {
  43.       worker->salary = (SALARY_PER_HOUR * (13 / 100)) * worker->hours_per_week;
  44.       cout << worker->salary;
  45.     } else {
  46.       worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (7 / 100))) * worker->hours_per_week;
  47.       cout << worker->salary;
  48.     }
  49.   } else {
  50.     if (stay) {
  51.       worker->salary = (SALARY_PER_HOUR * (14 / 100)) * worker->hours_per_week;
  52.       cout << worker->salary;
  53.     } else {
  54.       worker->salary = (SALARY_PER_HOUR + (SALARY_PER_HOUR * (6 / 100))) * worker->hours_per_week;
  55.       cout << worker->salary;
  56.     }
  57.   }
  58. }
  59.  
  60. int main() {
  61.  
  62.   Worker *worker[5];
  63.   unsigned int count;
  64.   string answer;
  65.  
  66.   cout << "Enter a number between 3 and 5";
  67.   cin >> count;
  68.  
  69.   for (size_t i = 0; i < count; i++) {
  70.     cout << "Enter worker's name";
  71.     cin >> worker[i]->name;
  72.     cout << "Enter worker's hours per week";
  73.     cin >> worker[i]->hours_per_week;
  74.     cout << "Does the worker stay? (yes/no)";
  75.     cin >> answer;
  76.  
  77.     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")) {
  78.       worker[i]->stay = true;
  79.     } else {
  80.       worker[i]->stay = false;
  81.     }
  82.   }
  83.  
  84.   for (size_t i = 0; i < count; i++) {
  85.     calculate_salary(worker[i]);
  86.   }
  87.  
  88.   return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement