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;
}
相关推荐
wuminyu6 小时前
Kafka中sendfile与mmap实现机制解析
java·linux·c语言·jvm·c++
无小道11 小时前
C++——列表初始化
c++·列表初始化
blueSatchel12 小时前
c++action 编写(ros-humble)
c++·ros2
老赵的博客13 小时前
c++面试之从虚函数表到Rtti一次性讲清楚
c++·qt
傲世仙尊15 小时前
System V 进程间通信详解:共享内存、消息队列与信号量(CSDN博客)
linux·开发语言·c++
cvby15 小时前
C++11
开发语言·c++
6Hzlia15 小时前
【Classic 150 刷题计划】 LeetCode 26. 删除有序数组中的重复项 | C++ 快慢双指针经典模板
c++·算法·leetcode
夜不会漫长16 小时前
C++:类和对象(2)
java·javascript·c++
无小道16 小时前
C++ 中 `explicit` 关键字详解:彻底理解隐式类型转换
c++·explicit
蒸蒸yyyyzwd16 小时前
cpp 选手秋招学习笔记 day34
c++·八股