Week five (timetable)

Source: Internet
Author: User

/*
*copyright (c) 2015, College of Computer Science, Yantai University
*all rights reserved.
* File name: Week fifth (timetable)

* Wangzhong
* Completion Date: 2015.4.8

* Version Number: v1.0
*
* Problem Description: 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.

* Input Description: Time

* Program output: Time

Less than two bits, the time reason, to the leading 0 has not yet completed, and the late efforts to add

#include <iostream>using namespace Std;class time{public:time (int=0,int=0,int=0); void Show_time ();//According to Is_ 24 and From0, output suitable form -20:23:5/8:23:5 pm/08:23:05 pmvoid 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 0 private:static bool is_24; True, 24-hour system, such as 20:23:5, for flase,12 hours, shown as 8:23:5 pmstatic bool from0; When True, the leading 0,8:23:5 is displayed as 08:23:05int hour;int minute;int sec;};/    /write down the initialization of the static member and the definition of the member function ... bool Time::is_24=true;bool time::from0=true;int main () {Time T1 (23,24,25), T2 (8,9,7);    T1.show_time ();    T2.show_time ();    T1.add_seconds (40);    T1.show_time ();    T1.add_minutes (20);    T1.show_time ();    T1.add_hours (10);    T1.show_time ();    T1.change24 ();    T1.show_time (); return 0;} Time::time (int h,int m,int s): Hour (h), Minute (m), SEC (s) {}void time::show_time () {if (is_24) cout<


Week five (timetable)

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.