Write a program with a class called CheapWatch thatprovides the time of day in a
ID: 3619351 • Letter: W
Question
- Write a program with a class called CheapWatch thatprovides the time of day in a program. Three unsigned integersshould be used to represent time:
- The first integer should represent the hour.
- The second integer should represent the minutes.
- The third integer should represent the seconds.
Include in the program a type conversion constructor that convertsa long integer representing the number of seconds from midnightinto your three-integer (hour, minute, second) representation. Forexample, if the long integer 18637 should convert to 5:10:37, youmay use the following formula:
Elapsed seconds = (hours *3600) + (minutes * 60) + seconds.
Use military time. For example, 3:40 PM is represented as15:40:00.
Explanation / Answer
please rate - thanks #include #include using namespace std; class CheapWatch { public: int hour,minute,second; CheapWatch() //constructor {hour=0; minute=0; second=0; } CheapWatch(int h,int m,int s) {hour=h; minute=m; second=s; } CheapWatch(long int s) {hour=s/3600; s%=3600; minute=s/60; second=s%60; } void sethour(int h) {if(h=0) hour=h; else hour=0; } void setminute(int m) {if(m=0) minute=m; else minute=0; } void setsecond(int s) {if(s=0) second=s; else second=0; } int gethour() {return hour; } int getminute() {return minute; } int getsecond() {return second; } voidshow() //print the time with 2 characters and 0 fill to make all digits 2,leading 0 if needed {coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.