123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Rectangle
- {
- public:
- Rectangle();
- Rectangle(float length, float width);
- ~Rectangle();
- float getArea();
- float getPerimeter();
- private:
- float mLength;
- float mWidth;
- };
- Rectangle::Rectangle() : mLength(0), mWidth(0)
- {
- }
- Rectangle::Rectangle(float length, float width) : mLength(length), mWidth(width)
- {
- }
- Rectangle::~Rectangle()
- {
- }
- float Rectangle::getArea()
- {
- return mLength * mWidth;
- }
- float Rectangle::getPerimeter()
- {
- return 2 * (mLength + mWidth);
- }
- int main()
- {
- float m, n;
- cout << "Input the Length and Width: ";
- cin >> m >> n;
- Rectangle r1(m, n);
- cout << "The Area is: " << r1.getArea() << endl;
- cout << "The Perimeter: " << r1.getPerimeter() << endl;
- return 0;
- }
|