Program To Enter Time In Hours , Minutes And Seconds And Display The Time In Universal Format (14:59:59) Using Classes In C++

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click View Source “View Source” on the right of this code snippet.


Background and Explanation of the code


In the above program, class time is declared with three private data members hh, min and sec and three private member functions sethour ( ), setmin ( ), setsec ( ) to set hours, minutes and seconds respectively.When an object t of class time invokes input_time ( ) function, the user is prompted to input hours, minutes and seconds.Then it displays time in proper universal format.

OUTPUT

Enter time : 12

12

34

Time entered is 12:12:34