Time Class (Increase N)

Source: Internet
Author: User

Enter the code:

/**copyright (c) 2015, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: sum123.cpp* Author: Lin Haiyun * Completion date: March 17, 2015 * version number: v2.0** problem Description: Read , after running the program, expand the functionality of the class as required, on the basis of the original class, add the following member functions within the class (will be built-in member functions) ADD_A_SEC ()//Add C seconds add_a_minute ()//Increase B min add_an_hour ()//Add a hour in main () number, call the newly added member function to test the expanded functionality. * Program input: Time. * Program output: The time after the change.    */#include <iostream>using namespace Std;class time{public:void set_time ();    void Showtime ();    void add_a_sec (int n);    void Add_a_minute (int n);    void Add_an_hour (int n);p rivate:bool is_time (int, int, int);    int hour;    int minute; int sec;};    void Time::set_time () {char c1,c2;    cout<< "Please enter the correct time format (HH:MM:SS):";        while (1) {cin>>hour>>c1>>minute>>c2>>sec; if (c1!= ': ' | |        c2!= ': ') cout<< "The input time format is not correct, please re-enter:";        else if (!is_time (hour,minute,sec)) cout<< "The time entered is illegal, please re-enter:";    else break; }}bool time::is_time (int h, int m,int s) {if (h<0| | h>24| | m<0| | m>60| | S<0||    S&GT;60) return false; else return true;} void Time::showtime () {cout<

Operation Result:

Time Class (Increase N)

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.