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;
}
相关推荐
汉克老师42 分钟前
GESP2026年3月认证C++六级真题与解析(编程题1 选数)
c++·动态规划·线性dp·gesp六级·状态转移·选与不选
有点。1 小时前
C++倍增法(练习题)
c++·算法
凡人叶枫1 小时前
Effective C++ 条款23:宁以 non-member、non-friend 替换 member 函数
linux·开发语言·c++·嵌入式开发
C语言小火车1 小时前
什么时候用智能指针?什么时候用裸指针?
c语言·c++·学习·指针
玖玥拾2 小时前
C/C++ 基础笔记(十二)友元、运算符重载
c语言·c++·运算符重载·友元
智者知已应修善业2 小时前
【51单片机8位数码管同时倒计时从9999】2024-1-25
c++·经验分享·笔记·算法·51单片机
郝学胜_神的一滴3 小时前
Qt 高级开发 031:QListWidget图标布局实战
c++·qt
Coder-magician4 小时前
《代码随想录》刷题打卡day15:二叉树part05
数据结构·c++·算法
Irissgwe4 小时前
算法的时间复杂度和空间复杂度
数据结构·c++·算法·c·时间复杂度·空间复杂度
随意起个昵称4 小时前
区间dp-基础题目3(永别)
c++·算法