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;
}
相关推荐
tankeven4 小时前
C++ 智能指针
c++
handler016 小时前
【算法模板】最小生成树:稠密图选 Prim,稀疏图选 Kruskal
c语言·数据结构·c++·算法
许长安6 小时前
RPC 异步调用基本使用方法:基于官方helloworld-async 示例
c++·经验分享·笔记·rpc
sparEE7 小时前
c++面向对象:对象的赋值
开发语言·c++
此生决int7 小时前
快速复习之数据结构篇——栈和队列
数据结构·c++
H_BB7 小时前
第17届蓝桥杯备战历程
c++·算法·职场和发展·蓝桥杯
daad7777 小时前
记录一次上下文切换次数的统计
服务器·c++·算法
tankeven8 小时前
C++ Lambda 表达式
c++
fangzt20108 小时前
插件系统:让其他人也能给编辑器写节点
c++
诙_8 小时前
深入理解C++文件操作
开发语言·c++