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++】C++11:列表初始化、声明、STL升级
c++
ComputerInBook2 小时前
c 和 c++ 中的宏块(macro)
c语言·c++··宏块·宏指令
AA陈超3 小时前
004 T02 - 俯视角摄像机系统 设计文档
网络·c++·ue5·虚幻引擎
bu_shuo3 小时前
c与cpp中的argc和argv
c语言·c++·算法
蓝创精英团队3 小时前
VCPKG 跨平台C++ 库管理器
c++·vcpkg
Jayden_Ruan5 小时前
C++组合的输出
c++·算法·深度优先
froyoisle5 小时前
CSP 真题解析:[CSP-J 2020-T3] 表达式
c++·算法·csp·信息学·信奥赛
Darkwanderor6 小时前
动、静态库相关内容的详细介绍
linux·c语言·开发语言·c++
文祐6 小时前
C++类之虚函数表没有虚继承的菱形继承
开发语言·c++·算法
孬甭_7 小时前
C++ string类
开发语言·c++