Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Date.cpp #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions 201816040230/Ex03_15/Date.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include "Date.h"
using namespace std;
Date::Date(int month1,int day1,int year1)//构造函数初始化
{
setMonth(month1);
setDay(day1);
setYear(year1);
}
void Date::setMonth(int month2)//月的set函数
{
month=month2;
}
int Date::getMonth()//月的get函数
{
if(month<1||month>12)//如果月不在1到12内则输出1
return 1;
return month;
}
void Date::setDay(int day2)//日的set函数
{
day=day2;
}
int Date::getDay()//日的get函数
{
return day;
}
void Date::setYear(int year2)//年的set函数
{
year=year2;
}

int Date::getYear()//年的get函数
{
return year;
}
void Date::displayDate()//输出显示数据
{
cout<<"月"<<"/"<<"日"<<"/"<<"年: "<<getMonth()<<"/"<<getDay()<<"/"<<getYear();
}