程序代码:
#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;
}
小乙 1:40:52
把构造函数定义写到下边怎么不行啊?
Aaron 1:41:03
不会吧
小乙 1:41:04
#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)
{
//无动作
}
DayOfYear::DayOfYear()
{
}
int DayOfYear::get_month()
{
return month;
}
int DayOfYear::get_day()
{
return day;
}
//使用iosream
void DayOfYear::input()
{
cout<<"输入月份:";
cin>>month;
cout<<"输入日期:";
cin>>day;
}
void DayOfYear::output()
{
cout<<"月:"<<month<<",日:"<<day<<endl;
}
[
本帖最后由 yxieguodong 于 2011-6-16 01:53 编辑 ]