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;
}
相关推荐
会周易的程序员14 小时前
microLog 后端开发指南
开发语言·c++·物联网·设计模式·日志·iot·aiot
汉克老师14 小时前
GESP2026年6月认证C++二级( 第三部分编程题(2、菱形))精讲
c++·找规律·绘制图形·对角线·双重循环
☆cwlulu14 小时前
try-throw-catch异常捕获流程
开发语言·c++
王老师青少年编程15 小时前
2026年6月GESP真题及题解(C++五级):排排坐
c++·题解·真题·gesp·五级·2026年6月·排排坐
郝学胜-神的一滴15 小时前
Qt 高级编程 034:深耕QWidget底层内核—彻底吃透无边框窗口设计核心原理
开发语言·c++·qt·程序人生·软件开发·用户界面
不会写代码的ys15 小时前
C++复习篇
java·开发语言·c++
aichitang202416 小时前
数论变换(NTT)
c++·算法·fft·ntt
_olone16 小时前
AtCoder Beginner Contest 465 D - X to Y
c++·算法
星夜夏空9916 小时前
C++学习(3) —— C++输入输出流
c++·学习
CAU界编程小白16 小时前
CAU抢课脚本
c++·脚本