Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // workerlist.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <array>
- #include <cstdlib>
- struct Worker
- {
- int idNumber;
- int hoursWorked;
- double hourlyRate;
- double earned;
- Worker();
- Worker(int id, int hours, double rate);
- int countOfOT();
- void getInfo();
- void calcEarned(int hours, double payrate, double &earned);
- void printInfo();
- };
- void fillArray();
- const int LIST = 10;
- Worker employeeList[LIST];
- //// array of 10 'Worker' objects hardcoded
- //Worker employeeList[LIST] =
- //{
- // Worker(94, 40, 15),
- // Worker(68, 30, 17),
- // Worker(83, 38, 14),
- // Worker(35, 50, 17),
- // Worker(81, 20, 12),
- // Worker(45, 50, 16),
- // Worker(38, 15, 12),
- // Worker(74, 35, 14),
- // Worker(59, 55, 19),
- // Worker(32, 60, 21)
- //};
- int main()
- {
- fillArray();
- for (int x = 0; x < LIST; x++)
- {
- employeeList[x].printInfo();
- }
- return 0;
- }
- void fillArray()
- {
- for (int x = 0; x < LIST; x++)
- {
- int id, hours;
- double rate;
- id = rand() % 100 + 1;
- hours = rand() % 30 + 20;
- rate = rand() % 25 + 10;
- Worker(id, hours, rate);
- }
- }
- Worker::Worker() // a default constructor
- {
- idNumber = 0;
- hoursWorked = 0;
- hourlyRate = 0;
- earned = 0;
- }
- Worker::Worker(int id, int hours, double rate)
- {
- idNumber = id;
- hoursWorked = hours;
- hourlyRate = rate;
- earned = 0;
- }
- void Worker::calcEarned(int hours, double payrate, double &earned)
- {
- int hoursOT;
- hoursOT = hours - 40;
- earned = hours * payrate;
- if (hoursOT > 0)
- {
- earned += hoursOT * (payrate * .5);
- }
- }
- void Worker::printInfo()
- {
- std::cout << std::endl;
- std::cout << "ID number: " << idNumber << std::endl;
- std::cout << "Total hours worked: " << hoursWorked << std::endl;
- std::cout << "Hourly payrate: $" << hourlyRate << " an hour" << std::endl;
- std::cout << "Total pay earned: $" << earned << std::endl;
- }
- int Worker::countOfOT()
- {
- int count = 0;
- for (int x = 0; x < LIST; x++)
- {
- if (employeeList[x].hoursWorked > 40)
- {
- count++;
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement