#include <iostream>
using namespace std;
class rec
{
public:
void set_l(int l);
void set_w(int w);
int get_l();
int get_w();
void show();
private:
int length;
int width;
};
void rec::set_l(int l)
{
length=l;
}
void rec::set_w(int w)
{
width=w;
}
int rec::get_l()
{
return length;
}
int rec::get_w()
{
return width;
}
void rec::show()
{
cout<<"矩形周长="<<(length+width)*2<<endl;
cout<<"矩形面积="<<length*width<<endl;
}
int main()
{
rec rectangle;
rectangle.set_l(20);
rectangle.set_w(10);
cout<<"矩形长="<<rectangle.get_l()<<endl;
cout<<"矩形宽="<<rectangle.get_w()<<endl;
rectangle.show();
return 0;
}
3.26 c++
最新推荐文章于 2024-07-19 17:07:49 发布