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
相关推荐
好好先森&几秒前
C语言:冒泡排序
c语言·数据结构·算法·遍历·冒牌排序
☆璇几秒前
【C++】stack和queue
开发语言·c++
气质、小青年!7 分钟前
【string类常见接口】
c++
hqxstudying15 分钟前
Java向量化
java·开发语言
李永奉36 分钟前
C语言-字符串(定义)、字符串函数(strlen、strcat、strcpy、strcmp、strlwr、strupr)
c语言·开发语言·算法
暖苏36 分钟前
python-异常(笔记)
大数据·开发语言·笔记·python·异常
Chase_______1 小时前
JavaWeb笔记2-JavaScript&Vue&Ajax
开发语言·javascript·vue.js
你知道烟火吗1 小时前
谈谈对反射的理解?
java·开发语言·spring boot·后端
逝雪Yuki1 小时前
牛客——接头密匙
c++·字典树·前缀树·数据结构与算法
啊阿狸不会拉杆1 小时前
《Java 程序设计》核心知识点梳理与深入探究
java·开发语言·python·算法·php·intellij-idea