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;
}
相关推荐
·present·5 小时前
CSAPP(lecture 4_01)
c语言·c++
FPGA小迷弟6 小时前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
c++·python·ai·plotly·django·ai编程·claude
程序员-King.6 小时前
【ROS1】Noetic 开发工作流程与常用命令
c++·ubuntu·ros
云深麋鹿6 小时前
C++ | 基于红黑树实现mymap与myset
开发语言·c++
傲世仙尊8 小时前
string增删查改-insert-erase-replace与find加substr组合技
c++
·present·9 小时前
CSAPP(lecture 3)
c++
别动我齐刘海10 小时前
机器人 C++ / 系统联调补强2——异常处理、Protobuf
linux·c++·人工智能·学习·算法·机器学习·机器人
basketball61610 小时前
C++ 中字符串与常见类型的转换总结
开发语言·c++
等我调个Bug10 小时前
C++智能指针通俗讲解
开发语言·c++
kyle~12 小时前
时间同步 --- PTP 与 Scheduled Action Command
c++·数码相机·机器人·传感器