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;
}
相关推荐
梦境虽美,却不长44 分钟前
C++ 学习 多线程 2025年6月17日18:41:30
c++·学习·线程·异步
一只理智毅1 小时前
copy-and-swap语义
c++
芒果快进我嘴里1 小时前
C++打印乘法口诀表
开发语言·c++
_w_z_j_2 小时前
C++----剖析stack、queue
开发语言·c++
量化投资和人工智能2 小时前
【CUDA编程】OptionalCUDAGuard详解
c++·人工智能·python·机器学习·云计算·cuda
yxc_inspire3 小时前
基于Qt的app开发第十五天
c++·qt·面向对象·qtreeview
MrGaomq4 小时前
软件测试用例(二)
linux·c语言·c++·经验分享·笔记·测试用例
虾球xz4 小时前
CppCon 2016 学习:Parallelism in Modern C++
开发语言·c++·学习
BMW_i85 小时前
C++---类和对象(中)
开发语言·c++
liulilittle6 小时前
_mm_aeskeygenassist_si128 硬件指令执行的操作
开发语言·c++·aes