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

At this point in time, using visual studio 2010 c++, declare a class named Time

ID: 3638440 • Letter: A

Question

At this point in time, using visual studio 2010 c++, declare a class named Time having integer data members named hours, minutes and seconds. Include a type conversion construct that converts a long integer representing the elapsed seconds from midnight into an equivalent representation as hours, minutes and seconds. An illustration/example of this is a long integer (37623) would convert to the time 6:45:23. However, make use of military time by way of 2:40 is converted to 14:40 etc etc. The relationship between time representations is as follows, Elapsed seconds=hours*3600+minutes*60+seconds

#include <iostream>
using namespace std;

int main()
{

class Time{
//variable declarations
//Functions

};

int main(){
Time t;
// t.functionName(parameters...);
}
class Time
{
int hrs,mins,secs;
public:
Time(){hrs=mins=secs=0;}
void display()
{
cout<<"hrs = "<<hrs<<" mins= "<<mins<<" secs= "<<secs<<endl;
}
Time operator=(Time& obj)
{
if(this != &obj)
{
hrs=obj.hrs;
mins=obj.mins;
secs=obj.secs;
}
}
};

int main()
{
int seconds=35800;
int hours = seconds/3600;

int tempminutes = seconds%3600;

int minutes = tempminutes/60;

seconds = tempminutes%60;
cout<<hours<<" "<<minutes<<" "<<seconds<<endl;
}


Explanation / Answer

please rate - thanks

to get you started


#include <iostream>
using namespace std;
class Time
{
int hrs,mins,secs;
public:
Time(){hrs=mins=secs=0;}
Time(long t)
{hrs=t/3600;
t%=3600;
mins=t/60;
secs%=60;
}
void display()
{
cout<<"hrs = "<<hrs<<" mins= "<<mins<<" secs= "<<secs<<endl;
}
Time operator=(Time& obj)
{
if(this != &obj)
{
hrs=obj.hrs;
mins=obj.mins;
secs=obj.secs;
}
}
};
int main(){
long sec;
   cout<<"Enter time in seconds: ";
cin>>sec;
Time t(sec);
t.display();
system("pause");
return 0;
}