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

Use Composition to implement the following: Use Multiple Source file, Class Defi

ID: 3719491 • Letter: U

Question

Use Composition to implement the following:

Use Multiple Source file, Class Definition in header file, class implementation in .cpp file and application in separate .cpp file.
Not using these criterias will receive 0 for the points.             

Design a TimeCard class that allows a company to pay a worker for a day’s labor.
The worker uses the time card to punch in at the beginning of the day and punch out upon quitting.
The company immediately pays the worker based on the hourly rate and the length of time on the job.
Use composition and incorporate the Time2 class to keep track of the
punchInTime (start time) and punchOutTime (end time) in the TimeCard class.

Use the following fields as private data for the Time2:
private int hour;
private int minute;
private int second;
Create all the appropriate method and constructors, with validation criteria.

Use the following fields as private data for the TimeCard:

Use the following fields as private data for the TimeCard:

private string workerID;                                   // SS Number
private Time2 punchInTime, punchOutTime; // Time2 objects
private double payrate;                                     // hourly pay
private bool hasPunched;                                 // set to true after worker punches out

Write a test program that will create a punchInTime object and a punchOutTime object.
The class TimeCard should have member function(s) to calculate the duration (hours worked)
and calculate and print the day’s earnings.

Assume no worker punches in before 8:00 AM and no worker punches out after 5:00 PM (17.00).

Sample Input/Output:

Worker ID: 123456789
Start Time: 8:00:00 AM
End Time: 3:30:00 PM
Pay Rate: $12.50
Hours worked: 7.50
Per hour, the day's earnings are: $93.75

Worker ID: 997654321
Start Time: 8:00:00 AM
End Time: 4:30:00 PM
Pay Rate: $12.50
Hours worked: 8.50
Per hour, the day's earnings are: $106.25

Table format would be more usable.

Worker ID                       Start Time    End Time Pay Rate Hours Worked Day's Earning
123456789           8:00:00 AM 3:30:00 PM    $12.50    7.50    $ 93.75
997654321                 8:00:00 AM 4:30:00 PM    $12.50 8.50 $106.25

please do include every header file and guide to make this assignment

Explanation / Answer

here is your program : ------------>>>>>>>>>

#ifndef TIME_2_
#define TIME_2_

class Time2{
private:
  int hour;
  int minute;
  int second;
public:
  Time2();
  Time2(int,int,int);
  Time2(Time2 &);
  Time2& operator=(Time2 &);
  void setHour(int);
  void setMinute(int);
  void setSecond(int);
  int getHour()const;
  int getMinute()const;
  int getSecond()const;
  double getTime()const;
};

#endif

Time2.cpp : -------->>>>>

#include "Time2.h"

Time2::Time2(){
hour = 0;
minute = 0;
second = 0;
}

Time2::Time2(int h,int m,int s){
setHour(h);
setMinute(m);
setSecond(s);
}
Time2::Time2(Time2 &t){
*this = t;
}
Time2& Time2::operator=(Time2 &oth){
if(this == &oth){
  return *this;
}

hour = oth.hour;
second = oth.second;
minute = oth.minute;

return *this;
}

void Time2::setHour(int h){
if(h < 24 && h > 0){
  hour = h;
}
}
void Time2::setMinute(int m){
if(m < 60 && m > 0){
  minute = m;
}
}

void Time2::setSecond(int s){
if(s < 60 && s > 0){
  second = s;
}
}
int Time2::getHour()const{
return hour;
}
int Time2::getMinute()const{
return minute;
}
int Time2::getSecond()const{
return second;
}
double Time2::getTime()const{
double n = second + minute*60 + hour*3600;
return n;
}

TimeCard.h : -------->>>>>>>

#ifndef TIME_CARD_
#define TIME_CARD_
#include "Time2.cpp"
#include<iostream>

using namespace std;

class TimeCard{
private:
  string workerId;
  Time2 punchInTime,punchOutTime;
  double payRate;
  bool hasPunched;
public:
  TimeCard();
  TimeCard(string,Time2,Time2,double);
  double durationWorked();
  double dayEarning();
  void punchIn(Time2);
  void punchOut(Time2);
};

#endif

TimeCard.cpp : --------->>>>>>>>>

#include "TimeCard.h"

TimeCard::TimeCard(){
workerId = "";
payRate = 0;
hasPunched = false;
}

TimeCard::TimeCard(string id,Time2 in,Time2 out,double rate){
workerId = id;
punchIn(in);
punchOut(out);
payRate = rate;
hasPunched = false;
}

void TimeCard::punchIn(Time2 in){
if(in.getHour() >= 8 )
punchInTime = in;
}
void TimeCard::punchOut(Time2 out){
if(out.getHour() <= 17){
  punchOutTime = out;
  hasPunched = true;
}
}

double TimeCard::durationWorked(){
if(hasPunched){
  double s = punchOutTime.getTime() - punchInTime.getTime();
  return s/3600;
}
}

double TimeCard::dayEarning(){
return durationWorked() * payRate;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote