6 7 日期類的設計與實現 30分

2021-10-24 01:10:55 字數 1360 閱讀 6989

使用過載運算子(++,+=,《等)實現日期類的操作。功能包括: 1)設定日期,如果日期設定不符合實際,則設定為預設日期(2023年1月1日) 2)在日期物件中向日期新增1或者加若干天(加入日期值後根據實際的日期進行月份、年份的變化) 3)過載流插入運算子進行日期的輸出,其中月份要用名稱表示

定義類mydate:

classmydate

主測試程式樣例:

#include

#include

using namespacestd;

/* 請在這裡填寫答案 */

intmain()

輸入樣例:

在這裡給出一組輸入。例如:

13 38 100

12 31 2009

2 28 2000

輸出樣例:

在這裡給出相應的輸出。例如:

d1 is january 1, 1900

d2 is december 31, 2009

d1 += 7 is january 8, 1900

d2 is december 31, 2009

++d2 is january 1, 2010

testing the prefix increment operator:

d3 is february 28, 2000

++d3 is february 29, 2000

d3 is february 29, 2000

testing the postfix increment operator:

d3 is february 29, 2000

d3++ is february 29, 2000

d3 is march 1, 2000

class mydate

void setdate(int m,int pd,int year)else

}mydate operator++()

}return *this;

}mydate operator++(int)

mydate operator+=(int day)

return *this;

}friend ostream& operator<<(ostream & outd,mydate md);

};ostream& operator<<(ostream & outd,mydate md);

outd

}

C 5 日期類的實現

比較運算子的過載 得出日期相差天數 列印日期 獲取當前月份天數 判斷是否是閏年 class date.c 執行測試圖 pragma once include using namespace std class date date date const date d date operator con...

01 日期抽象資料型別設計與實現

思維導圖如下 上學期學的c語言是資料結構的基礎,資料結構就像是把c語言的語法連起來使用。比起上學期按題目要求打 我們現在更要考慮 的時間複雜度和空間複雜度,要思考如何讓 達到最優,這個比單純解決題目要求更難,這個也是我們這個學期學習的重點,也是我們應該投入精力的部分。adt date 資料關係 r ...

1047 C 類與物件3 日期類

題目描述 定義乙個類date,類中有3個私有成員year month和day,兩個共有成員函式setday 和display 前乙個用來設定日期,後乙個用來顯示日期。在main 中定義2個物件,設定2個具體的日期,然後輸出這2個日期。輸入輸入2個日期的year month和day。輸出按照 年 月 ...