Day 5 C++

#include <iostream>
//多继承
using namespace std;
//封装沙发 类
class Sofa
{
private:
    string sitting;
public:
    Sofa(){cout<< "父类sofa无参构造函数" << endl;}
    Sofa(string s):sitting(s)
    {
        cout << "父类sofa有参构造函数" << endl;
    }
    //拷贝构造函数
    Sofa(const Sofa &other):sitting(other.sitting)
    {
        cout << "父类Sofa拷贝构造函数" << endl;
    }
    //拷贝赋值函数
    Sofa &operator=(const Sofa &other)
    {
        cout << "父类Sofa拷贝赋值函数" << endl;
        sitting=other.sitting;
        return *this;
    }
    ~Sofa()
    {
        cout << "父类sofa析构函数" << endl;
    }
    void show()
    {
        cout << sitting<< endl ;
    }

};


//封装 桌子 类
class Table
{
private:
    string material;
    int quaty;
public:
    Table(){cout << "父类Table无参构造函数" << endl;}
    Table(string material,int quaty):material(material),quaty(quaty)
    {
        cout << "父类Table有参构造函数" << endl;
    }
    //拷贝构造函数
    Table(const Table &other):material(other.material),quaty(other.quaty)
    {
        cout << "父类Table拷贝构造函数" << endl;
    }
    //拷贝赋值函数
    Table &operator=(const Table &other)
    {
        cout << "父类Table拷贝赋值函数" << endl;
        material=other.material;
        quaty=other.quaty;
        return *this;
    }
    ~Table()
    {
        cout << "父类Table析构函数" << endl;
    }
    void show()
    {
        cout << material <<endl;
        cout << quaty << endl;

    }
};
//封装 家具 沙发 桌子
class Furni :public Sofa,public Table
{
private :
    int num ;
    string color;
public:
    Furni(){cout << "子类无参构造函数" << endl;}
    Furni(int n,string c,string sit,string m,int q):Sofa(sit),Table(m,q),num(n),color(c)
    {
        cout << "子类有参构造函数" << endl;
    }
    //子类拷贝构造函数
    Furni(const Furni &other):num(other.num),color(other.color),Sofa(other),Table(other)
    {
        cout << "子类拷贝函数" << endl;
    }
    //子类拷贝赋值函数
    Furni &operator=(const Furni &other)
    {
        cout << "子类拷贝赋值函数" << endl;
        num=other.num;
        color=other.color;
        Sofa::operator=(other);
        Table::operator=(other);
        return *this;
    }
    ~Furni()
    {
        cout << "子类析构函数" << endl;
    }


    void show()
    {
        cout << num <<endl;
        cout << color << endl;

    }

};
int main()
{
    Furni s(10,"white","可坐","woolen",20);
    Furni s1;
    Furni s2(s);
    s1=s;
    s.Sofa::show();
    s.Table::show();
    s.show();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值