码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C++学习day5


    目录

    作业:

    1> 思维导图

    2> 多继承代码实现沙发床


    1>思维导图

    2> 多继承代码实现沙发床

    1. #include
    2. using namespace std;
    3. //创建沙发类
    4. class sofa
    5. {
    6. private:
    7. string sitting;
    8. public:
    9. sofa(){
    10. cout << "sofa的无参构造函数" << endl;
    11. }
    12. sofa(string s):sitting(s)
    13. {
    14. cout << "sofa的有参构造函数" << endl;
    15. }
    16. //拷贝构造函数
    17. sofa(const sofa &other):sitting(other.sitting)
    18. {
    19. cout << "sofa的拷贝构造函数" << endl;
    20. }
    21. //拷贝赋值函数
    22. sofa &operator=(const sofa &other)
    23. {
    24. cout << "sofa的拷贝赋值函数" << endl;
    25. sitting=other.sitting;
    26. return *this;
    27. }
    28. //析构函数
    29. ~sofa()
    30. {
    31. cout << "sofa的析构函数" << endl;
    32. }
    33. void show()
    34. {
    35. cout << "sofa" << endl;
    36. }
    37. };
    38. //创建床类
    39. class bed
    40. {
    41. protected:
    42. string sleeping;
    43. public:
    44. bed(){
    45. cout << "bed的无参构造函数" << endl;
    46. }
    47. bed(string b):sleeping(b)
    48. {
    49. cout << "bed的有参构造函数" << endl;
    50. }
    51. //拷贝构造函数
    52. bed(const bed &other):sleeping(other.sleeping)
    53. {
    54. cout << "bed的拷贝构造函数" << endl;
    55. }
    56. //拷贝赋值函数
    57. bed &operator=(const bed &other)
    58. {
    59. cout << "bed的拷贝赋值函数" << endl;
    60. sleeping=other.sleeping;
    61. return *this;
    62. }
    63. //析构函数
    64. ~bed()
    65. {
    66. cout << "bed的析构函数" << endl;
    67. }
    68. void show()
    69. {
    70. cout << "bed" << endl;
    71. }
    72. };
    73. //构造沙发床类
    74. class sofa_bed: public bed,public sofa
    75. {
    76. private:
    77. string color;
    78. public:
    79. sofa_bed(){
    80. cout << "sofa_bed的无参构造函数" << endl;
    81. }
    82. sofa_bed(string s,string b,string c):bed(b),sofa(s),color(c)
    83. {
    84. cout << "sofa_bed的有参构造函数" << endl;
    85. }
    86. //拷贝构造函数
    87. sofa_bed(const sofa_bed &other):bed(other.sleeping),sofa(other),color(other.color)
    88. {
    89. cout << "sofa_bed的拷贝构造函数" << endl;
    90. }
    91. //拷贝赋值函数
    92. sofa_bed &operator=(const sofa_bed &other)
    93. {
    94. cout << "sofa_bed的拷贝赋值函数" << endl;
    95. color=other.color;
    96. sofa::operator=(other);
    97. sleeping=other.sleeping;
    98. return *this;
    99. }
    100. //析构函数
    101. ~sofa_bed()
    102. {
    103. cout << "sofa_bed的析构函数" << endl;
    104. }
    105. void show()
    106. {
    107. cout << "sofa_bed的show" << endl;
    108. }
    109. };
    110. int main()
    111. {
    112. cout << "Hello World!" << endl;
    113. sofa_bed s1;
    114. sofa_bed s2("坐着","睡觉","yellow");
    115. s2.show();
    116. sofa_bed s3(s2);
    117. s1=s2;
    118. return 0;
    119. }

    效果图 :

     

     

  • 相关阅读:
    vue全家桶是指什么?有哪些东西?
    【力扣刷题】重新格式化电话号码
    阿里云无影云电脑、VDI以及传统PC电脑有什么区别?
    python+django高校教师科研成果管理系统pycharm源码lw
    文件搜索工具测试
    聊聊 C# 中的 Composite 模式
    Centos7.4重启提示gurb2/i386-pc/normal.mod not found
    【Hadoop】学习笔记(三)
    深入理解正则表达式:高效处理文本数据的利器
    CentOS 7操作系统使用LAMP架构安装Zabbix 5.0监控系统的详细指南
  • 原文地址:https://blog.csdn.net/m0_69894626/article/details/133776913
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号