216 Week 1
(4) Resize
(5) Quit
3
Perimeter: 36
*** Menu ***
(1) Draw Rectangle
(2) Area
(3) Perimeter
(4) Resize
(5) Quit
5
Exiting...
This program utilizes most of the skills you learned this week. You should not
only be able to enter, compile, link, and run this program, but also understand
what it does and how it works, based on the work you’ve done this week. If you are con-
fused by any of the lines in this listing, you should go back and review the previous
week’s material. To the left of many of the lines are references to which day that line’s
primary function is covered.
This program presents a text menu and waits for you to make a selection. The menu
works with a rectangle. You have options to print out a representation of the rectangle as
well as options to get its area and perimeter. You can also change the default values for
the rectangle. The menu does not do all of the error checking that a full-fledged program
should do; however, it does do some checking.
On lines 7–12, the program listing sets up the new types and definitions that will be used
throughout the program.
Lines 15–34 declare the Rectangleclass. There are public accessor methods for obtain-
ing and setting the width and height of the rectangle, as well as for computing the area
and perimeter. Lines 37–47 contain the class function definitions that were not declared
inline. Because a constructor was created on lines 43–47, a destructor is also created on
line 49.
The function prototypes, for the nonclass member functions, are on lines 51–54, and the
entry point of the program begins on line 57. As stated, the essence of this program is to
generate a rectangle, and then to print out a menu offering five options: Draw the rectan-
gle, determine its area, determine its perimeter, resize the rectangle, or quit.
A flag is set on line 63, and as long as the flag is set to false, the menu loop continues.
The flag is only set to trueif the user chooses Quitfrom the menu.
ANALYSIS
10 0672327112_w1_wir.qxd 11/19/04 12:26 PM Page 216