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;
}
相关推荐
秋田君1 分钟前
2026 前端新出路:掌握 C++ 核心语法,无缝衔接 QT 桌面开发
前端·c++·qt
handler016 分钟前
【C++11 】Lambda 表达式、std::function 与 std::bind 解析
c++·c·c++11·bind·解耦·function·lamda
字节高级特工34 分钟前
C++11(二) 革新:引用折叠与lambda表达式
java·开发语言·c++·算法
白驹笙鸣1 小时前
STL allocator作用
开发语言·c++
小小编程路1 小时前
C++ STL 原理与性能
开发语言·c++
小欣加油1 小时前
leetcode239 滑动窗口最大值
数据结构·c++·算法·leetcode·哈希算法
玖釉-1 小时前
Vulkan 示例解析:pipelines.cpp 如何在一个 Render Pass 中切换多条 Graphics Pipeline
c++·windows·算法·图形渲染
随意起个昵称1 小时前
线性dp-计数类题目11(不等数列)
c++·算法·动态规划
并不喜欢吃鱼1 小时前
一.C++11:统一列表初始化 + std::initializer_list 超详细精讲
开发语言·c++
CHHH_HHH2 小时前
【C++】二叉搜索树全面升级,深度剖析AVL树
开发语言·数据结构·c++·算法·stl