?? 2_5.cpp
字號:
// 2_5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
#include "time.h"
class Time{
public:
Time();
void settime(int ,int ,int );
void printstandard();
private:
int hour;
int minute;
int second;
};
Time::Time()
{
time_t ltime;
time(<ime);
struct tm *nowtime;
nowtime=localtime(<ime);
hour=nowtime->tm_hour;
minute=nowtime->tm_min;
second=nowtime->tm_sec;
}
void Time::settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void Time::printstandard()
{
cout<<((hour==0||hour==12)?12:hour%12)
<<":"<<(minute<10?"0":"")<<minute
<<":"<<(second<10?"0":"")<<second
<<(hour<12?"AM":"PM")
<<'\n';
}
main()
{
Time t;
t.printstandard();
t.settime(11,11,11);
t.printstandard();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -