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;
}
相关推荐
Tri_Function9 小时前
动态规划DP1(c++)
c++
清水迎朝阳12 小时前
客户端软件 — 用户统计方案
服务器·c++·客户端·用户统计
再卷也是菜13 小时前
C++17(下)
c++
alexwang21114 小时前
HDU 4348 详细题解
c++·算法·题解·hdu·主席树·可持久化数据结构·可持久化线段树
程序员zgh14 小时前
C++ 拷贝赋值运算符 详解
c语言·开发语言·c++
皓月斯语15 小时前
B2132 素数对
c++·算法·题解
星轨初途16 小时前
LeetCode 热题 100——day2 字母异位词分组
c++·算法·leetcode
笨鸟先飞的橘猫17 小时前
c++面向对象编程
开发语言·c++
啦啦啦啦啦zzzz17 小时前
设计模式:桥接模式和组合模式
c++·设计模式·组合模式·桥接模式
-森屿安年-17 小时前
647. 回文子串
c++·算法·动态规划