# What's the anniversary

"What's our 99 days together?"
"Say! How long have we been together today! "
"..."

source program
The original date is initialized directly and can be changed by yourself.

It can realize days statistics and days query between dates.
Blackboard program
I had nothing to write long ago.

#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
int MonthDays[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
class Date
{  public:
Date(int a=3,int b=3,int c=2018);//The initial date is March 3, 2018, constructor;
void assign(int a,int b,int c);//Assignment function;
void display();//Output function;
bool leap_year();//Determine whether it is a leap year (Boolean);
void increment(int n);//The date n days after the current date;
int accumulate(Date& t);
private:
int day;
int month;

int year;
};
int Date::accumulate(Date& t)
{ int sum,n1,n2;

n1=MonthDays[month]-day;

while(t.year>year)// Are the two dates "year" the same
{     if(leap_year()==0)
MonthDays[2]=28;
else
MonthDays[2]=29;

for(int i=month;i<12;i++)
{ n1+=MonthDays[i+1];
}
year+=1;
month=0;
}

if(leap_year()==0) //In the same year;
MonthDays[2]=28;
else
MonthDays[2]=29;
if(t.month>month)//Not in the same month;
{
for(int i=month;i<t.month-1;i++)
{ n1+=MonthDays[i+1];
}
n1+=t.day;
}
else
n1=t.day-day;

return n1;
}
Date::Date(int a,int b,int c)//Constructor;
{  day=a;
month=b;
year=c;
}
void Date::assign(int a,int b,int c)//Assignment function;
{  day=a;
month=b;
year=c;
}
void Date::display()//Output function;
{  cout<<year<<"/"<<month<<"/"<<day<<endl;
cout<<"========================"<<endl;
}
bool Date::leap_year() //Function to determine whether it is a leap year;
{  return(year%4==0&&year%100!=0)||(year%400==0);//Judgment conditions of leap year;
}
void Date::increment(int n) //Function to calculate the date after n days;
{
while(n>=31)//The number of days added is more than one month;

{
if(leap_year()==0)//Not a leap year;
{   MonthDays[2]=28;
n=n-MonthDays[month];
month+=1;
if(month>12)
{month=month-12;
year+=1;}
}
else//Is a leap year;
{if(month<3)
MonthDays[2]=29;
n=n-MonthDays[month];
month+=1;
if(month>12)
{month=month-12;
year+=1;}
}

}

if(leap_year()==0)
{  MonthDays[2]=28;
day=day+n;
if(day>MonthDays[month])
{day=day-MonthDays[month];
month+=1;
if(month>12)
{month=month-12;
year+=1;}
}
}
else
{ if(month<3)
MonthDays[2]=29;
day=day+n;
if(day>MonthDays[month])
{day=day-MonthDays[month];
month+=1;
if(month>12)
{month=month-12;
year+=1;}
}
} }
int main()
{
int n,a1,b1,c1,a2,b2,c2,a;
/*date1.display();//Output initialization;
date2.display();//Output March 3, 2018;*/
cout<<"Dear user, the default date is 2018.3.3"<<endl<<endl<<endl<<endl<<endl;
char m='y';
while(m=='y')
{  Date date1, date2(3,3,2018),date3,date4;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl<<endl;
cout<<"1.Find interval days 2.Seek addition n Days after"<<endl<<endl;
cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl<<endl<<endl;
if(a==1)
{
cin>>a2>>b2>>c2;//Enter another date;
date4.assign(c2,b2,a2);
cout<<"------------------------"<<endl;
cout<<"The days between are:";
cout<<date2.accumulate(date4)<<endl;//Days between calculations;
cout<<"========================"<<endl;}
if(a==2)
{
cin>>a1>>b1>>c1;//Enter a date;
date3.assign(c1,b1,a1);
cout<<"------------------------"<<endl;
cout<<"Please enter the number of days:"<<endl;
cin>>n;//Enter a day;
date3.increment(n);//The date after which the number of days is calculated;
cout<<"The accumulated date is:(year/month/day)"<<endl;
date3.display();//Display the date after the number of days;
}
cout<<"★★★★★★★★★★★★"<<endl;
cout<<"========================"<<endl;
cout<<"Do you want to continue? ( y/n)"<<endl;
cin>>m;
}
return 0;

}

Published 21 original articles, praised 0, visited 52

Posted on Sat, 07 Mar 2020 08:05:39 -0800 by ERuiz