亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

定義一個時間類 Time,它能表示 24 小時制的時、分、秒,具體要求如下

張軍 6577 0

(20 ) 定義一個時間類 Time,它能表示 24 小時制的時、分、秒,具體要求如下:


  1. (1) 供默認構造函數 Time(),將時、分、 秒都初始化成 0。

  2. (2) 提供構造函數 Time(int h, int m, int s)

  3. (3) 提供成員函數 set(int h, int m, int s),功能是調整時間。

  4. (4)能夠分別獲取時、分、秒信息。

  5. (5) 提供成員函數 display(),顯示時間值。

  6. (6) 提供成員函數 equal(Time &other_time),比較是否與時間 other_time 相等。

  7. (7) 提供成員函數 increment()使時間增加一秒。

  8. (8) 提供成員函數 less_than(Time &other_time),比較是否早于時間 other_time。

// ConsoleApplication1.cpp : 定義控制臺應用程序的入口點。
//《面向對象程序設計(C++)》期末考試試題(綜合大作業)(原創張軍(QQ:360901061))


#include "stdafx.h"
#include <iostream>;
using namespace std;
class Time
{
public:
	// (1) 提供默認構造函數 Time(),將時、分、 秒都初始化成 0。
	Time()
	{
		_h = 0;
		_m = 0;
		_s = 0;
	}

	// (2) 提供構造函數 Time(int h, int m, int s)。
	Time(int h, int m, int s)
	{
		check(h, m, s);
		_h = h;
		_m = m;
		_s = s;
	}
	bool check(int h, int m, int s){
		//判斷輸入值合法性
		if (h<0 || h>23 || m < 0 || m >59 || s<0 || s > 59){
			throw string("時間格式不合法");
		}
	}
	//(3) 提供成員函數 set(int h, int m, int s),功能是調整時間。
	void set(int h, int m, int s){
		check(h, m, s);
		_h = h;
		_m = m;
		_s = s;
	}
	//(4)能夠分別獲取時信息。
	int getH(){
		return _h;
	}
	//(4)能夠分別獲取分信息。
	int getM(){
		return _m;
	}
	//(4)能夠分別獲取秒信息。
	int getS(){
		return _s;
	}
	//(5) 提供成員函數 display(),顯示時間值。
	void display(){
		cout << _h << " 時 " << _m << " 分 " << _s << " 秒 " << endl;
	}
	//(6) 提供成員函數 equal(Time &other_time),比較是否與時間 other_time 相等。
	bool equal(Time other_time){
		if (_h == other_time._h && _m == other_time._m && _s == other_time._s){
			return true;
		}
		else{
			return false;
		}
	}
	//(7) 提供成員函數 increment(),使時間增加一秒。
	void increment(){
		_s++;
		if (_s == 60) {
			_m++; _s = 0;
			if (_m == 60) {
				_h++; _m = 0;
				if (_h == 24) {
					_h = 0; _m = 0; _s = 0;
				}
			}
		}
	}
	//(8) 提供成員函數 less_than(Time &other_time),比較是否早于時間 other_time。
	bool less_than(Time other_time){
		if (_h < other_time._h) { return true; }
		else if (_h == other_time._h && _m < other_time._m) { return true; }
		else if (_h == other_time._h && _m == other_time._m && _s < other_time._s) { return true; }
		else { return false; }
	}
	//表示 24 小時制的時、分、秒
private:
	int _h;
	int _m;
	int _s;
};

int main()
{
	//Time t;
	Time t(22, 59, 59);
	//Time t2(10, 11, 12);
	//t.increment();
	//t.set(15, 16, 17);
	t.display();
	//cout << t.getH() << endl;
	//cout << t.equal(t2) << endl;
	//cout << t2.less_than(t) << endl;
	system("pause");
	return 0;
}



更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲999| 伊人婷婷色 | 在线 中文字幕 日韩 欧美 | 青青青爽线在线视频观看 | 中文字幕第13亚洲另类 | 国内精品日本久久久久影院 | 另类欧美chinese | 91香蕉网站 | 日本 国产 欧美 | 国产精品久久久久久久9999 | 日韩一区三区 | 一级做a爱片特黄在线观看 一级做a爱片特黄在线观看免费看 | 欧美一区二区高清 | 青草久草视频 | 男女性高爱麻豆 | 深夜视频在线 | 一本一本久久a久久精品综合麻豆 | 免费一级欧美大片久久网 | 欧美视频在线不卡 | 一区二区三区在线免费看 | 伊人久久在线观看 | 亚洲精品国产经典一区二区 | 在线高清免费爱做网 | 综合色久| 思99热精品久久只有精品 | 久久性生活片 | 2021久久精品国产99国产 | 亚洲视频综合网 | 亚洲欧美国产中文 | 久cao在线观看视频 久re这里只有精品最新地址 | 99热久久国产综合精品久久国产 | 精品一区二区日本高清 | 亚洲人妖女同在线播放 | 欧美成人啪啪看片 | 欧美综合区 | 奇米777四色影视在线看 | 狠狠大日本亚洲香蕉亚洲 | 日本久久精品免视看国产成人 | 国内精品欧美久久精品 | 777kkk亚洲综合欧美色老头 | 老头做爰xxxx视频 |