C++Day5

C++Day5_第1张图片

#include 

using namespace std;

class Sofa
{
    string sitting;
public:
    Sofa()
    {

    }
    Sofa(string sitting):sitting(sitting)
    {

    }
    void show()
    {
        cout << sitting << endl;
    }

};

class Bed
{
    string sleep;
public:
    Bed()
    {
        sleep = "躺着";
    }
    Bed(string sleep):sleep(sleep)
    {

    }
    void show()
    {
        cout << sleep << endl;
    }
};

class Sofa_bed:public Sofa,public Bed
{
    string color;
public:
    Sofa_bed()
    {

    }
    Sofa_bed(string sitting,string sleep,string color):Sofa(sitting),Bed(sleep),color(color)
    {

    }
    void show()
    {
        Sofa::show();
        Bed::show();
        cout << color << endl;
    }
};
int main()
{
    Sofa_bed s("坐着","躺着","红色");
    s.show();
    return 0;
}

你可能感兴趣的:(c++,开发语言)