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;
}
相关推荐
编程之路,妙趣横生2 小时前
STL(五) priority_queue 基本用法 + 模拟实现
c++
一念一花一世界2 小时前
Arbess从初级到进阶(9) - 使用Arbess+GitLab实现C++项目自动化部署
c++·ci/cd·gitlab·arbess
大锦终2 小时前
【Linux】Reactor
linux·运维·服务器·c++
沐怡旸3 小时前
【穿越Effective C++】23.宁以non-member、non-friend替换member函数
c++·面试
青小俊3 小时前
【代码随想录c++刷题】-二分查找 移除元素 有序数组的平方 - 第一章 数组 part 01
c++·算法·leetcode
赖small强4 小时前
【Linux C/C++开发】第16章:多线程编程基础
linux·c语言·c++·多线程编程·进程和线程的本质区别
AA陈超4 小时前
以 Lyra 的架构为基础,创建一个名为 “Aura“ 的英雄并实现发射火球技能
c++·笔记·学习·ue5·lyra
xlq223225 小时前
16.17.list(上)
c++·list
cpp_25016 小时前
P1765 手机
数据结构·c++·算法·题解·洛谷
未到结局,焉知生死6 小时前
PAT每日三题11-20
c++·算法