我的void show( )函数是以年月日的方式输出year day month
void yesterday( )函数是把变量day减一,让日期变成昨天
但我只要一输入时间比如输入2022 3 10按完回车之后 show函数没有显示2022年3月9日 而是仍然显示2021年3月10日
所以应该怎么改
#include<iostream>
using namespace std;
class Date
{
private:
int day;
int month;
int year;
public:
Date(int day=1,int month=1,int year=1);
void setDay(int );
int getDay();
void setMonth(int );
int getMonth();
void setYear(int );
int getYear();
void yesterday( );
void show( );
};
Date:: Date(int day,int month,int year)
{
cout << "This is constructor " << endl;
}
void Date:: setDay(int Day)
{
day=Day;
}
int Date:: getDay()
{
return day;
}
void Date:: setMonth(int Month)
{
month=Month;
}
int Date:: getMonth()
{
return month;
}
void Date:: setYear(int Year)
{
year=Year;
}
int Date:: getYear()
{
return year;
}
void Date:: yesterday( )
{
day--;
}
void Date:: show( )
{
cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
int main()
{
int year,month,day;
Date d;
cin>>year>>month>>day;
d.setYear(year);
d.setMonth(month);
d.setDay(day);
d.yesterday();
d.show();
system("pause");
return 0;
}