#include <iostream>
using namespace std;
class Rectangle
{
private:
int length;
int width;
public:
void set_l(int x);
void set_w(int y);
int get_l();
int get_w();
void show();
};
void Rectangle::set_l(int x)
{
length = x;
}
void Rectangle::set_w(int y)
{
width = y;
}
int Rectangle::get_l()
{
return length;
}
int Rectangle::get_w()
{
return width;
}
void Rectangle::show()
{
int a = get_l();
int b = get_w();
int c = 2*(a+b);
int s = a*b;
//输出周长和面积
cout << "c = " << c << endl;
cout << "s = " << s << endl;
}
int main()
{
Rectangle A;
A.set_l(20);
A.set_w(15);
A.show();
return 0;
}
C++第二天
最新推荐文章于 2024-09-14 16:21:49 发布