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;
}
相关推荐
2601_961845155 小时前
2026四级作文预测题|英语四级写作押题+提纲PDF
java·c语言·数据库·c++·python·pdf·php
郝亚军5 小时前
Visual Studio 2022项目中的.sln是什么?
c++·c#·visual studio
暖阳华笺5 小时前
【高频考点】K-Means聚类算法
c++·算法·机器学习·kmeans·聚类
j7~6 小时前
【C++】模板初阶--函数模板,类模板详解
数据结构·c++·算法·函数模板·类模板·函数模板实例化
吴梓穆6 小时前
UE5 C++ 注册 开始重叠和结束重叠事件
开发语言·c++·ue5
CodeSheep程序羊6 小时前
宇树科技,即将上市!
java·c语言·c++·人工智能·python·科技·硬件工程
雪落漂泊6 小时前
C++ 继承与多态(下)
开发语言·c++
charlie1145141916 小时前
通用GUI编程技术——图形渲染实战(四十九)——完全自绘控件架构:状态机与动画
c++·windows·架构·图形渲染
BAGAE6 小时前
FEC-RS前向纠错编码理论及工程实施研究
c语言·c++·qt·算法·决策树·链表
阿旭超级学得完6 小时前
Linux基础指令 四(apt,vim,git,cgdb)
linux·服务器·开发语言·数据结构·c++·git·vim