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;
}
相关推荐
jimy120 分钟前
C++ 虚函数表:基类和派生类共用一张 vtable 吗?
开发语言·c++
爱吃提升29 分钟前
Dev-C++ 5.11 C++断点调试完整教程
开发语言·c++
xlq223221 小时前
全面复习7
c++
geats人山人海2 小时前
现代c++2.4 虚继承
java·开发语言·c++
csuzhucong2 小时前
天元一号、二号、三号
c++
灯澜忆梦2 小时前
【面向对象编程c++】| 数组与函数
java·数据结构·c++
起个名字费劲死了3 小时前
VisionMaster 十二点标定+单点抓取
c++·visionmaster
Lzg_na5 小时前
僵尸进程、孤儿进程、守护进程:含义、区别与生命周期详解
c++
zhanghaha13145 小时前
C++ 的类是什么(新手保姆讲解,配合 Qt 对照理解)
c++
aqiu1111115 小时前
【C++算法打怪专栏】LeetCode 402. 移掉 K 位数字(单调栈 + 贪心)
c++·算法·leetcode