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