Definition of time class (member function)

Source: Internet
Author: User
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)

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.