我把你的代码改了一下但还是运行不了。
不过我们的主管说那是设置的问题你可以在你的机器上试一下
//~:data.h
#ifndef DATA_H
#define DATA_H
class data
{
private:
int year;
int month;
int day;
public:
data(int y,int m,int d);
bool leapYear();
int getYear();
int getMonth();
int getDay();
bool inputYearRight(); //判断年是否超出范围
bool inputMonthRight(); //判断月是否超出范围
bool inputDayRight1(); //判断日是否超出范围(大月)
bool inputDayRight2(); //判断日是否超出范围(小月)
bool inputDayRight3(); //判断日是否超出范围(二月.闰年)
bool inputDayRight4(); //判断日是否超出范围(二月.非闰年)
bool inputRight(); //综合判断
void display(); //显示下一天的日期
~data();
};
#endif ///:~data.h
//:data.cpp
#include "data.h"
#include<iostream.h>
//using namespace std;
data::data(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
bool data::leapYear() //判断是否为闰年
{
return (year%4==0&&year%100!=0)||(year%400==0);
}
int data::getYear()
{
return year;
}
int data::getMonth()
{
return month;
}
int data::getDay()
{
return day;
}
bool data::inputYearRight() //判断年是否超出范围
{
return (year>=1812&&year<=2012);
}
bool data::inputMonthRight() //判断月是否超出范围
{
return (month>=1&&month<=12);
}
bool data::inputDayRight1() //判断日是否超出范围(大月)
{
return(day>=1&&day<=31);
}
bool data::inputDayRight2() //判断日是否超出范围(小月)
{
return(day>=1&&day<=30);
}
bool data::inputDayRight3() //判断日是否超出范围(二月.闰年)
{
return(day>=1&&day<=29);
}
bool data::inputDayRight4() //判断日是否超出范围(二月.非闰年)
{
return(day>=1&&day<=28);
}
bool data::inputRight() //综合判断
{
if(data::inputYearRight()&&data::inputMonthRight())
{
if(data::getMonth()==1||data::getMonth()==3||data::getMonth()==5||data::getMonth()==7||data::getMonth()==8||data::getMonth()==10||data::getMonth()==12)
return data::inputDayRight1();
if(data::getMonth()==4||data::getMonth()==6||data::getMonth()==9||data::getMonth()==11)
return data::inputDayRight2();
if(data::getMonth()==2)
{
if(data::leapYear())
return data::inputDayRight3();
if(!data::leapYear())
return data::inputDayRight4();
}
}
return 0;
}
void data::display() //显示下一天的日期
{
if(data::inputRight())
{
cout<<"the Data you input is effectual!"<<endl;
cout<<"the Next Day is: "<<endl;
if(data::getMonth()==1||data::getMonth()==3||data::getMonth()==5||data::getMonth()==7||data::getMonth()==8||data::getMonth()==10||data::getMonth()==12)
{
if(data::getDay()<=30)
cout<<data::getYear()<<"year "<<data::getMonth()<<"month "<<data::getDay()+1<<"th"<<endl;
if(data::getDay()==31&&data::getMonth()!=12)
cout<<data::getYear()<<"year "<<data::getMonth()+1<<"month "<<"1th"<<endl;
if(data::getDay()==31&&data::getMonth()==12&&data::getYear()!=2012)
cout<<data::getYear()+1<<"year "<<"1 month "<<"1th"<<endl;
if(data::getDay()==31&&data::getMonth()==12&&data::getYear()==2012)
cout<<"the NextData is paranormal !";
}
if(data::getMonth()==4||data::getMonth()==6||data::getMonth()==9||data::getMonth()==11)
{
if(data::getDay()<=29)
cout<<data::getYear()<<"year "<<data::getMonth()<<"month "<<data::getDay()+1<<"th"<<endl;
if(data::getDay()==30)
cout<<data::getYear()<<"year "<<data::getMonth()+1<<"month "<<"1th"<<endl;
}
if(data::getMonth()==2)
{
if(data::leapYear())
{
if(data::getDay()<=28)
cout<<data::getYear()<<"year "<<data::getMonth()<<"month "<<data::getDay()+1<<"th"<<endl;
if(data::getDay()==29)
cout<<data::getYear()<<"year "<<data::getMonth()+1<<"month "<<"1th"<<endl;
}
if(!data::leapYear())
{
if(data::getDay()<=27)
cout<<data::getYear()<<"year "<<data::getMonth()<<"month "<<data::getDay()+1<<"th"<<endl;
if(data::getDay()==28)
cout<<data::getYear()<<"year "<<data::getMonth()+1<<"month "<<"1th"<<endl;
}
}
}
else
cout<<"the data is useless!"<<endl;
}
data::~data()
{
cout<<" The end!"<<endl;
}
#include "data.h"
#include<iostream.h>
//using namespace std;
int main()
{
int y,m,d;
cout<<"please input data: eg::9 30 2006"<<endl;
cin>>y;
cin>>m;
cin>>d;
data newData(y,m,d);
while(!newData.inputRight())
{
cout<<"input error,please input again."<<endl;
cin>>y;
cin>>m;
cin>>d;
};
newData.display();
return 0;
}