码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 华清 c++ day5 9月12


    1. #ifndef _HOMEWORK_H_
    2. #define _HOMEWORK_H_
    3. #include
    4. #include
    5. using namespace std;
    6. //定义一个图形类
    7. class Shap
    8. {
    9. protected:
    10. //周长
    11. double perimeter;
    12. //面积
    13. double area;
    14. public:
    15. //无参构造
    16. Shap();
    17. //析构函数
    18. ~Shap();
    19. };
    20. //圆类
    21. class Circle :public Shap
    22. {
    23. private:
    24. double radius;
    25. public:
    26. //无参构造
    27. Circle();
    28. //有参构造
    29. Circle(double r);
    30. //拷贝构造
    31. Circle(const Circle& other);
    32. //获取周长
    33. double getPerimeter()const;
    34. //获取面积
    35. double getArea()const;
    36. };
    37. //矩形类
    38. class Rect :public Shap
    39. {
    40. private:
    41. double width;
    42. double length;
    43. public:
    44. //无参构造
    45. Rect();
    46. //有参构造
    47. Rect(double l, double w);
    48. //拷贝构造
    49. Rect(const Rect& other);
    50. //获取周长
    51. double getPerimeter()const;
    52. //获取面积
    53. double getArea()const;
    54. };
    55. #endif // !_HOMEWORK_H_
    1. #include "homework.h"
    2. Shap::Shap():perimeter(0),area(0)
    3. {
    4. cout << "Shap::无参构造" << endl;
    5. }
    6. Shap::~Shap()
    7. {
    8. cout << "Shap::析构函数" << endl;
    9. }
    10. Circle::Circle():radius(0)
    11. {
    12. cout << "Cricle::无参构造" << endl;
    13. }
    14. Circle::Circle(double r):radius(r)
    15. {
    16. cout << "Circle::有参构造" << endl;
    17. perimeter = 2 * 3.1415926 * radius;
    18. area = 3.1415926 * radius * radius;
    19. }
    20. Circle::Circle(const Circle& other):radius(other.radius)
    21. {
    22. cout << "Circle::拷贝构造函数" << endl;
    23. perimeter = 2 * 3.1415926 * radius;
    24. area = 3.1415926 * radius * radius;
    25. }
    26. double Circle::getPerimeter() const
    27. {
    28. return perimeter;
    29. }
    30. double Circle::getArea() const
    31. {
    32. return area;
    33. }
    34. Rect::Rect():width(0),length(0)
    35. {
    36. cout << "Rect::无参构造" << endl;
    37. }
    38. Rect::Rect(double l, double w):length(l),width(w)
    39. {
    40. cout << "Rect::有参构造" << endl;
    41. perimeter = 2 * (length + width);
    42. area = length * width;
    43. }
    44. Rect::Rect(const Rect& other):width(other.width),length(other.length)
    45. {
    46. cout << "Rect::拷贝构造函数" << endl;
    47. perimeter = 2 * (length + width);
    48. area = length * width;
    49. }
    50. double Rect::getPerimeter() const
    51. {
    52. return perimeter;
    53. }
    54. double Rect::getArea() const
    55. {
    56. return area;
    57. }
    1. #include "homework.h"
    2. int main()
    3. {
    4. Circle c1(5);
    5. cout << "c1: Perimeter = " << c1.getPerimeter() << ", Area = " << c1.getArea() << endl;
    6. Rect r1(4, 6);
    7. cout << "r1: Perimeter = " << r1.getPerimeter() << ", Area = " << r1.getArea() << endl;
    8. Circle c2(c1);
    9. cout << "c2: Perimeter = " << c2.getPerimeter() << ", Area = " << c2.getArea() << endl;
    10. Rect r2(r1);
    11. cout << "r2: Perimeter = " << r2.getPerimeter() << ", Area = " << r2.getArea() << endl;
    12. return 0;
    13. }

    面试题 - GitMind

    C++ - day4 - GitMind

    在线思维导图 - GitMind

  • 相关阅读:
    字节一面,面试官问我Vue3源码,我说……
    计算机毕业设计ssm+vue基本微信小程序的奶茶点单系统
    老板让我牵头搞ELK,我该如何确定ES的集群规模?
    【C++】STL容器适配器——queue类的使用指南(含代码使用)(18)
    MyBatis源码学习
    SpringBoot定时任务(一看就会)
    基于 docker 搭建 grafana+prometheus 监控资源之mysql+docker+alertmanager配置(二)(超详细版)
    python type hint
    [附源码]计算机毕业设计JAVAJAVA大方汽车租赁管理系统
    C++ 单例模式的各种坑及最佳实践
  • 原文地址:https://blog.csdn.net/Huxiao1220/article/details/132840547
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号