#include<iostream>
using namespace std;
class date
{
private:
int year;
int month;
int day;
int f;
int g;
int N;
public:
void readIn(void)
{
int year1;
int month1;
int day1;
cout<<"ÇëÊäÈëÈÕÆÚ"<<endl;
cout<<"year=";
cin>>year1;
cout<<endl;
cout<<"month=";
cin>>month1;
cout<<endl;
cout<<"day=";
cin>>day1;
cout<<endl;
if(year1>0)
year=year1;
else
{
cout<<"ÈÕÆÚ¸ñʽÊäÈëÓÐÎó£¬ÇëÊäÈë(Y)ÖØвâÊÔ»òÊäÈë(N)½áÊø³ÌÐò"<<endl;
char decision;
cin>>decision;
switch(toupper(decision))
{
case 'Y':
readIn();
case 'N':
{
cout<<"³ÌÐò½áÊø"<<endl;
system("pause");
exit(0);
}
}
}
if(month1>0&&month1<=12)
month=month1;
else
{
cout<<"ÈÕÆÚ¸ñʽÊäÈëÓÐÎó£¬ÇëÊäÈë(Y)ÖØвâÊÔ»òÊäÈë(N)½áÊø³ÌÐò"<<endl;
char decision;
cin>>decision;
switch(toupper(decision))
{
case 'Y':
readIn();
case 'N':
{
cout<<"³ÌÐò½áÊø"<<endl;
system("pause");
exit(0);
}
}
}
if((month==1||month==3||month==5||month==7||month==8||month==10||month==12)&&(day1>0&&day1<=31))
day=day1;
else if((month==4||month==6||month==9||month==11)&&(day1>0&&day1<=30))
day=day1;
else if((month==2)&&(year%400!=0&&year%4==0)&&(day1>0)&&(day1<=28))
day=day1;
else if((month=2)&&(year%4!=0)&&(day1>0&&day1<=29))
day=day1;
else
{
cout<<"ÈÕÆÚ¸ñʽÊäÈëÓÐÎó£¬ÇëÊäÈë(Y)ÖØвâÊÔ»òÊäÈë(N)½áÊø³ÌÐò"<<endl;
char decision;
cin>>decision;
switch(toupper(decision))
{
case 'Y':
readIn();
case 'N':
{
cout<<"³ÌÐò½áÊø"<<endl;
system("pause");
exit(0);
}
}
}
}
int getYear()
{
return year;
}
int getMonth()
{
return month;
}
int getDay()
{
return day;
}
int methodF(int Y,int M)//¼ÆËãfµÄ·½·¨£¬ÆäÖÐY´ú±íÄ꣬M´ú±íÔÂ
{
if(M<3)
f=Y-1;
else if(month>=3)
f=Y;
return f;
}
int methodG(int m)//¼ÆËãgµÄº¯Êý£¬ÆäÖÐm´ú±íÔÂ
{
if(month<3)
g=m+3;
else if(month>=3)
f=m+1;
return g;
}
int methodN(int n1,int n2, int n3)//¼ÆËãNµÄº¯Êý£¬ÆäÖÐn1´ú±íf£¬n2´ú±íg
{
N=1461*n1/4+153*n2/5+n3;
return N;
}
};
这个是我建好的类
然后在另一个工程里面调用这个类创造对象和调用方法
#include<iostream>
#include<minu.h>
void apply()
{
minu date1;
minu date2;
}
int sub(int a,int b)
{
return (a-b);
}
void loop()
{
cout<<"ÊäÈë(Y)¼ÌÐø²âÑé»òÕßÊäÈë(N)½áÊø³ÌÐò";
int decision;
cin>>decision;
switch(toupper(decision))
{
case 'Y':
{
apply();
date1.readIn();
date2.readIn();
int sub;
sub=sub(date1.methodN-date2.methodN);
cout<<date1.getYear()<<" "<<date1.getMonth()<<" "<<date1.getDay()<<" "<<"Óë"<<date2.getYear()<<" "<<date2.getMonth()<<" "<<
date2.getDay()<<"Ïà²î"<<sub<<"Ìì"<<endl;
}
case 'N':
{
cout<<"³ÌÐò½áÊø"<<endl;
}
int main(void)
{
apply();
date1.readIn();
date2.readIn();
int sub;
sub=sub(date1.methodN-date2.methodN);
cout<<date1.getYear()<<" "<<date1.getMonth()<<" "<<date1.getDay()<<" "<<"Óë"<<date2.getYear()<<" "<<date2.getMonth()<<" "<<
date2.getDay()<<"Ïà²î"<<sub<<"Ìì"<<endl;
loop();
system(pause);
return 0;
}
但是老实说找不到上面的那个类...