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;
}
相关推荐
从零开始的代码生活_5 小时前
C++ 内存管理:从内存分区到 new/delete 底层原理
开发语言·c++·后端
aaPIXa6226 小时前
C++ 用 13 条规则让模型写出安全现代 C++
java·c++·安全
枕星而眠7 小时前
【数据结构】红黑树入门指南
运维·数据结构·c++·后端
2601_949817727 小时前
C++指针与引用深度精讲:底层原理、差异对比与高阶实战陷阱
java·jvm·c++
烟锁池塘柳09 小时前
【C/C++】解决C++控制台输出中文乱码问题
c语言·开发语言·c++
zh路西法9 小时前
【10天速通Navigation2】(九):LQR最优控制器的原理推导与Nav2插件实现
c++·ros2·最优控制·lqr·navigation2
粘稠的浆糊9 小时前
[AtCoder - abc465_d ]X to Y题解
数据结构·c++·算法
誰能久伴不乏9 小时前
C++11 随机数生成——告别 rand()
开发语言·c++
KouFiee10 小时前
同名隐藏基础
开发语言·c++
从零开始的代码生活_10 小时前
C++ string 详解:常用接口、字符串算法与深拷贝实现
开发语言·c++·后端·学习·算法