2-2 Definition of time class Time Limit: 1000 ms memory limit: 65536 K Description
You can use this exercise to understand the definition of classes and objects;
Design a time class. Private Data members include hour (hour), minute (minute), and second (second );
Public member functions include sethour (INT), which sets the value of the data member hour. The default value of invalid input is 12. setminue (INT) sets the value of the data member minute. The default value of invalid input is 0; setsecond (INT) sets the value of the data member second. The default value of invalid input is 0. settime (INT, Int, INT) sets the value of the hour, minute, and second data member; showtime () shows the value of the time object.
Call the corresponding member function in the main function main () so that the value of the time object can be received from the keyboard and displayed correctly.
Input
Enter three integers separated by a space.
Output
The output time, minute, and second values, separated ":"
Sample Input
10 11 12
Sample output
10:11:12
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <iostream>#include <vector>#include <stack>using namespace std;class Time{private:int h,m,s;public:void setHour() { if(h>12||h<0)h=12; } void setMin() { if(m>60||m<0)m=0; } void setSec() { if(s<0||s>60)s=0; } void setTime() { cin>>h>>m>>s; } void showTime(){if (h<10)cout<<"0";cout<
Definition of time class (member function)