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;
}
相关推荐
WL学习笔记35 分钟前
类和对象(下)
c++·类和对象
傲世仙尊1 小时前
拷贝构造-传值传参的连锁反应与隐式函数的三个局限
c++
垆边人似月.1 小时前
华为机试题 :最大数
c++·算法·华为
方便面不加香菜2 小时前
C++ 关于多态的知识点讲解
开发语言·c++
jimy12 小时前
C++ 类成员函数的内联定义(inline)详解
开发语言·c++
sanqima3 小时前
CreateThread、_beginthreadex、AfxBeginThread三种线程创建的区别与联系
c++·tls·线程创建
sanqima3 小时前
依赖TLS和模块状态的MFC类
c++·mfc·tls·module state
All for pursuit.3 小时前
【动态规划-11】279.完全平方数
数据结构·c++·算法·leetcode·动态规划
瑶山3 小时前
Windows + WSL2 Ubuntu + VS Code配置C++开发环境
开发语言·c++·windows·vscode·wsl
小米里的大麦4 小时前
19 C、C++ 操作 MySQL
c语言·c++·mysql