| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 342 人关注过本帖
标题:改了很久,还是感觉怪怪的
只看楼主 加入收藏
yxieguodong
Rank: 1
来 自:广东湛江
等 级:新手上路
帖 子:17
专家分:8
注 册:2011-4-17
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:2 
改了很久,还是感觉怪怪的
程序代码:
#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;
}
2011-06-16 01:50
yxieguodong
Rank: 1
来 自:广东湛江
等 级:新手上路
帖 子:17
专家分:8
注 册:2011-4-17
收藏
得分:0 
程序代码:
#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 编辑 ]
2011-06-16 01:51
Pirelo
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:118
专家分:550
注 册:2011-1-28
收藏
得分:20 
回复 2楼 yxieguodong
程序代码:
#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;
}

这样不是可以了吗,具体的需求到底是什么?
2011-06-16 12:13
快速回复:改了很久,还是感觉怪怪的
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038130 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved