⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2_5.cpp

📁 一个时间类的若干操作
💻 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(&ltime);
	struct tm *nowtime;
	nowtime=localtime(&ltime);
	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 + -