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 小时前
Linux软件编程学习笔记(七):线程分离与线程间通信详解
linux·c语言·c++·笔记·学习
水饺编程11 小时前
第5章,[Win32 章节] :绘图模式
c语言·c++·windows·visual studio
INGNIGHT11 小时前
1908 · 布尔表达式求值(stack单调栈&dfs)
开发语言·c++·算法
小小杨树11 小时前
【C++】学习:双缓冲视频流水线深解析
c++·性能优化·音视频开发
青少儿编程课堂13 小时前
图形化编程实战:智能交通灯调度台,一个作品讲透循环、条件与广播
c++·python·算法·bfs·信息学竞赛
赵民勇13 小时前
C++无锁编程详解
c++
醉颜凉13 小时前
C++ 中野指针与悬挂指针的区别:从成因到防范,彻底讲清两种危险指针
c++
Demon--hx13 小时前
设计不能被继承的类
开发语言·c++
兔兔兔兔113 小时前
记录C++ 13
开发语言·c++·算法
开心大爆炸14 小时前
ubuntu20.4 安装ros1 noetic版本流程
c++