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;
}
相关推荐
en.en..22 分钟前
C语言核心解析:#define与typedef本质区别
开发语言·c++·算法
码匠许师傅33 分钟前
【设计模式精讲】26.策略模式(Strategy)
c++·设计模式·策略模式·uml
果果燕1 小时前
实习笔记(六)主机按钮状态上报完整流程
开发语言·c++·php
是个西兰花2 小时前
网络基础1
linux·网络·c++·智能路由器
老赵的博客2 小时前
c++QT之动态库加载常见报错
c++·qt
wabs6663 小时前
关于二叉树【429.N叉树的层序遍历的思考】
数据结构·c++·算法·leetcode·二叉树
hetao17338373 小时前
2026-09-08 hetao1733837 的刷题记录
c++·算法
码匠许师傅3 小时前
【设计模式精讲】25.状态模式(State)
c++·ui·设计模式·状态模式·uml
C++ 老炮儿的技术栈3 小时前
MFC CPtrArray的用法
开发语言·数据结构·c++·算法·mfc·c
佳児素花痴╮3 小时前
C++基础速通
开发语言·c++