Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For the problems 1 and 2 work with the following structure struct Worker { int i

ID: 3694369 • Letter: F

Question

For the problems 1 and 2 work with the following structure

                     struct Worker

                     {

                            int        idNumber;

                            int        hoursWorked;

                            double hourlyRate;

                            double earned;

                      };                      

1                      worker.cpp      Worker structure

                                                Write 3 functions

1.     one to input the data – the idNumber,

the hoursWorked and the hourlyRate

do NOT input earned, it will be

calculated

2.      one to figure the earned – calculate

time and a half for all hours above 40

(i.e., 10.0 per hour, 52 hours –

earned would be 40 * 10.0 + 12 * 15.0)

3.      one to output the data – print all 4 fields

                                                Write a driver program to test the 3 functions

                                                 Test Plan – run once, select your own data

2.                     workerlist.cpp            

                                                 -array of Worker structures

                                                Write 4 functions

1.      one to input an array of Worker structures

2.     one to figure the earned for each Worker

structure in the array

3.      one to output the array of Worker structures

4.      one to count the number of workers who have worked overtime. Return the answer through the function call

                                                NOTE: For your array functions, use the structure

                                                              functions that your wrote in Problem 1.

                                                Write a driver program to test the 4 functions

                                                 Test Plan – run once, select your own data

Explanation / Answer

Answer for Worker.cpp
This below C++ program written as per given conditions in problem statement

#include<iostream>
using namespace std;

struct Worker
{
   int idNumber;
   int hoursWorked;
   double hourlyRate;
   double earned;

   void inputs(int id, int hours, double rate)
   {
       idNumber = id;
       hoursWorked = hours;
       hourlyRate = rate;
   }

   void earned1()
   {
       if(hoursWorked <= 40)
        {
            earned = hoursWorked * hourlyRate;
        }
       else
       {
           int hours_above_40 = hoursWorked - 40 ;
           earned = 40 * hourlyRate + hours_above_40 * 15.0;
       }
   }
   void print()
   {
       cout<<"Emplyee Id :"<<idNumber<<endl;
       cout<<"Emplyee Hours Worked :"<<hoursWorked<<endl;
       cout<<"Emplyee Hours Rate :"<<hourlyRate<<endl;
       cout<<"Emplyee Earned :"<<earned<<endl;
   }

};

int main()
{
   Worker obj;
   obj.inputs(10,52,10);
   obj.earned1();
   obj.print();
   return 1;
}

Answer for Workerlist.cpp
This below C++ program written as per given conditions in problem statement

#include<iostream>
using namespace std;

struct Worker
{
   int idNumber;
   int hoursWorked;
   double hourlyRate;
   double earned;

   void inputs(Worker obj[], int size)
   {
       for(int i = 0; i< size; i++)
       {
           obj[i].idNumber = 10 + i;
           obj[i].hoursWorked = 40 + i;
           obj[i].hourlyRate = 15 + i;
       }
   }

   void earned1(Worker obj[], int size)
   {
       for(int i =0; i<size; i++)
       {
           if(obj[i].hoursWorked <= 40)
           {
               obj[i].earned = obj[i].hoursWorked * obj[i].hourlyRate;
           }
           else
           {
               int hours_above_40 = obj[i].hoursWorked - 40 ;
               obj[i].earned = 40 * obj[i].hourlyRate + obj[i].hours_above_40 * 15.0;
           }
       }
   }
   void print(Worker obj[], int size)
   {
       for(int i =0; i<size; i++)
       {
           cout<<"Emplyee Id :"<<obj[i].idNumber<<endl;
           cout<<"Emplyee Hours Worked :"<<obj[i].hoursWorked<<endl;
           cout<<"Emplyee Hours Rate :"<<obj[i].hourlyRate<<endl;
           cout<<"Emplyee Earned :"<<obj[i].earned<<endl;
       }
   }

};

int main()
{
   Worker obj1[] = new Worker[4];
   obj.inputs(obj1,4);
   obj.earned1(obj1,4);
   obj.print(obj1,4);
   return 1;
}