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
相关推荐
阿kun要赚马内几秒前
Qt写群聊项目(二):客户端
开发语言·c++·qt
轩情吖3 分钟前
数据结构-并查集
开发语言·数据结构·c++·后端··并查集
wjs20249 分钟前
SQL CREATE DATABASE 命令详解
开发语言
好学且牛逼的马11 分钟前
【Hot100|18-LeetCode 54. 螺旋矩阵】
算法·leetcode·矩阵
独自破碎E11 分钟前
LCR001-两数相除
java·开发语言
YYYing.11 分钟前
【Linux/C++进阶篇 (一)】man手册、gdb调试、静态库与动态库
linux·运维·c++
孞㐑¥13 分钟前
算法—模拟
c++·经验分享·笔记·算法
70asunflower13 分钟前
Python网络内容下载框架教程
开发语言·网络·python
微祎_14 分钟前
Flutter for OpenHarmony:构建一个专业级 Flutter 番茄钟,深入解析状态机、定时器管理与专注力工具设计
开发语言·javascript·flutter
2401_8914504616 分钟前
C++中的职责链模式实战
开发语言·c++·算法