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;
}
相关推荐
WL学习笔记1 小时前
模板初阶(C++)
开发语言·c++·后端·模板初阶
埃伊蟹黄面1 小时前
面试常问题目 —— STL
c++·面试·职场和发展·stl
CHANG_THE_WORLD1 小时前
ida-multi-mcp-跨版本逆向实战博客
c++
青瓦梦滋1 小时前
【在线五子棋对战】游戏匹配模块
网络·c++·网络协议·http·https
David猪大卫2 小时前
【C++修炼】STL容器—模板进阶:非类型模板参数、模板特化、模板分离编译
c语言·开发语言·c++·经验分享·笔记·学习·面试
纪念 2292 小时前
C++ vector(一)
开发语言·c++
垆边人似月.3 小时前
最少的元素个数使和为 target
数据结构·c++·算法
Zip-List3 小时前
工作小记-pytorch的算子优化: 转gpu核函数 python调c
c语言·c++·pytorch·python·cuda
暖焰核心3 小时前
多态全解——虚函数、重写、虚表与多态原理
c++
白杨尚青4 小时前
C++入门篇(十八):模板进阶——非类型参数、特化全家桶与分离编译(收官篇)
开发语言·c++·笔记·模板·偏特化·分离编译