Here: html "> http://www.bkjia.com/ebook/201007/19457.html
# Include <iostream>
Using namespace std;
Enum CHOICE {DrawRect = 1, GetArea, GetPerim,
ChangeDimensions, Quit };
// Rectangle class declaration
Class Rectangle
{
Public:
// Construcors
Rectangle (int width, int height );
~ Rectangle ();
// Accessors
Int GetHeight () const {return itsHeight ;}
Int GetWidth () const {return itsWidth ;}
Int GetArea () const {return itsHeight * itsWidth ;}
Int GetPerim () const {return 2 * itsHeight + 2 * itsWidth ;}
Void SetSize (int newWidth, int newHeight );
// Misc. methods
Private:
Int itsWidth;
Int itsHeight;
};
// Class method implementations
Void Rectangle: SetSize (int newWidth, int newHeight)
{
ItsWidth = newWidth;
ItsHeight = newHeight;
}
Rectangle: Rectangle (int width, int height)
{
ItsWidth = width;
ItsHeight = height;
}
Rectangle ::~ Rectangle (){}
Int DoMenu ();
Void DoDrawRect (Rectangle );
Void DoGetArea (Rectangle );
Void DoGetPerim (Rectangle );
Int main ()
{
// Initialize a rectangle to 30,5
Rectangle theRect (30, 5 );
Int choice = DrawRect;
Int fQuit = false;
While (! FQuit)
{
Choice = DoMenu ();
If (choice <DrawRect | choice> Quit)
{
Cout <"Invalid Choice, please try again .";
Continue;
}
Switch (choice)
{
Case DrawRect:
DoDrawRect (theRect );
Break;
Case GetArea:
DoGetArea (theRect );
Break;
Case GetPerim:
DoGetPerim (theRect );
Break;
Case ChangeDimensions:
Int newLength, newWidth;
Cout <"New width :";
Cin> newWidth;
Cout <"New height :";
Cin> newLength;
TheRect. SetSize (newWidth, newLength );
DoDrawRect (theRect );
Break;
Case Quit:
FQuit = true;
Cout <"Exiting ...";
Break;
Default:
Cout <"Error in choice! ";
FQuit = true;
Break;
} // End switch
} // End while
Return 0;
} // End main
Int DoMenu ()
{
Int choice;
Cout <"*** Munu ***";
Cout <"(1) Draw Rectangle ";
Cout <"(2) Area ";
Cout <"(3) Perimeter ";
Cout <"(4) Resize ";
Cout <"(5) Quit ";
Cin> choice;
Return choice;
}
Void DoDrawRect (Rectangle theRect)
{
Int height = theRect. GetHeight ();
Int width = theRect. GetWidth ();
For (int I = 0; I
{
For (int j = 0; j <width; j ++)
Cout <"*";
Cout <"";
}
}
Void DoGetArea (Rectangle theRect)
{
Cout <"Area:" <theRect. GetArea () <endl;
}
Void DoGetPerim (Rectangle theRect)
{
Cout <"Perimeter:" <theRect. GetPerim () <endl;
}