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

I have wrote a C++ program that converts total seconds into miitary time. I have

ID: 1947491 • Letter: I

Question

I have wrote a C++ program that converts total seconds into miitary time. I have the first class working, but I cannot get it the second class to call the default constructor CheapWatch(). I have not included the header file because it has the information declared and all the prototypes. Why is the overload constructor not working? Thank you.

#include <iostream>
#include "CheapWatch.h"

using namespace std;

int main()
{

long num = 18637;
CheapWatch milTime( num );

CheapWatch newTime();


}



CheapWatch::CheapWatch()
: hours( 0 ), minutes( 0 ), seconds( 0 )
{
long temp = 0;
cout << " Please input the total number of seconds : ";
cin >> temp;
cout << endl;
CheapWatch temp1( temp );
}

CheapWatch::CheapWatch( long &secs )
: hours( 0 ), minutes( 0 ), seconds( 0 )
{
setTime( secs );
}

CheapWatch::~CheapWatch()
{
printMilTime();
}

void CheapWatch::setTime( long total )
{
setHours( total );
setMinutes( total );
setSeconds( total );
}

void CheapWatch::setHours(long hrs)
{
hours = static_cast<int>(hrs / 3600.);
}

void CheapWatch::setMinutes(long mins)
{
minutes = static_cast<int>((mins - (hours *3600.))/60);
}

void CheapWatch::setSeconds(long secs)
{
seconds = static_cast<int>(((secs - (hours * 3600.))- minutes * 60));
}

unsigned int CheapWatch::getHours() const
{
return hours;
}

unsigned int CheapWatch::getMinutes() const
{
return minutes;
}

unsigned int CheapWatch::getSeconds() const
{
return seconds;
}

void CheapWatch::printMilTime() const
{

cout << setfill('0') << setw( 2 ) << getHours() <<":" << setw( 2 ) << getMinutes() << ":" << setw( 2 ) << getSeconds() << endl;
}

Explanation / Answer

#include #include #define SR 0.0100235 int main() { float time, time_2; float salary, hours; printf("Please enter your clock-in time in military units (e.g, 08:10:15): "); scanf("%f", &time); fflush(stdin); printf("Now please enter your clock-out time in military units: "); scanf(" %f", &time_2); hours=((time_2-time)/60); printf("Today you worked %2.4f hours. ", &hours); salary=hours*SR; printf("Your income today=$%3.2f ", &salary); return(0); }