题目
设计一个程序,定义一个矩形类,包括数据成员和函数成员。要求能获取和修改矩阵的的长和宽,并能计算矩阵的面积,并编写 main 函数进行测试。
相关阅读
完整代码
#include<bits/stdc++.h>
#define Pi 3.14;
using namespace std;
class Rectangle{
double length;
double width;
public:
double getLength(){
return length;
}
double getWidth(){
return width;
}
void modifyLength(double length){
this->length = length;
}
void modifyWidth(double width){
this->width = width;
}
double getArea(){
return length*width;
}
};
int main(){
Rectangle rectangle;
rectangle.modifyWidth(3.0);
rectangle.modifyLength(4.0);
cout << "The width is: " << rectangle.getWidth() << endl;
cout << "The length is: " << rectangle.getLength() << endl;
cout << "The area is: " << rectangle.getArea() << endl;
}