c++ day2

cpp 复制代码
#include <iostream>

using namespace std;
class rectangle{
    int length;
    int width;
public:
    void set_l(){
        cin>>length;
    }
    void set_w(){
        cin>>width;
    }
    int get_l(){
        return length;
    }
    int get_w(){
        return width;
    }
    void show(){
        int peremeter=2*(length+width);
        int space=length*width;
        cout<<"周长= "<<peremeter<<"  面积="<<space<<endl;
    }
};

int main()
{
    rectangle r1;
    r1.set_l();
    r1.set_w();
    cout<<r1.get_l()<<"   "<<r1.get_w()<<endl;
    r1.show();

    return 0;
}

结果

cpp 复制代码
3
5
3   5
周长= 16  面积=15
相关推荐
季明洵1 分钟前
Java实现循环队列、栈实现队列、队列实现栈
java·数据结构·算法··队列
Non importa4 分钟前
二分法:算法新手第三道坎
c语言·c++·笔记·qt·学习·算法·leetcode
王老师青少年编程4 分钟前
2020年信奥赛C++提高组csp-s初赛真题及答案解析(完善程序第1题)
c++·题解·真题·初赛·信奥赛·csp-s·提高组
WZ188104638695 分钟前
LeetCode第2368题
算法·leetcode
iAkuya6 分钟前
(leetcode)力扣100 74 数组中的第K个最大元素(快速选择\堆)
数据结构·算法·leetcode
学编程的闹钟7 分钟前
安装GmSSL3库后用VS编译CMake源码
c语言·c++·ide·开发工具·cmake·visual studio
云深处@7 分钟前
【数据结构】排序
数据结构·算法·排序算法
宇木灵8 小时前
C语言基础学习-二、运算符
c语言·开发语言·学习
想放学的刺客8 小时前
整理了120道单片机嵌入式面试题与答案,覆盖了硬件电路和C语言等核心领域。
c语言·c++·stm32·单片机·嵌入式硬件·mcu·51单片机
yangSimaticTech9 小时前
沿触发的4个问题
开发语言·制造