日期类的定义和使用
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库#include <iostream>
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库using namespace std;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库class Date
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库{
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库private:
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int year, month, day;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库public:
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void setDate(int y = 2000, int m = 1,int d = 1);
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void setYear(int y){year = y;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void setMonth(int m){month = m;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void setDay(int d){day = d;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int getYear(){return year;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int getMonth(){return month;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int getDate(){return day;}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void showDate();
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库};
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void Date::setDate(int y, int m, int d)
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库{
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库year = y;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库month = m;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库day = d;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库void Date::showDate()
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库{
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << year << ".";
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库if(month < 10) cout << '0';
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << month << '.';
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库if(day < 10) cout << ’0’;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << day << endl;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int main()
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库{
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库Date today, NationalDay, NewCentury;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库int year, month, day;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << "请输入今天的日期:";
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cin >> year >> month >> day;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库today.setDate(year, month, day);
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NationalDay.setYear(2019);
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NationalDay.setMonth(10);
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NationalDay.setDay(1);
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NewCentury.setDate();
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << "今天是:";
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库today.showDate();
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << "新世纪是:";
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NewCentury.showDate();
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库cout << "国庆节是:";
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库NationalDay.showDate();
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库return 0;
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库}
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库程序运行结果:
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库请输入今天的日期:2019 01 09
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库今天是:2019.01.09
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库新世纪是:2000.01.01
3DI100150满分答卷(100150.com)-青少年编程等级考试及竞赛题库国庆节是:2019.10.01