/*
02. *Copyright (c) 2016,烟台大学计算机学院
03. *All rights reserved.
04. *文件名称:cpp
05. *作 者:孙亚茹
06. *完成日期:2016年4月10日
07. *版 本 号:v1.0
09. *问题描述:输出分数的各种形式。
*/
#include <iostream>
using namespace std;
class time
{
private:
static bool is_24;
static bool from0;
int hour;
int minute;
int sec;
public:
time(int=0,int=0,int=0);
void show_time();
void add_seconds(int);
void add_minutes(int);
void add_hours(int);
static void change24();
static void changefrom0();
};
bool time::is_24=true;
bool time::from0=false;
time::time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
void time::show_time()
{
if(from0)
{
if(hour<10)
cout<<"0"<<hour<<":";
else
cout<<hour<<":";
if(minute<10)
cout<<"0"<<minute<<":";
else
cout<<minute<<":";
if(sec<10)
cout<<"0"<<sec<<endl;
else
cout<<sec<<endl;
}
}
void time::add_hours(int z)
{
hour+=z;
if(hour>=24)
{
hour=hour%24;
}
}
void time::add_minutes(int y)
{
minute+=y;
if(minute>=60)
{
hour+=minute/60;
minute=minute%60;
}
}
void time::add_seconds(int x)
{
sec+=x;
if(sec>=60)
{
minute+=sec/60;
sec=sec%60;
}
}
void time::changefrom0()
{
is_24=!is_24;
}
void time::change24()
{
from0=!from0;
}
int main()
{
time t1(23,14,25);
time t2(8,45,6);
cout<<"24小时制,不前导0:"<<endl;
t1.show_time();
t2.show_time();
cout<<"10小时后,切换是否前导0:"<<endl;
t1.add_hours(10);
t2.add_hours(10);
time::change24();
cout<<"t1是:";
t1.show_time();
cout<<"t2是:";
t2.show_time();
cout<<"换一种时制:"<<endl;
t1.changefrom0();
cout<<"t1是:";
t1.show_time();
t2.changefrom0();
cout<<"t2是:";
t2.show_time();
}