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;
}
相关推荐
小保CPP14 小时前
OCR C++ Tesseract生成可搜索的pdf
c++·人工智能·ocr·模式识别·光学字符识别
是个西兰花15 小时前
Linux:深入解析Linux线程原理与实现
linux·运维·c++·线程·互斥锁
小保CPP17 小时前
OCR C++ Tesseract基础用法
c++·人工智能·ocr·模式识别·光学字符识别
TCW112117 小时前
AI底层系列:用C++实现线性代数的公式推导与算法设计-8.线性变化(3)
c++·人工智能·算法
皓月斯语17 小时前
B3849 [GESP样题 三级] 进制转换 题解
c++·算法·题解
Ljwuhe18 小时前
C++——模板进阶
开发语言·c++
hehelm18 小时前
AI 大模型接入 SDK —项目概述
linux·服务器·网络·数据库·c++
zmzb010318 小时前
C++课后习题训练记录Day161
开发语言·c++
小保CPP19 小时前
OCR 在C语言中使用Tesseract API
c语言·c++·人工智能·算法·ocr·模式识别·光学字符识别
sTone8737519 小时前
写时复制COW的第一性理解
android·c++·flutter