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;
}
相关推荐
Augustzero13 小时前
为什么线程不能说睡就睡?看懂等待与唤醒机制
c++·后端
程序员与背包客_CoderZ13 小时前
Linux D-Bus通信协议详解:从入门到C/C++编码实战
linux·服务器·c语言·c++·嵌入式硬件·嵌入式软件·dbus
冻柠檬飞冰走茶13 小时前
PTA基础编程题目集 7-35有理数均值(C++语言实现)
开发语言·数据结构·c++·算法·均值算法
wangchen_013 小时前
C++正则表达式
开发语言·c++·正则表达式
码匠许师傅16 小时前
【C++ 面试真题】聊聊 C++ 中的 lambda 表达式
java·c++·面试
依然鸣16 小时前
PTA团体程序设计天梯赛L1真题讲解L1-085-088
数据结构·c++·经验分享·算法·深度优先·pat考试
沙盘客16 小时前
AFSIM 14篇 C++ 插件开发:扩展你的仿真能力
c++·后端
NeilYuen16 小时前
【vemory】高性能KV存储AOF方案设计
linux·c++·redis·缓存
王老师青少年编程18 小时前
2021年CSP-J初赛真题及答案解析(完善程序2)
c++·真题·csp-j·答案·csp·初赛·信奥赛
有点。18 小时前
C++二叉树(一)
开发语言·数据结构·c++