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;
}
相关推荐
小小龙学IT4 分钟前
第一节 QML 背景介绍
c++·qt·js
水饺编程14 分钟前
第5章,[Win32 章节] :创建、选择和删除画笔
c语言·c++·windows·visual studio
wind1003217 分钟前
Outdated Visual C++ Redistributable 过时 VC++ 运行库报错修复
开发语言·c++
小小龙学IT28 分钟前
Abseil 开源 C++ 公共库深度解析:从 SwissTable 到 Status 的 Google 工程实践
c++·开源
兔兔兔兔141 分钟前
记录C++ 12
开发语言·c++
此陆昭昭1 小时前
qt,使用qml写一个简单的界面
c++·qt
沫璃染墨1 小时前
《从零入门Linux系统篇(二十九):文件篇·二——深入文件描述符:从文件描述符表到重定向,再到Shell实现》
linux·运维·服务器·c++·驱动开发·系统架构
码匠许师傅2 小时前
【C++ 面试真题】35. 聊聊 C++ 的万能引用(T&&)和完美转发(std::forward)
java·c++·面试
OPEN-F2 小时前
C++入门教程:数组、字符串与指针入门
数据结构·c++·算法
啦啦啦啦啦zzzz3 小时前
共享内存的网络聊天室
linux·服务器·网络·c++·网络编程