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

Write a C++ program that declares a class named Time having integer data members

ID: 3660025 • Letter: W

Question

Write a C++ program that declares a class named Time having integer data members named hours, minutes, and seconds. Include a type conversion constructor that converts a long integer, representing the elapsed seconds from midnight, into an equivalent representation as hours:minutes:seconds. For example, the long integer 30336 should convert to the time 8:25:36. Use military time-for example, 2:30p.m. is represented as 14:30:00. The relationship between time representations is as follows: elapsed seconds= hours x 3600 + minutes x 60 + seconds I know I'm close but will someone give me the right code? #include #include using namespace std; class Inttime; class Time { private: int hours; int minutes; int seconds; public: Time(int = 0, int = 00, int = 00); //constructor with defaults void showTime(); //member function to display Time }; class Inttime { private: long time; public: Inttime(long = 0); operator Time(); void setInt(); }; Time::Time(int hh, int mm, int ss) { hours = hh; minutes = mm; seconds = ss; } void Time::showTime() { cout << "The time is " << hours << ":" << minutes << ":" << seconds << endl; } Inttime::operator Time() { int hh,mm,ss; float sum; hh = int(time/3600); mm = int((time600)*60); sum = (time600)*60 - mm; ss = int(sum*60); return(Time(hh,mm,ss)); } int main () { Time a; Inttime b(30336); a = Inttime(b); a.showTime(); system ("pause"); return 0; }

Explanation / Answer

//long at this program for idea, it was for a similar assingment a while back #include using namespace std; void normalize(long int& hr, long int& min, long int& sec); class Time{ long int hour,minute, second; void minimize();//private fxn public: Time(long int); Time(long int,long int,long int); friend ostream& operator=60){ second-=60; minute++; } while(minute>=60){ minute-=60; hour++; } hour%=24; } Time::Time(long int t){//takes t as second hour=0; minute=0; second=t; normalize(hour,minute,second); minimize(); } Time::Time(long int hr,long int min,long int sec){ normalize( hr, min, sec); hour=hr; minute=min; second=sec; minimize(); } ostream& operator
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote