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;
}