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;
}
相关推荐
低频电磁之道1 分钟前
C++中类的this指针
开发语言·c++
水饺编程1 小时前
Visual Studio 软件操作:添加附加依赖项
c语言·c++·windows·visual studio
-To be number.wan1 小时前
C++ 进阶技巧:如何让 cout << 自定义对象 正常输出?
开发语言·c++
序属秋秋秋2 小时前
《Linux系统编程之进程控制》【进程创建 + 进程终止】
linux·c语言·c++·操作系统·进程·进程创建·进程终止
上天_去_做颗惺星 EVE_BLUE2 小时前
C++学习:学生成绩管理系统
c语言·开发语言·数据结构·c++·学习
John_ToDebug2 小时前
Chromium WebUI 定制实践:从 C++ 注入到 JS 安全展示全链路解析
javascript·c++·chrome
水饺编程2 小时前
开源项目介绍:VirtuaNES 模拟器
c语言·c++·windows·visual studio
十五年专注C++开发2 小时前
CMake进阶:find_package使用总结
开发语言·c++·cmake·跨平台编译
闻缺陷则喜何志丹3 小时前
【计算几何】平面凸包
c++·数学·扫描线·凸包·单调性·上凸包·下凸包
-To be number.wan3 小时前
C++ 运算符重载入门:让“+”也能为自定义类型服务!
开发语言·c++