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;
}
相关推荐
必须得开心呀24 分钟前
字节序大小端科普
c++·程序人生
会编程的小孩38 分钟前
C++ 子集
c++
SunkingYang1 小时前
C++20 vs C++17:新特性对比与用法指南
c++·c++20·特性·版本·新特性·对比·c++17
前进吧-程序员1 小时前
C++20 协程入门实战:从 co_await 到一个 100 行的异步任务调度器
网络·c++·c++20
前进吧-程序员1 小时前
实战:C++20 协程 + io_uring 写一个 400 行的 echo server
网络·c++·c++20
青少儿编程课堂6 小时前
蓝桥杯青少组 + 全国青少年信息素养大赛 + 电子学会图形化考级|校园推箱子大挑战解析
c++·python·算法·bfs·信息学竞赛
多弗朗皮卡丘6 小时前
C++STL之空间配置器
开发语言·c++·内存池·空间配置器
牵猫散步的鱼儿7 小时前
Demosaic 和 Remosaic
c++
CodeYp20197 小时前
第19讲:封装红黑树实现 mymap 和 myset
开发语言·c++·红黑树
孙鹏宇.7 小时前
C++类型转换
c++