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;
}
相关推荐
王老师青少年编程13 小时前
2026年6月GESP真题及题解(C++二级):完全平方数计数
c++·题解·真题·gesp·二级·2026年6月·完全平方数计数
zwenqiyu13 小时前
非线性字符串数据结构串讲
数据结构·c++·学习·算法
努力中的编程者13 小时前
STL-vector的模拟实现
开发语言·c++·算法·stl·vector
没文化的阿浩14 小时前
【C++】详解继承机制
开发语言·c++
拳里剑气14 小时前
C++算法:队列与BFS
c++·算法·bfs·宽度优先·队列
aaPIXa62214 小时前
C++模板元编程:在编译期完成计算,实现零运行时开销
java·开发语言·c++
郝学胜-神的一滴15 小时前
CMake 038:OBJECT目标复用编译+Linux动态库版本自动化管理
linux·c++·程序人生·软件工程·软件构建·cmake·工程配置
Sylvia-girl15 小时前
第八站:vector及其常用操作【上】
c++
Sunsets_Red16 小时前
浅谈博弈论
c++·学习·编程·博弈论·信息学竞赛·巴巴博弈
ALex_zry16 小时前
C++26 std::inplace_vector 详解:零堆分配的定容向量
开发语言·c++