12.4作业

#include <iostream>
 
using namespace std;
 
 
//封装 沙发 类
class Sofa
{
private:
    string sitting;
    int *price;
public:
    //无参
    Sofa(){cout << "Sofa::无参构造函数" << endl;}
    //有参
    Sofa(string s,int price):sitting(s),price(new int (price))
    {
       cout << "Sofa::有参构造函数" << endl;
    }
    //拷贝构造函数
    Sofa(const Sofa &other):sitting(other.sitting),price(new int (*other.price))
    {
        cout <<"Sofa::拷贝构造函数" << endl;
    }
    //拷贝赋值函数
    Sofa &operator=(const Sofa &O1)
    {
        if(this!=&O1)
        {
            sitting=O1.sitting;
            price=O1.price;
 
        }
        cout <<"Sofa::拷贝赋值函数" << endl;
        return *this;
    }
    ~Sofa()
    {
        cout << "Sofa::析构函数" << endl;
 
        delete price;
        price=nullptr;
    }
     void show()
     {
              cout << sitting << " "<<price<<" "<< endl;
          }
     };
 
 
     //封装 床 类
     class Bed
     {
     private:
         string sleep;
         int *size;
     public:
         Bed(){cout << "Bed::无参构造函数" << endl;}
         Bed(string s,int size):sleep(s),size(new int (size))
         {
             cout << "Bed::有参构造函数" << endl;
         }
         //拷贝构造
         Bed (const Bed &other):sleep(other.sleep),size(new int(*other.size))
         {
             cout << "Bed::拷贝构造函数" << endl;
         }
         //拷贝赋值函数
         Bed &operator=(const Bed &o)
         {
           if(this != &o)
             {
                 sleep=o.sleep;
                 size=o.size;
 
 
             }
           cout <<" Bed::拷贝赋值函数 "<<endl;
            return *this;
         }
         ~Bed()
         {
             cout << "Bed::析构函数" << endl;
             delete size;
             size=nullptr;
         }
 
         void show()
         {
             cout << sleep <<" "<<size<<endl;
         }
     };
 
 
     //封装 沙发床 类  共有继承于沙发和床
     class Sofa_bed:public Sofa,public Bed
     {
     private:
         string color;
         int *soft;
     public:
         Sofa_bed(){cout << "Sofa_bed::无参构造函数" << endl;}
         Sofa_bed(string s,int p, string sl,int si, string c,int soft):Sofa(s,p),Bed(sl,si),color(c),soft(new int (soft))
         {
             cout << "Sofa_bed::有参构造函数" << endl;
         }
         //拷贝构造函数
         Sofa_bed(const Sofa_bed&other):Sofa(other),Bed(other),color(other.color),soft(new int(*(other.soft)))
         {
             cout << "Sofa_bed::拷贝构造函数"<< endl;
         }
         //拷贝赋值函数
         Sofa_bed &operator=(const Sofa_bed &o)
         {
             if(this!=&o)
             {
                 color=o.color;
                 soft=o.soft;
                 Bed::operator=(o);
                 Sofa::operator=(o);
 
             }
 
             cout<< "Sofa_bed::拷贝赋值函数"<< endl;
             return *this;
         }
         ~Sofa_bed()
         {
             cout << "Sofa_bed::析构函数" << endl;
 
         }
         void show()
         {
             cout << color << " " <<soft <<" ";
             Bed::show();
             Sofa::show();
         }
 
     };
 
 
 
int main()
{
    Sofa_bed b("可睡",10000,"可躺",2000,"pink",9);
 
    b.show();
    return 0;
}
 

  • 30
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Xcode 12.4是一款由Apple开发的集成开发环境(IDE),用于在Mac OS X操作系统上进行软件开发。它包含了iOS 14.4、iPadOS 14.4、tvOS 14.4、watchOS 7.2以及macOS Big Sur 11.1的SDK。Xcode 12.4支持iOS 9及以上版本、tvOS 9及以上版本、watchOS 2及以上版本,并需要在安装有macOS 10.15.4及以上版本的电脑上使用。 如果您的电脑是运行在Catalina 10.15.7上的,而App Store显示由于版本过低无法安装Xcode,您可以尝试从第三方网站下载Xcode 12.4的应用程序。一个相对安全的下载地址是https://cloud.mfpud.com/Application/Xcode/,您可以下载Xcode_12.4.xip文件并解压缩后安装。然后,您还需要下载Xcode 12.4的真机配置包,将其拖到已解压的Xcode 12.4应用程序中的指定位置。 请注意,从非官方和未经验证的第三方网站下载Xcode应用程序可能存在安全风险,因此建议您谨慎操作。 希望这些信息对您有所帮助。如果您还有其他问题,请随时提问。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [2021-07-09](https://blog.csdn.net/bjnbt/article/details/118610239)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Xcode12.4发布说明(翻译)](https://blog.csdn.net/guoyongming925/article/details/113865330)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值