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;
}
相关推荐
thisiszdy14 分钟前
<C++> 智能指针
开发语言·c++
玖玥拾26 分钟前
C/C++ 基础笔记(五)
c语言·c++·指针
Flash.kkl37 分钟前
C++基于websocketpp的多用户网页五子棋项目
开发语言·网络·数据库·c++·websocket·mysql
QT-Neal1 小时前
C/C++ 程序段的概念与分类
c语言·c++
枕星而眠1 小时前
【数据结构】树与二叉树基础知识点总结
数据结构·c++·后端·算法·运维开发
不会C语言的男孩1 小时前
C++ Primer 第16章:模板与泛型编程
开发语言·c++
QT-Neal2 小时前
C++智能指针使用详解
开发语言·c++
luj_17682 小时前
硝酸核关联假说缺乏实验证据
c语言·开发语言·c++·经验分享·算法
草莓熊Lotso2 小时前
【Linux网络】深入理解 HTTP 协议(三):静态资源服务、状态码与重定向实战
linux·运维·服务器·网络·c++·http
壹号用户2 小时前
缺省参数和函数重载
c++·学习