#include <iostream>
using namespace std;
class Rectangle
{
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 Rectangle::set_l(int l)
{
length = l;
}
void Rectangle::set_w(int w)
{
width = w;
}
int Rectangle::get_l()
{
return length;
}
int Rectangle::get_w()
{
return width;
}
void Rectangle::show()
{
// cout << "矩形周长为:" << 2*(get_l()+get_w()) <<endl;
// cout << "矩形面积为:" << get_l()*get_w() <<endl;
cout << "矩形周长为:" << 2*(length+width) <<endl;
cout << "矩形面积为:" << length*width <<endl;
}
int main()
{
Rectangle Rec;
Rec.set_l(10);
Rec.set_w(5);
cout << "矩形长为:" << Rec.get_l() << endl;
cout << "矩形宽为:" << Rec.get_w() << endl;
Rec.show();
return 0;
}
3/26 C++_day2
最新推荐文章于 2024-10-19 15:29:34 发布