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;
}
相关推荐
XH华1 小时前
C++语言第二章类和对象(下)
开发语言·c++
从零开始的代码生活_1 小时前
C++ stack、queue 与 priority_queue:容器适配器原理与实战
开发语言·c++·后端·学习·算法
AA陈超3 小时前
003 XiYou 西游 — P0 阶段实施计划
c++·笔记·学习·ue5
黑不溜秋的3 小时前
C++ STL 容器使用的底层数据结构
c++
灵晔君3 小时前
【C++】标准模板库STL——set /multiset/map /multimap
开发语言·c++
noipp4 小时前
推荐题目:洛谷 P13554 【MX-X15-T1】奶龙龙
c语言·数据结构·c++·算法·编程·洛谷
库玛西5 小时前
深入剖析 Linux 线程机制与分页式存储管理
linux·服务器·c++·笔记
众少成多积小致巨5 小时前
Android C++ 编码规范指南
android·c++·google
Yyyyyy~6 小时前
【C++】字符串
c++
wWYy.6 小时前
Pimpl模式
c++