| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 315 人关注过本帖
标题:请各位支招,谢谢
只看楼主 加入收藏
爱学习ing
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2014-3-20
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
请各位支招,谢谢
定义一个Birthday类,该类拥有year、month和day三个私有成员。在此基础上,定义一个Student类,包括三个私有成员:char name[20]; int id; Birthday birthday。为这两个类添加构造函数和拷贝构造函数,同时添加一个显示成员的函数show来分别显示各自的成员。main函数中的代码为:
     Birthday b(2000,1,1);
     Student s(“Tom”,1,b);
     s.show();
2014-04-03 16:38
hubinyes
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:11
帖 子:104
专家分:557
注 册:2014-2-4
收藏
得分:20 
class CBirthday
{
public:
    CBirthday(int year = 0,int month = 0,int day = 0)
    :m_iYear(year),m_iMonth(month),m_iDay(day)
    {

    }

    ~CBirthday(){}

    CBirthday(const CBirthday& birthday)
    {
        m_iYear = birthday.m_iYear;
        m_iMonth = birthday.m_iMonth;
        m_iDay = birthday.m_iDay;
    }

    void Show()
    {
        cout << m_iYear <<" "<< m_iMonth <<" "<< m_iDay <<endl;
    }

private:
    int m_iYear;
    int m_iMonth;
    int m_iDay;
};

class CStudent
{
public:
    CStudent(char name[20],int id,CBirthday birthday)
    {
        strcpy(this->name,name);
        this->id = id;
        this->birthday = birthday;
    }
    ~CStudent(){}
   
    CStudent(const CStudent& student)
    {
        strcpy(this->name,student.name);
        this->id = student.id;
        this->birthday = student.birthday;
    }

    void Show()
    {
        cout << name <<" " << id <<" ";
        birthday.Show();
    }

private:
    char name[20];
    int id;
    CBirthday birthday;
};
void main()
{
    CBirthday b(2000,1,1);
    CStudent s("Tom",1,b);
    b.Show();
    s.Show();

    getchar();
}
2014-04-03 22:02
快速回复:请各位支招,谢谢
数据加载中...
 
   



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

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