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;
}
相关推荐
归去_来兮6 分钟前
深度学习模型在C++平台的部署
c++·深度学习·模型部署
pay4fun1 小时前
2048-控制台版本
c++·学习
hjjdebug3 小时前
ffplay6 播放器关键技术点分析 1/2
c++·ffmpeg·音视频
Azxcc04 小时前
C++异步编程入门
开发语言·c++
吐泡泡_4 小时前
C++(STL源码刨析/vector)
c++
你的冰西瓜4 小时前
C++排序算法全解析(加强版)
c++·算法·排序算法
特立独行的猫a4 小时前
11款常用C++在线编译与运行平台推荐与对比
java·开发语言·c++
笑鸿的学习笔记4 小时前
qt-C++笔记之setCentralWidget的使用
c++·笔记·qt
苏克贝塔6 小时前
Qt 图形视图框架3-事件处理与传播
c++·qt
轩情吖6 小时前
Qt的信号与槽(二)
数据库·c++·qt·信号·connect·信号槽·