📄 cpp04.cpp
字号:
// Coded by plusir -- Dec.29.2002.
// Standard C++ Bible -- (P253-9-4)
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std ;
// ------------------------------------ struct Date ;
struct Date
{
int month ;
int day ;
int year ;
void display( void ) ;
} ;
void Date::display( void )
{
static char *mon[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
} ;
cout << mon[month - 1] << ' ' << day << ", " << year ;
}
// -------------------------------------- struct Time
struct Time
{
int hour ;
int minute ;
int second ;
void display( void ) ;
} ;
void Time::display( void )
{
cout.fill( '0' ) ;
cout
<< ( hour > 12 ? hour - 12 : ( hour == 0 ? 12 : hour ) ) << ':'
<< setw( 2 ) << minute << ':'
<< setw( 2 ) << second
<< ( hour < 12 ? "am" : "pm" ) ;
cout.fill( ' ' ) ;
}
// ---------------------------------------- main function
int main()
{
time_t curtime = time( NULL ) ;
tm tim = *localtime( &curtime ) ;
Time now ;
Date today ;
now.hour = tim.tm_hour ;
now.minute = tim.tm_min ;
now.second = tim.tm_sec ;
today.month = tim.tm_mon ;
today.day = tim.tm_mday ;
today.year = tim.tm_year + 1900 ;
cout << "At the tone it will be " ;
now.display() ;
cout << " on " ;
today.display() ;
cout << '\a' << endl ;
return 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -