Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class CRectangle {
- int x, y;
- public:
- void set_values (int,int); // setter
- int getX() const { return x; } // getter
- int getY() const { return y; } // getter
- };
- void CRectangle::set_values (int a, int b) {
- x = a;
- y = b;
- }
- int area(int a, int b) { return (a* b); }
- int main () {
- CRectangle rect;
- int locX, locY;
- rect.set_values (3,4);
- locX = rect.getX();
- locY = rect.getY();
- int rectangleArea = area(locX, locY);
- cout << "area: " << rectangleArea;
- // could have just done this and removed a lot of work
- cout << "area: " << area(rect.getX(), rect.getY());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment