Lessons
C++ · Objects · 52. Methods and Constructors
step 1 of 7
A method does a job
A function inside a class is a method. area needs no arguments — it uses its own w and h.
Call it with the dot: r.area().
Mission
Add a method perimeter that returns 2 * (w + h), and print r.perimeter() too.
PIP·1
main.cppyour code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
← press me!
Press RUN to see what this program does.