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
相关推荐
xyq202414 小时前
Chart.js 安装指南
开发语言
ysa05103015 小时前
模拟【打牌游戏】
数据结构·c++·笔记·算法
Predestination王瀞潞15 小时前
1. Java SE到底是什么:不仅仅是面向对象
java·开发语言
Byron070715 小时前
Python面向对象编程(OOP)详解:类、对象、继承、多态、封装
开发语言·python
ht巷子15 小时前
boost.asio网络学习:Http Server
网络·c++·http
-许平安-15 小时前
MCP项目笔记三(server)
网络·c++·笔记·mcp
weixin_6495556715 小时前
C语言程序设计第四版(何钦铭、颜晖)第八章指针之循环后移
c语言·c++·算法
福楠15 小时前
C++ | 哈希的应用
开发语言·c++·哈希算法
_饭团15 小时前
C语言数组全解析:从入门到精通
c语言·开发语言·数据结构·经验分享·笔记·学习·算法
陕西小伙伴网络科技有限公司15 小时前
kettle单转换实现分页查询
开发语言·前端·javascript