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;
}
相关推荐
郑同学的笔记22 分钟前
【c++随笔30】C++ 注册回调函数
开发语言·c++
lengxuenong1 小时前
树状数组 · 信息学学习手册2-离散化与逆序对
c++·学习·算法
十二1 小时前
【洛谷题解】P1115 最大子段和(前缀和 + 维护最小前缀)
数据结构·c++·算法·蓝桥杯
cu1433 小时前
细谈IT65631的具体功能与其应用
c++·单片机·嵌入式硬件
幻智星科技3 小时前
Karatsuba与CSD优化FPGA大数乘法
c++·fpga开发·密码学
flower9803233 小时前
C++消息总线软件开发框架AI重构版
c++·设计模式·架构
lengxuenong4 小时前
树状数组 · 信息学学习手册3-优化LIS
c++·学习·算法
fanfan_hongyun4 小时前
【UE5.1 创建C++文件】
c++·ue5
余额瞒着我当琳4 小时前
C++11,发展历史浅谈,初始化列表和对象初始化,右值引用和移动语义
java·开发语言·c++·算法
Tsuki_tl4 小时前
【优选算法:双指针】——复写零题解
java·c++·算法·leetcode·数组·双指针·复写零