Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Rectangle
- {
- private:
- double width, length;
- public:
- void setWidth(double);
- void setlength(double);
- double getWidth() const;
- double getLength() const;
- double getArea() const;
- };
- void Rectangle::setWidth(double w)
- {
- width = w;
- }
- void Rectangle::setlength(double len)
- {
- length = len;
- }
- double Rectangle::getWidth() const
- {
- return width;
- }
- double Rectangle::getLength() const
- {
- return length;
- }
- double Rectangle::getArea() const
- {
- return width * length;
- }
- //Function main
- int main()
- {
- Rectangle box;
- double rectWidth; //Local variable for width
- double rectLength; //Local variable for length
- cout << "This program will calcuilate the area of a\n";
- cout << "rectangle. What is the width ?";
- cin >> rectWidth;
- cout << "What is the length? ";
- cin >> rectLength;
- box.setWidth(rectWidth);
- box.setlength(rectLength);
- cout << "Here is the rectangle's data:\n";
- cout << "Width: " << box.getWidth() << endl;
- cout << "Length: " << box.getLength() << endl;
- cout << "Area: " << box.getArea() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement