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;
}
相关推荐
小苗卷不动2 小时前
OJ练习之疯狂的自我检索者(简单)
c++
LUVK_2 小时前
第七章查找
数据结构·c++·考研·算法·408
迷途之人不知返2 小时前
vector
c++
khalil10203 小时前
代码随想录算法训练营Day-31贪心算法 | 56. 合并区间、738. 单调递增的数字、968. 监控二叉树
数据结构·c++·算法·leetcode·贪心算法·二叉树·递归
小苗卷不动3 小时前
进程与线程的核心区别
c++
啊我不会诶3 小时前
2024ICPC西安邀请赛补题
c++·算法
ZenosDoron3 小时前
keil软件修改字体,Asm editor,和C/C++ editor的区别
c语言·开发语言·c++
山栀shanzhi4 小时前
C/C++之:构造函数为什么不能设置为虚函数?
开发语言·c++·面试
谭欣辰4 小时前
C++ 版Dijkstra 算法详解
c++·算法·图论
qeen874 小时前
【算法笔记】双指针及其经典例题解析
c++·笔记·算法·双指针