. 以下程序能根据对象提供的长方形的长和宽得到该长方形的面积和周长 class rectangle { private: float ledge,sedge public: rectangle(){ledge=0;sedge=0;} rectangle(float a,float b) {ledge=a; sedge=b;} void area(){cout<<”面积:”<< ▁▁▁ << endl;} void length(){cout<<”周长:”<< ▁▁▁ << endl;} }; void main() { rectangle A(3.5, 2.0),B(4.2, 2.0); A.area(); A.length(); B.area(); B.length(); }
时间: 2023-05-17 07:06:53 浏览: 93
java代码-已知长方形的长和宽,求长方形的周长和面积。
5星 · 资源好评率100%
答案:
class rectangle {
private:
float ledge, sedge;
public:
rectangle() {
ledge = 0;
sedge = 0;
}
rectangle(float a, float b) {
ledge = a;
sedge = b;
}
void area() {
cout << "面积:" << ledge * sedge << endl;
}
void length() {
cout << "周长:" << 2 * (ledge + sedge) << endl;
}
};
void main() {
rectangle A(3.5, 2.0), B(4.2, 2.0);
A.area();
A.length();
B.area();
B.length();
}
阅读全文