修改tdate.cpp

This commit is contained in:
Hmtsai 2023-10-29 16:20:55 +08:00
parent 58bc9a220e
commit 31f507b004
3 changed files with 87 additions and 46 deletions

87
src/type/class/tdate.cpp Normal file
View File

@ -0,0 +1,87 @@
#include <iostream>
using namespace std;
class Tdate
{
public:
Tdate ( int setDay,int setMouth,int setYear ) //构造函数没有返回类型,一个类可以由多个构造函数
{
set ( setDay,setMouth,setYear );
}
void set ( int setDay,int setMouth,int setYear )
{
day=setDay;
mouth=setMouth;
year=setYear;
}
int isLeapYear()
{
return ( ( year%4==0&&year%100!=0 ) || ( year%400==0 ) );
}
void printYear()
{
cout<<year<<"/"<<mouth<<"/"<<day<<endl;
}
void nextDay()
{
if ( mouth==2 ) {
if ( isLeapYear() ) {
if ( day+1>29 ) {
mouth++;
day=1;
} else {
day++;
}
} else {
if ( day+1>28 ) {
mouth++;
day=1;
} else {
day++;
}
}
} else if ( isBigMouth ( mouth ) ) {
if ( day+1>31 ) {
mouth++;
day=1;
} else {
day++;
}
} else if ( mouth==12 ) {
if ( day+1>31 ) {
year++;
mouth=1;
day=1;
} else {
day++;
}
} else {
if ( day+1>20 ) {
mouth++;
day=1;
} else {
day++;
}
}
}
private:
int day,mouth,year;
int isBigMouth ( int inMouth )
{
int bigMouth[7]= {1,3,5,7,8,10};
for ( int i=0; i<7; i++ ) {
if ( inMouth==bigMouth[i] ) {
return 1;
}
}
return 0;
}
};
int main()
{
Tdate date ( 21,10,2011 );
date.printYear();
cout<<date.isLeapYear() <<endl;
return 0;
}

View File

@ -1,35 +0,0 @@
#include <iostream>
using namespace std;
class Tdate
{
public:
Tdate ( int setDay,int setMouth,int setYear ) //构造函数没有返回类型,一个类可以由多个构造函数
{
set ( setDay,setMouth,setYear );
}
void set ( int setDay,int setMouth,int setYear )
{
day=setDay;
mouth=setMouth;
year=setYear;
}
int isLeapYear()
{
return ( ( year%4==0&&year%100!=0 ) || ( year%400==0 ) );
}
void printYear()
{
cout<<year<<"/"<<mouth<<"/"<<day<<endl;
}
private:
int day,mouth,year;
};
int main()
{
Tdate date ( 21,10,2011 );
date.printYear();
cout<<date.isLeapYear() <<endl;
return 0;
}

View File

@ -1,11 +0,0 @@
#include <iostream>
using namespace std;
int main(){
int year;
cin>>year;
if(((year%4==0)&&(year%100!=0))||year%400==0){
return 0;
}else{
return 1;
}
}