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;
}
相关推荐
问君能有几多愁~3 分钟前
C++ 日志实现
java·前端·c++
JANGHIGH33 分钟前
c++ 多线程(二)
开发语言·c++
珑墨1 小时前
【浏览器】页面加载原理详解
前端·javascript·c++·node.js·edge浏览器
a伊雪2 小时前
c++ 引用参数
c++·算法
应茶茶3 小时前
从 C 到 C++:详解不定参数的两种实现方式(va_args 与参数包)
c语言·开发语言·c++
code bean3 小时前
【C++】Scoop 包管理器与 MinGW 工具链详解
开发语言·c++
hetao17338374 小时前
2025-12-11 hetao1733837的刷题笔记
c++·笔记·算法
saltymilk5 小时前
C++ 语言特性的变更可能让你的防御成为马奇诺防线
c++
Smile丶凉轩5 小时前
C++ 高性能内存池面试题总结
开发语言·c++
汉克老师6 小时前
CCF-NOI2025第二试题目与解析(第二题、集合(set))
c++·算法·noi·子集卷积·sos dp·mod 异常