← Classes & Objects

Rectangle Area and Perimeter

medium

Complete Rectangle’s two member functions: area (width times height) and perimeter (twice the sum of width and height).

This is deliberately similar to the last exercise, with two member functions on one class instead of one – both read the same two member variables, computing something different from them. Notice main never touches width or height inside a formula itself; it just asks the object for area() and perimeter() and trusts the class to know how those are computed. That’s the actual value of bundling data and behavior together, made concrete.

Your solution

"Run" uses the sample stdin ("4 5"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution