C++ day2

1.xmind
2.

cpp 复制代码
#include <iostream>

using namespace std;

class Rect
{
private:
    int  width;
    int height;
public:
    void init(int width,int height );
    void set_width(int width);
    void set_height(int height);
    void show();
};
void Rect :: init (int width,int height)
{
    this->width=width;
    this->height=height;
}
void Rect :: set_width(int width)
{
    this->width=width;
}
void Rect :: set_height(int height)
{
    this->height=height;
}
void Rect :: show()
{
    cout << "周长: " << 2*height+2*width << "  面积: " << height*width << endl ;
}

int main()
{
    int width = 10;
    int height =10 ;
    Rect r1;
    r1.init(width,height);
    r1.show();

    cout << "please enter width : " ;
    cin >> width ;
    r1.set_width(width);
    cout << "please enter height : ";
    cin >> height;
    r1.set_height(height);
    r1.show();

    return 0;
}
相关推荐
代码中介商22 分钟前
C++ 智能指针完全指南(三):weak_ptr 与循环引用
开发语言·c++
BestOrNothing_201532 分钟前
ROS2 C++ 小车控制完整实战(二):自定义 msg 消息发布与订阅保姆级教程
c++·ros2·subscriber·publisher·msg·topic通信·自定义接口
-森屿安年-43 分钟前
91. 解码方法
c++·动态规划
有点。1 小时前
C++(二分答案)
c++
程序喵大人1 小时前
【C++并发系列】第一章:多线程读写同一个变量为什么会出错
开发语言·c++·多线程·并发
梓䈑1 小时前
C++ 接入 SQLite 数据库:环境搭建、API 详解 与 两种执行方式对比
数据库·c++·sqlite
zh路西法2 小时前
基于yaml-cpp的C++参数服务器设计2:多级参数配置
linux·服务器·c++
啦啦啦啦啦zzzz2 小时前
算法总结(双指针)
c++·算法·双指针
QiLinkOS3 小时前
极客与商业思维的融合实践(1)
c语言·数据库·c++·人工智能·算法·开源协议
坚果派·白晓明3 小时前
鸿蒙PC】libuv适配:AtomCode Skills一站式指南
c语言·c++·华为·ai编程·harmonyos·atomcode