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;
}
相关推荐
linx29511 分钟前
单元五 · 对称认知·下:编译与链接
linux·c语言·开发语言·c++·嵌入式硬件
C++ 老炮儿的技术栈40 分钟前
西门子 S7 常用存储区(I/Q/M/T/C/DB/PI/PQ)
linux·开发语言·c++·windows·qt·io
linx2952 小时前
单元七 · 零基础路线图-第 1–3 周·变量、类型与字符串
c语言·开发语言·数据结构·c++·算法
Benny_Tang2 小时前
P7514 [省选联考 2021 A/B 卷] 卡牌游戏 题解
c++·算法
程序猿编码2 小时前
LLM 技术迁移音频领域:基于 GGML 搭建 Roformer,端侧音乐人声分离实现详解
c++·llm·音视频·transformer·模型推理·ggml
wuminyu2 小时前
Kafka的写入延迟与磁盘IO抖动原理分析
java·linux·c语言·jvm·c++
buhuizhiyuci2 小时前
线程的互斥
linux·运维·服务器·c++
Benny_Tang2 小时前
「雅礼集训 2018 Day7」A 题解
数据结构·c++·算法
m0_734571762 小时前
深入理解C++ 构造函数<十一> initializer_list 构造
开发语言·c++
水饺编程3 小时前
第5章,[Win32 章节] :绘制平面直角坐标系
c语言·c++·windows·visual studio