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;
}
相关推荐
zh路西法20 分钟前
【Navigation2进阶】(十二):自主探索性能优化与 RIG 算法推导与 Nav2 插件实现
c++·dijkstra·ros2·rrt·navigation2·前沿探索
星恒随风28 分钟前
C++ STL 详解:set 与 multiset 的使用、区间查询和算法应用
开发语言·c++·笔记·学习·算法
再卷也是菜37 分钟前
C++11支持并发库
开发语言·c++
六月的翅膀1 小时前
OCR:RapidOCR C++/C#
c++·ocr
颜x小1 小时前
[C#]——接口与继承
开发语言·c++·c#
小肝一下2 小时前
多态(上)
android·开发语言·c++·vscode·多态·面向对象·伊蕾娜
无敌秋2 小时前
python/c++/java上云
java·c++·python
code_pgf12 小时前
C++11 / C++14 / C++17 / C++20 新特性总结
c++·c++20
颜x小16 小时前
[C#] C++与c#语法对比
开发语言·c++·c#
汉克老师17 小时前
GESP2026年3月认证C++八级( 第三部分编程题(2、子图最短路)精讲
c++·最短路·floyd·gesp8级