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;
}
相关推荐
luj_17686 小时前
星火科技助力边远地区防病攻坚
c语言·开发语言·c++·经验分享·算法
zmzb01037 小时前
C++课后习题训练记录Day175
开发语言·c++
啦啦啦啦啦zzzz7 小时前
工具:动态类工厂和用配置文件存储属性
c++·设计模式·工具·动态工厂
脱胎换骨-军哥7 小时前
C++ 代码规范与格式化指南
开发语言·c++·代码规范
迷途之人不知返9 小时前
lambda表达式
c++
@三十一Y9 小时前
C++:红黑树的实现
开发语言·c++
_wyt00110 小时前
拓扑排序:有向无环图的排队艺术
c++·拓扑排序·队列
皓月斯语10 小时前
B2118 验证子串
c++·题解
乐观勇敢坚强的老彭10 小时前
C++信奥:开关门、开关灯问题
开发语言·c++·算法
2301_7779983411 小时前
C/C++:预处理详解
c语言·c++