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;
}
相关推荐
浅念-2 分钟前
C++ 继承
开发语言·c++·经验分享·笔记·学习·算法·继承
王老师青少年编程20 分钟前
csp信奥赛C++之反素数
数据结构·c++·数学·算法·csp·信奥赛·反素数
YxVoyager2 小时前
基于 X-Macro 宏的手动 RTTI 实现模式
c++
wanderist.2 小时前
算法模板-线段树
c++·算法
lcj25112 小时前
蓝桥杯C++梳理(1):从入门到数组
c++·算法
wanderist.2 小时前
算法模板-01trie数
c++·算法
PingdiGuo_guo2 小时前
C++指针(一)
开发语言·c++
天若有情6733 小时前
IoC不止Spring!求同vs存异,两种反向IoC的核心逻辑
java·c++·后端·算法·spring·架构·ioc
tankeven3 小时前
HJ103 Redraiment的走法
c++·算法
瓦特what?3 小时前
平 滑 排 序
c++·算法·排序算法