clock.cpp

来自「这是 一个电梯模拟的C++程序...分成N个文件运行..实现自动模拟」· C++ 代码 · 共 52 行

CPP
52
字号
//Clock.cpp
#include"All.h"

Clock::Clock()
{ 
	currenttime = time(0) ; 
}

long int Clock::gettime() 
{
	return currenttime ;
}

void Clock::showtime() 
{
	int t = time(0) ;
	int todaysecond = t % ( 24 * 60 * 60 ) ;

	hour = todaysecond / ( 60 * 60 ) + 8 ;
	minute = todaysecond / 60 % 60 ;
	second = todaysecond % 60 ;

	if( hour < 10 )
		cout << "0" ;
	cout << hour << " 点 " ;
	if( minute < 10 )
		cout << "0" ;
	cout << minute << " 分 " ;
	if( second < 10 )
		cout << "0" ;
	cout << second << "秒" ;
}

void Clock::change( long int x ) 
{
	int todaysecond = x % ( 24 * 60 * 60 ) ;

	int h = todaysecond / ( 60 * 60 ) + 8 ;
	int m = todaysecond / 60 % 60 ;
	int s = todaysecond % 60 ;

	if( h < 10 )
		cout << "0" ;
	cout << h << " 点 " ;
	if( m < 10 )
		cout << "0" ;
	cout << m << " 分 " ;
	if( s < 10 )
		cout << "0" ;
	cout << s << "秒" ;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?