Advertisement
Guest User

Untitled

a guest
Nov 17th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. // workerlist.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <array>
  7. #include <cstdlib>
  8.  
  9. struct Worker
  10. {
  11.     int idNumber;
  12.     int hoursWorked;
  13.     double hourlyRate;
  14.     double earned;
  15.  
  16.     Worker();
  17.     Worker(int id, int hours, double rate);
  18.     int countOfOT();
  19.     void getInfo();
  20.     void calcEarned(int hours, double payrate, double &earned);
  21.     void printInfo();
  22. };
  23.  
  24. void fillArray();
  25. const int LIST = 10;
  26. Worker employeeList[LIST];
  27. //// array of 10 'Worker' objects hardcoded
  28. //Worker employeeList[LIST] =
  29. //{
  30. //  Worker(94, 40, 15),
  31. //  Worker(68, 30, 17),
  32. //  Worker(83, 38, 14),
  33. //  Worker(35, 50, 17),
  34. //  Worker(81, 20, 12),
  35. //  Worker(45, 50, 16),
  36. //  Worker(38, 15, 12),
  37. //  Worker(74, 35, 14),
  38. //  Worker(59, 55, 19),
  39. //  Worker(32, 60, 21)
  40. //};
  41.  
  42. int main()
  43. {
  44.     fillArray();
  45.     for (int x = 0; x < LIST; x++)
  46.     {
  47.     employeeList[x].printInfo();
  48.     }
  49.     return 0;
  50. }
  51.  
  52. void fillArray()
  53. {
  54.     for (int x = 0; x < LIST; x++)
  55.     {
  56.         int id, hours;
  57.         double rate;
  58.         id = rand() % 100 + 1;
  59.         hours = rand() % 30 + 20;
  60.         rate = rand() % 25 + 10;
  61.         Worker(id, hours, rate);
  62.     }
  63. }
  64.  
  65. Worker::Worker() // a default constructor
  66. {
  67.     idNumber = 0;
  68.     hoursWorked = 0;
  69.     hourlyRate = 0;
  70.     earned = 0;
  71. }
  72.  
  73. Worker::Worker(int id, int hours, double rate)
  74. {
  75.     idNumber = id;
  76.     hoursWorked = hours;
  77.     hourlyRate = rate;
  78.     earned = 0;
  79. }
  80.  
  81. void Worker::calcEarned(int hours, double payrate, double &earned)
  82. {
  83.     int hoursOT;
  84.     hoursOT = hours - 40;
  85.     earned = hours * payrate;
  86.     if (hoursOT > 0)
  87.     {
  88.         earned += hoursOT * (payrate * .5);
  89.     }
  90. }
  91.  
  92. void Worker::printInfo()
  93. {
  94.     std::cout << std::endl;
  95.     std::cout << "ID number: " << idNumber << std::endl;
  96.     std::cout << "Total hours worked: " << hoursWorked << std::endl;
  97.     std::cout << "Hourly payrate: $" << hourlyRate << " an hour" << std::endl;
  98.     std::cout << "Total pay earned: $" << earned << std::endl;
  99. }
  100.  
  101. int Worker::countOfOT()
  102. {
  103.     int count = 0;
  104.     for (int x = 0; x < LIST; x++)
  105.     {
  106.         if (employeeList[x].hoursWorked > 40)
  107.         {
  108.             count++;
  109.         }
  110.     }
  111.     return count;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement