学生类

作者: 逍遥_9353 | 来源:发表于2018-04-16 16:02 被阅读96次

    #include<iostream>

    #include<string>

    using namespace std;

    class date

    {

    public:

    /*

    date()//构造

    {

    yy=2000;

    mm=5;

    dd=4;

    cout<<"date constructor..."<<endl;

    }

    */

    date(int y=2000,int m=5,int d=4)//构造

    {

    yy=y;

    mm=m;

    dd=d;

    cout<<"date  constructor two..."<<endl;

    }

    date(date &rd)//拷贝构造

    {

    yy=rd.yy;

    mm=rd.mm;

    dd=rd.dd;

    cout<<"date  copy  constructor..."<<endl;

    }

    ~date()

    {

    cout<<"date destructor..."<<endl;

    }

    void show()

    {

    cout<<"brithday:year/month/day"<<yy<<"/"<<mm<<"/"<<dd<<endl;

    }

    private:

    int yy;

    int mm;

    int dd;

    };

    class student

    {

    public:

        /*

    student()

    {

    m_num=201720180101;

    m_name="zhang";

    cout<<"student  constructor..."<<endl;

    }

    */

    student(string n,string s,int y,int m,int d):m_bri(y,m,d)

    {

    m_num=n;

    m_name=s;

    cout<<"student constructor two..."<<endl;

    }

    student(string n,string s,date &rd):m_bri(rd)

    {

    m_num=n;

    m_name=s;

    cout<<"student constructor three..."<<endl;

    }

    student(student &rs)//拷贝构造

    {

    m_num=rs.m_num;

    m_name=rs.m_name;

    cout<<"student  copy  constructor..."<<endl;

    }

    ~student()//析构

    {

    cout<<"student destructor..."<<endl;

    }

    void printinfo()

    {

    cout<<"number:"<<m_num<<"    name:"<<m_name<<"    ";

    m_bri.show();

    }

    private:

    string  m_num;

    string  m_name;

    date m_bri;

    };

    int main()

    {

    student s1("201720180101","zhou",1996,1,1);

    s1.printinfo();

    date tday(2018,4,16);

    student s2("201720181601","wang",tday);

    s2.printinfo();

    //student s3();

    //s3.printinfo();

    return 0;

    学生类

    相关文章

      网友评论

      • 尼枚哉:写大段代码的时候 用 ```(数字1前面的一个键)```这样包起来,会显示代码样式出来,更好阅读。像这样:

        ```
        class Hello {
        main() {
        }
        }
        ```
        逍遥_9353:@尼枚哉 好的,谢谢你的建议

      本文标题:学生类

      本文链接:https://www.haomeiwen.com/subject/easekftx.html