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;
}
相关推荐
浆果02072 小时前
NanoTrack C++ — RK3588 实时目标跟踪
c++·目标跟踪·rk3588
ysa0510303 小时前
【并查集】判环
c++·笔记·算法
持力行3 小时前
C/C++ 中的 char*:它标识数组吗?为什么能用下标访问?
c语言·c++
汉克老师5 小时前
GESP2026年6月认证C++六级( 第三部分编程题(2、满二叉树))精讲
c++·深度优先·树形dp·满二叉树·gesp六级·树形dfs
踮起脚看烟花5 小时前
多人聊天室实现v2.0
c++·信息与通信
梦帮科技5 小时前
UE5 GAS 实战:用 Gameplay Ability System 搭建「赛博修真」境界与技能体系
c++·人工智能·python·ue5·c#
旖-旎5 小时前
QT系统篇(5)(下)
开发语言·c++·qt
99乘法口诀万物皆可变6 小时前
PcanToVectorXL_V01:打通 Vector 与 PCAN 的双向 CAN/CAN‑FD 桥梁
c++·学习
liulun6 小时前
C++ WinRT中的事件
开发语言·c++
whitelbwwww6 小时前
c++运行onnx模型
开发语言·c++