首页 > 其他分享 >6-1Date类

6-1Date类

时间:2023-05-29 21:36:00浏览次数:23  
标签:定义 1Date month int year Date display

本题要求实现一个日期类定义,根据所定义的类可以完成相关的类测试。

Date类定义:

根据Date被使用的情况,进行Date类定义,要求通过构造函数进行日期初始化,并通过display()函数进行日期格式显示,显示格式为"月/日/年"

#include<bits/stdc++.h>
using namespace std;
class Date{
public:
Date(int a=1,int b=1,int c=2019)
{
date=a;
month=b;
year=c;
}
void display()
{
cout<<date<<"/"<<month<<"/"<<year<<endl;
}
private:
int date,month,year;
};
int main()
{
Date d1(3,25,2019);
Date d2(3,30);
Date d3(10);
Date d4;
d1.display();
d2.display();
d3.display();
d4.display();
return 0;
}

标签:定义,1Date,month,int,year,Date,display
From: https://www.cnblogs.com/Christmas77/p/17441704.html

相关文章