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;
}
相关推荐
h_a_o777oah11 分钟前
【算法专项】扩展域并查集:原理详解及解决大部分种类并查集问题(洛谷P5937 P2024 C++代码)
数据结构·c++·算法·acm·并查集·扩展域·逻辑建模
雾沉川1 小时前
Visual C++ 运行库合集 v105.0 部署与故障排查技术指南
开发语言·c++·dll
丘山望岳2 小时前
剑起霜华——平衡二叉树(AVL树 )精讲
开发语言·数据结构·c++
Boom_Shu2 小时前
浅拷贝与深拷贝
开发语言·c++·算法
Mortalbreeze2 小时前
C++ Lambda表达式详解:从捕获列表到底层原理
开发语言·c++
为何创造硅基生物2 小时前
LVGL
c++·ui
只做人间不老仙2 小时前
C++ grpc 拦截器示例学习
开发语言·c++·学习
qeen872 小时前
【C++】类与对象之零散知识点补充(四)
c++·笔记·学习·语法
Irissgwe3 小时前
顺序表和链表
数据结构·c++·链表·c·顺序表·线性表
牛油果子哥q3 小时前
二叉树(Binary Tree)零基础精讲,树基础概念、树形分类、核心性质、递归/层序遍历、完整代码与面试考点全解
c++·面试·数据挖掘