Write a program with a class called CheapWatch that provides the time of day in
ID: 3538499 • Letter: W
Question
Write a program with a class called CheapWatch that provides the time of day in a program. Three unsigned integers should 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 converts a long integer representing the number of seconds from midnight into your three-integer (hour, minute, second) representation. For example, if the long integer 18637 should convert to 5:10:37, you may use the following formula:
Elapsed seconds = (hours * 3600) + (minutes * 60) + seconds.
Use military time. For example, 3:40 PM is represented as 15:40:00.
(Hint: Design the CheapWatch class where the 3 integers representing time are to be treated as private data members. Include a standard constructor, a type conversion constructor, and a function that shows the time as public function members. In your design, identify with a comment the constructor member function. Ask the user to enter the number of seconds after midnight; output the seconds converted to military time. Make sure the output is formatted properly with appropriate manipulators, formatting flags and formatting functions.)
Please show all work, and enter complete program's. Thanks!
Explanation / Answer
#include #include using namespace std; class cheap_watch { unsigned int Hr, Min, Sec; public: cheap_watch(); cheap_watch(long); void set_values ( long ); void Show (); }; cheap_watch::cheap_watch() { Hr=0,Min=0,Sec=0; } cheap_watch::cheap_watch( long Secs) { Hr = Secs / 3600; Secs-=Hr*3600; Min = Secs / 60; Secs-=Min*60; Sec = Secs; } void cheap_watch:: set_values ( long Secs ) { Hr = Secs / 3600; Secs-=Hr*3600; Min = Secs / 60; Secs-=Min*60; Sec = Secs; } void cheap_watch::Show () { // Output formatted military time coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.