Question
The code has already been written. Please describe what each line and each function does. I have to explain to someone else and I have
The code has already been written. Please describe what each line and each function does. I have to explain to someone else and I have a limited knowledge of C++
I have attached the instruction, the answer which is the code and the output the code gave. i want an explanation on the code on what each line is performing. I need the code to be explained.
#include
using namespace std;
class Converter
{
private:
int days, hours, minutes, seconds;
const int SECONDS_IN_7_DAYS = 604800; //60x60x24x7
public:
Converter()
{
days = 0;
hours = 0;
minutes = 0;
seconds = 0;
}
int getDays()
{
return days;
}
int getMinutes()
{
return minutes;
}
int getSeconds()
{
return seconds;
}
int getHours()
{
return hours;
}
void setSeocnds(int s)
{
if (s > SECONDS_IN_7_DAYS)
cout
else
seconds = s;
}
void convertSeconds(int s)
{
setSeocnds(s);
if (seconds % 86400 == 0)
{
days = seconds / 86400;
cout
}
else if (seconds % 86400 != 0)
{
if (seconds
{
if (seconds % 3600 == 0)
{
hours = seconds / 3600;
cout
}
else
{
hours = seconds / 3600;
seconds = seconds % 3600;
minutes = seconds / 60;
seconds = seconds % 60;
if (hours == 0)
cout
else if (minutes == 0)
cout
else
cout
}
}
if (seconds > 86400)
{
days = seconds/ 86400;
seconds = seconds % 86400;
hours = seconds / 3600;
seconds = seconds % 3600;
minutes = seconds / 60;
seconds = seconds % 60;
if (days == 0)
cout
if (hours == 0)
cout
else if (minutes == 0)
cout
else
cout
}
}
}
};
void main()
{
Converter secConvert;
int sec;
x:
cout
cin >> sec;
if (sec
goto x;
secConvert.convertSeconds(sec);
system("pause");//to hold the output screen
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started