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;
}
相关推荐
hold?fish:palm10 小时前
kv存储主从复制的设计与实现
c++·redis·后端
啦啦啦啦啦zzzz10 小时前
算法:贪心算法
c++·算法·leetcode·贪心算法
charlie11451419110 小时前
现代C++工程实践 WeakPtr 实战(三):WeakPtrFactory 与「最后成员」惯用法
开发语言·c++·开源项目·现代c++
JetComXCpp12 小时前
给 Win32 窗口加上毛玻璃效果——纯 D3D11 实现,零依赖
c++
ysa05103014 小时前
【板子】二分答案(最大最小?)
c++·笔记·算法·板子
是多巴胺不是尼古丁14 小时前
C++基础知识
开发语言·c++
stolentime15 小时前
SP8549 MAIN75 - BST again题解
c++·算法·二叉树·深度优先·图论·记忆化搜索·组合数学
ziguo112215 小时前
C/C++ 错误处理全解:从 errno 到 C++ 异常
linux·c语言·c++·windows·visual studio
stolentime15 小时前
AT_pakencamp_2020_day1_k Gcd of Sum题解
c++·算法
2601_9561219715 小时前
map_计蒜客T1271 完美K倍子数组
c++·算法