改了很久,还是感觉怪怪的
#include <iostream>using namespace std;
class DayOfYear
{
public:
friend bool equal(DayOfYear date1,DayOfYear date2); //友元
DayOfYear(int the_month,int the_day);
DayOfYear();
void input();
void output();
int get_month();
int get_day();
//private:
void check_date();
int month;
int day;
};
int main ()
{
DayOfYear today,bach_birthday(3,21);
cout<<"输入今天日期:";
today.input();
cout<<"今天是";
today.output();
cout<<"xxx的生日是";
bach_birthday.output();
if(equal(today,bach_birthday))
cout<<"happy!";
else
cout<<"unhappy!";
return 0;
}
bool equal(DayOfYear date1,DayOfYear date2)
{
return(date1.month == date2.month && date1.day ==date2.day);
}
DayOfYear::DayOfYear(int the_month,int the_day):month(the_month),day(the_day)
{
//无动作
}
int DayOfYear::get_month()
{
return month;
}
int DayOfYear::get_day()
{
return day;
}
//使用iostream
void DayOfYear::input()
{
cout<<"输入月份:";
cin>>month;
cout<<"输入日期:";
cin>>day;
}
void DayOfYear::output()
{
cout<<"月:"<<month<<",日:"<<day<<endl;
}