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;
}
相关推荐
欧特克_Glodon1 小时前
OpenCV计算机视觉开发入门与实践<二十七>:图像分割概述
c++·人工智能·opencv·计算机视觉
蒸蒸yyyyzwd1 小时前
cpp 选手秋招学习笔记 day21
c++·面试·八股
「QT(C++)开发工程师」12 小时前
C++ auto 用法详解
开发语言·c++
OPEN-F12 小时前
C++STL教程:容器适配器与实用工具
开发语言·c++
OPEN-F13 小时前
C++模板教程:变参模板、折叠表达式与SFINAE
java·开发语言·c++
有点。13 小时前
C++二叉搜索树进阶
开发语言·c++
HugoStudio_SWAN13 小时前
【擦除重绘】C++ 控制台动画:弹跳 Logo DVD 屏保效果
开发语言·c++·学习·程序人生
kyle~15 小时前
C++_STL---迭代器失效
开发语言·c++
wuminyu16 小时前
深入剖析 Panama Off-heap 的性能损耗与开销
java·linux·c语言·jvm·c++
rhythm-ring16 小时前
宏定义续行符 \ 的使用与踩坑
c语言·c++