日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

日程安排(多重继承+重载)

發(fā)布時間:2023/12/18 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 日程安排(多重继承+重载) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

已有一個日期類Date,包括三個protected成員數(shù)據(jù)

int year;

int month;

int day;

另有一個時間類Time,包括三個protected成員數(shù)據(jù)

int hour;

int minute;

int second;

現(xiàn)需根據(jù)輸入的日程的日期時間,安排前后順序,為此以Date類和Time類為基類,建立一個日程類Schedule,包括以下新增成員:

int ID;//日程的ID

bool operator < (const Schedule & s2);//判斷當前日程時間是否早于s2

生成以上類,并編寫主函數(shù),根據(jù)輸入的各項日程信息,建立日程對象,找出需要最早安排的日程,并輸出該日程對象的信息。

輸入格式: 測試輸入包含若干日程,每個日程占一行(日程編號ID 日程日期(****//)日程時間(::**))。當讀入0時輸入結束,相應的結果不要輸出。

輸入樣例:

1 2014/06/27 08:00:01

2 2014/06/28 08:00:01

0

輸出樣例:

The urgent schedule is No.1: 2014/6/27 8:0:1

#include <iostream> using namespace std;class Date {public:Date(int y, int mo, int d): year(y), month(mo), day(d) {}protected:int year;int month;int day; };class Time {protected:int hour;int minute;int second;public:Time(int h, int mi, int s): hour(h), minute(mi), second(s) {} };class Schedule: public Date, public Time {int ID;public:Schedule();Schedule(int y, int mo, int d, int h, int mi, int s, int id): Date(y, mo, d), Time(h, mi, s) {ID = id;}bool operator<(const Schedule &s2) {if (year < s2.year) {return 1;} else if (year == s2.year) {if (month < s2.month)return 1;else if (month == s2.month) {if (day < s2.day)return 1;else if (day == s2.day) {if (hour < s2.hour)return 1;else if (hour == s2.hour) {if (minute < s2.minute)return 1;if (second < s2.second)return 1;}}}}return 0;}void disp() {cout << "The urgent schedule is No." << ID << ':' << " " << year << '/' << month << '/' << day << ' ' << hour << ':' <<minute<< ':' << second <<endl;} };int main() {int id, i;int y, mo, d, h, mi, s;char op1, op2, op3, op4;Schedule *sche[100];Schedule *early;int count = 0;cin >> id;while (id != 0) {cin >> y >> op1 >> mo >> op2 >> d >> h >> op3 >> mi >> op4 >> s;sche[count++] = new Schedule(y, mo, d, h, mi, s, id);cin >> id;}early = sche[0];for (i = 1; i < count; i++) {if ((*sche[i] < *early)) {early = sche[i];}}early->disp();return 0; }

總結

以上是生活随笔為你收集整理的日程安排(多重继承+重载)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。