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;
}
相关推荐
txinyu的博客30 分钟前
解析muduo源码之 Buffer.h & Buffer.cc
c++
阿猿收手吧!1 小时前
【C++】异常处理:catch块执行后程序如何继续
服务器·网络·c++
代码游侠1 小时前
C语言核心概念复习(一)
c语言·开发语言·c++·笔记·学习
Once_day1 小时前
C++之《Effective C++》读书总结(3)
c语言·c++
蜕变的土豆1 小时前
grpc-通关速成
开发语言·c++
今儿敲了吗1 小时前
10| 扫雷
c++·笔记·学习
代码游侠2 小时前
学习笔记——Linux内核与嵌入式开发3
开发语言·arm开发·c++·学习
怎么没有名字注册了啊2 小时前
C++ 进制转换
开发语言·c++
金枪不摆鳍2 小时前
C++常用关键字考察
c++
茉莉玫瑰花茶3 小时前
C++ 17 详细特性解析(4)
开发语言·c++·算法