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;
}
相关推荐
还是阿落呀8 分钟前
基本控制结构2
c++
多思考少编码30 分钟前
PAT甲级真题1001 - 1005题详细题解(C++)(个人题解)
c++·python·最短路·pat·算法竞赛
极客智造2 小时前
C++ 标准 IO 流全详解:cin /cout/get /getline 原理、用法、区别与避坑
c++·io
charlie1145141912 小时前
嵌入式C++工程实践第20篇:GPIO 输入模式内部电路 —— 芯片是如何“听“到外部信号的
开发语言·c++·stm32·单片机
样例过了就是过了4 小时前
LeetCode热题100 分割等和子集
数据结构·c++·算法·leetcode·动态规划
麦兜和小可的舅舅4 小时前
ClickHouse 列管理机制解析:从 COW、IColumn 到 CRTP
c++·clickhouse
旖-旎5 小时前
深搜练习(组合)(5)
c++·算法·深度优先·力扣
vegetablesssss5 小时前
vtk镜像图
c++·qt·vtk
@小码农5 小时前
2026年3月Scratch图形化编程等级考试一级真题试卷
开发语言·数据结构·c++·算法
【 】4236 小时前
C++&STL(Standard Template Library,标准模板库)
java·开发语言·c++