Sdut 2-2 Time class definition

Source: Internet
Author: User

Sdut 2-2 Time class definition

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
Prompt

Input

58 23 85

Output

12:23:00

Sample program from Huang Jingjing

This question has a small problem. When the minute and second are equal to 0, 00 is output, and "% 02d" can be used in c (# include is required ). ), And use cout in ++. with (0); cout. fill ("0"); yes, but the latter is troublesome (no separate header files are required). In this case, the latter is not implemented. Please advise !!

# Include
 
  
# Include
  
   
Using namespace std; // declare class type class time {// define private part private: int h; int m; int s; // define public part public: int sethour () // member function {if (h> 12 | h <0) h = 12; return h;} int setminue () // control the member function {if (m> 60 | m <0) m = 0; return m;} int setsecond () // controls the second member function {if (s> 60 | s <0) s = 0; return s;} void settime () // value assignment member function {cin> h> m> s;} void showtime () // output member function {printf ("% 02d: % 02d: % 02d \ n ", h, m, s); // # include
   
    
}; // Do not forget this semicolon // main function int main () {class time t; t. settime (); t. sethour (); t. setminue (); t. setsecond (); t. showtime (); return 0 ;}
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.