Week five Project 4-static member application

Source: Internet
Author: User

Design a time class that contains static data members and member functions. A static data member is a common data for all objects in a class, in the following design, whether the clock is to be 12-hour or 24-hour, or if the number that is less than two digits is preceded by 0, is a "global" setting that is appropriate as a static data member in the class.

/** Copyright (c) 2015, Yantai University School of Computer * All right reserved.* Shao * file: demo.cpp* finish: April 08, 2015 * version number: v1.0*/#include <iostream    > #include <cmath>using namespace Std;class time{public:time (int=0,int=0,int=0); void Show_time (); According to Is_24 and FROM0, the output is suitable for form -20:23:5/8:23:5 pm/08:23:05 pm void add_seconds (int); Added n seconds void add_minutes (int); Added n minutes void add_hours (int);  Added n-hour static void Change24 ();   Change static member is_24, convert static void Changefrom0 () between 12 and 24 o'clock; Change static member From0, toggle whether leading 0private:static bool is_24; When True, the 24-hour system, such as 20:23:5, is flase,12-hour, and is displayed as 8:23:5 pm static bool from0;    When True, the leading 0,8:23:5 is displayed as 08:23:05 int hour;    int minute; int sec;}; Time::time (int h,int m,int s): Hour (h), Minute (m), SEC (s) {};bool time::is_24=true;bool time::from0=true;void time::show    _time () {int h= (is_24)? hour:hour%12;    if (h<10&&from0) cout<< ' 0 ';    cout<Operation Result:


@ Mayuko


Week five Project 4-static member application

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.