C++ Operator Overloading的问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 01:50:49
1. Develop a class Date for representing a calendar. The class should provide:

1) A default constructor that initializes the date to May 1, 2009.
2) Another constructor should initialize a Date object to a specific month, day, and year.
3) A destructor;
4) Three public gets and three public sets that allow the month, day, and year to be accessed.
5) The operators ++ and -- should be overloaded so that when applied to a Date object, the object’s new value is, respectively, the successive or preceding day.
6) The subtraction operator should be overloaded such that the difference of two dates is the number of days between them.
7) The addition operator taking an extra int argument n should be overloaded to get the Date n days after this;
8) Overload the insertion and extraction operator for Date objects.
9) Provide a main() to test your Date class.
不会啊~求高手帮忙解答!

1、一个缺省的构造函数2009.5.1
2、含三个参数的构造函数year.month.day
3、一个析构函数
4、获得年月日的三个公有函数,设定年月日的三个公有函数
5、重载++和--,使之满足日期对象的特征
6、-(减号)运算符重载之后能得到两个日期之间的天数
7、+(加号)运算符重载之后能得到一个日期加上一个天数之后的另一个日期
8、给日期对象重载插入>>(insertion)和获取(extraction)<<
9、main函数来测试你的日期类。

基本上就是重载++,--,+,-,<<,>> 看看书上相关的知识,不难的