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;
}
相关推荐
纪念 2291 小时前
C++ 算法模板与错题 (差分)
开发语言·c++·算法
li星野1 小时前
C++/Qt 开发避坑与重构原则清单 (速记版)
c++·qt·重构
西西弗Sisyphus1 小时前
C++ 最小 Agentic Loop 实现 - 回调函数系列 - 函数指针详解(3)
c++
杜 硕2 小时前
从零开始的C++生活——第十六讲
开发语言·数据结构·c++·生活
沫璃染墨2 小时前
《Qt从零入门系列(十七):网络编程基础详解——从Socket原理到TCP/UDP通信API》
开发语言·网络·c++·qt·http·qt5·qt6.3
金榜题名萱2 小时前
蓝桥杯|石子合并(区间动态规划)
c语言·数据结构·c++·算法·蓝桥杯·动态规划
ShineWinsu2 小时前
对于Qt:绘图的解析
开发语言·数据库·c++·qt·面试·客户端·绘图
纪念 2292 小时前
C++ 算法模板与错题 (前缀和)
开发语言·c++·算法
潇湘散客3 小时前
PlantAis插件更新:RVM负实体开关;VUE文件读取与导出等
c++·qt·opengl
金榜题名萱3 小时前
蓝桥杯 - 旗帜
c语言·数据结构·c++·算法·蓝桥杯