1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
class TimeCard {
private:
string workerID;
time2 punchInTime;
time2 punchOutTime;
double payrate, totalpay = 0;
bool hasPunched=0;
public:
TimeCard();
TimeCard(string, double);
void punchOut();
void punchIn();
void pay();
};
TimeCard::TimeCard(){}
TimeCard::TimeCard(string workerID, double payrate)
{
this->workerID = workerID;
this->payrate = payrate;
}
void TimeCard::punchIn()
{
int sec, min, hour;
for (;;)
{
cout << "Punched in at (H M S): ";
cin >> hour >> min >> sec; //takes punched out time
if (hour >= 8 && hour < 17 && min >= 0 && min <= 59 && sec >= 0 && sec <= 59) break;
//validates input
if (hour == 17 && min == 0 && sec == 0) break;
//validates special case of input
else cout << endl << "Improper input. Try again." << endl;
}
punchInTime.calcTime(hour, min, sec);
}
void TimeCard::punchOut()
{
int sec, min, hour;
for (;;)
{
cout << "Punched out at (H M S): ";
cin >> hour >> min >> sec; //takes punched out time
if (hour >= 8 && hour <= 17 && min >= 0 && min <= 59 && sec >= 0 && sec <= 59) break;
//validates input
if (hour == 17 && min == 0 && sec == 0) break;
//validates special case of input
else cout << endl << "Improper input. Try again." << endl;
}
punchOutTime.calcTime(hour, min, sec);
hasPunched = 1;
}
void TimeCard::pay() {
totalpay = ((punchOutTime.returntime() - punchInTime.returntime()) / 3600) * payrate;
if (punchOutTime.returntime() < punchInTime.returntime()) cout << "You cannot punch out before punching in." << endl;
else cout << "Your total pay for the day is $" << totalpay;
}
///////////////////////////////////////////////////////////////////////////////
class time2 {
private:
int hour, minute, second, seconds;
public:
time2();
void calcTime(int,int,int);
int returnTime();
};
time2::time2() {//constructs class type
hour = 0;
minute = 0;
second = 0;
}
void time2::calcTime(int hour, int minute, int second) {//calculates seconds of day
int seconds = 0;
this->hour = hour;
this->minute = minute;
this->second = second;
//validation to make sure they're within the correct range
seconds += 3600 * hour;
seconds += 60 * minute;
seconds += second;
}
int time2::returnTime() {//returns time of day in seconds
return seconds;
}
|