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;
}
相关推荐
一拳一个呆瓜3 小时前
【STL】iostream 编程:使用提取运算符
c++·stl
我不是懒洋洋4 小时前
从零实现一个分布式日志平台:ELK的核心设计
c++
神仙别闹4 小时前
基于QT(C++)实现Windows 自启动项查看和分析
c++·windows·qt
WWTYYDS_6665 小时前
ProtoBuf超详细使用教程
c++
野生风长5 小时前
c++类和对象(this指针,重载operator,习题总结)
java·开发语言·c++
雪的季节5 小时前
Python「假多态」与 C++「真多态」的核心区别
开发语言·c++
zmzb01036 小时前
C++课后习题训练记录Day166
开发语言·c++
皓月斯语6 小时前
程序设计语言的特点
开发语言·数据结构·c++
邪修king6 小时前
C++ 进阶终章:异常机制与智能指针全解 —— 从错误处理到 RAII 资源管理,打通现代 C++ 的核心命脉
android·数据结构·c++
梓䈑12 小时前
【算法题攻略】BFS 解决FloodFill 算法、最短路问题、多源BFS 和 拓扑排序
c++·算法·宽度优先