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

1b. Write the implementation file timeClock.cpp for the class TimeClock. Compile

ID: 3822362 • Letter: 1

Question

1b. Write the implementation file timeClock.cpp for the class TimeClock. Compile the file, and save it in the Chap13 folder of your Student Data Files.

1c. Write a C++ program named weeklyPay.cpp to test your class TimeClock. Your program should ask the user how many hours the user worked each day of the week. An object should be created for each day of the week with the number of hours for each day worked and an object for the weekly total.

Save your program as weeklyPay.cpp and execute it.

The following is a copy of the screen results that might appear after running your program, depending on the data entered. The input entered by the user is shown in bold.

This program asks the user for the number of hours worked each day of the week, totals the hours, and shows the days and hours worked.

How many hours did you work Monday? 4

How many hours did you work Tuesday? 9

How many hours did you work Wednesday? 3

How many hours did you work Thursday? 12

How many hours did you work Friday? 3

How many hours did you work Saturday? 7

   How many hours did you work Sunday? 0

This week you worked in days:     in Hours

Monday:

0.5

4

Tuesday:

1.125

9

Wednesday:

0.375

3

Thursday:

1.5

12

Friday:

0.375

3

Saturday:

0.875

7

Sunday:

0

0

Total for the week:

4.75

38

// Header File Code:

#ifndef TIMECLOCK_H

#define TIMECLOCK_H

class Timeclock

{

     private:

          float days;

          float hours;

         

     public:

          Timeclock(float d=0, float h=0);

          float getDays();

          void setDays(float h);

          float getHours();

          void setHours(float h);

          Timeclock operator+(float h);

          Timeclock operator-(float h);

          void display();

};

#endif

_________________________

TimeClock

Days: float

Hours: float

+TimeClok()                                                                 // Default Constructor

+TimeClock(float, float)                                            // Overloaded Constructor

+getDays():    float                                                      // Return value of days

+getHours():    float                                                    // Return value of hours

+setDays(float):    void                                              // set a value for days

+setHours(float):    void                                            // set a value for hours

+operator+(TimeClock):     TimeClock                    // add hours to data member hours

+operator-(TimeClock):     TimeClock                     // subtract hours from data member hours

   How many hours did you work Sunday? 0

This week you worked in days:     in Hours

Monday:

0.5

4

Tuesday:

1.125

9

Wednesday:

0.375

3

Thursday:

1.5

12

Friday:

0.375

3

Saturday:

0.875

7

Sunday:

0

0

Total for the week:

4.75

38

Explanation / Answer

// timeClock.h

#ifndef TIMECLOCK_H
#define TIMECLOCK_H

class Timeclock
{
private:
float days;
float hours;

public:
Timeclock(float d=0, float h=0);
float getDays();
void setDays(float d);
float getHours();
void setHours(float h);
Timeclock operator+(float h);
Timeclock operator-(float h);
void display();
};
#endif

// timeClock.cpp

#include "timeClock.h"

Timeclock::Timeclock(float d, float h){
days = d;
hours = h;
}
float Timeclock::getDays(){
return days;
}
void Timeclock::setDays(float d){
days = d;
}
float Timeclock::getHours(){
return hours;
}
void Timeclock::setHours(float h){
hours = h;
}
Timeclock Timeclock::operator+(float h){
Timeclock temp;
temp.days = this->days;
temp.hours = this->hours + h;
}
Timeclock Timeclock::operator-(float h){
Timeclock temp;
temp.days = this->days;
temp.hours = this->hours - h;
}
void display(){
}

// weeklyPay.cpp

#include <iostream>
#include <iomanip>
#include "timeClock.cpp"
using namespace std;

int main(){
string days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
float normal = 8;
Timeclock *temp[7];
float hoursTemp, daysTemp;
float hoursTotal = 0, daysTotal = 0;
for(int i = 0; i < 7; i++){
cout << "How many hours did you work " << days[i] << "? ";
cin >> hoursTemp;
daysTemp = hoursTemp / normal;
temp[i] = new Timeclock();
temp[i]->setDays(daysTemp);
temp[i]->setHours(hoursTemp);
hoursTotal += hoursTemp;
daysTotal += daysTemp;
}

cout << "This week you worked in days: in Hours ";
for(int i = 0; i < 7; i++){
cout << setw(10) << days[i] << ":" << setw(25) << temp[i]->getDays() << setw(10) << temp[i]->getHours() << " ";
}
cout << setw(10) << "Total :" << setw(25) << daysTotal << setw(10) << hoursTotal << " ";
}

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