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;
}
相关推荐
jinyishu_9 小时前
模拟实现 C++ 栈和队列——从适配器模式看懂 STL 容器之美
java·c++·适配器模式
hehelm9 小时前
AI大模型接入SDK—通用模块设计
linux·开发语言·c++
hold?fish:palm12 小时前
RDB全量快照备份
c++·redis·后端
盐焗鹌鹑蛋13 小时前
【C++】C++11:列表初始化、声明、STL升级
c++
ComputerInBook15 小时前
c 和 c++ 中的宏块(macro)
c语言·c++··宏块·宏指令
AA陈超15 小时前
004 T02 - 俯视角摄像机系统 设计文档
网络·c++·ue5·虚幻引擎
bu_shuo15 小时前
c与cpp中的argc和argv
c语言·c++·算法
蓝创精英团队15 小时前
VCPKG 跨平台C++ 库管理器
c++·vcpkg
Jayden_Ruan17 小时前
C++组合的输出
c++·算法·深度优先
froyoisle18 小时前
CSP 真题解析:[CSP-J 2020-T3] 表达式
c++·算法·csp·信息学·信奥赛