定义一个矩形类(Rectangle),包含私有成员:长(length)、宽(width),
定义成员函数:
设置长度:void set_l(int l)
设置宽度:void set_w(int w)
获取长度:int get_l();
获取宽度:int get_w();
展示函数输出该矩形的周长和面积:void show()
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
class Stu
{
private:int length;int width;
public:void set_l(int l);void set_w(int w);int get_l();int get_w();void show();
};void Stu::set_l(int l)
{length = l;
}void Stu::set_w(int w)
{width = w;
}
int Stu::get_l()
{return length;
}
int Stu::get_w()
{return width;
}
void Stu::show()
{int peremeter = (length+width)*2;int space = length*width;cout<<"该矩形的周长为:"<<peremeter<<" 该矩形的面积为:"<<space<<endl;
}int main()
{Stu s1;s1.set_l(6);s1.set_w(8);s1.show();return 0;
}