one solution

Download Report

Transcript one solution

The Hollow Rectangle
Display “Enter the height: “
Read <height>
While (<height> <= 0 )
Display “The height must be > 0”
Display “Enter the height: “
Read <height>
End_while
CMSC 104, Version 9/01
1
The Hollow Rectangle
Display “Enter the width: “
Read <width>
While (<width> <= 0 )
Display “The width must be > 0”
Display “Enter the width: “
Read <width>
End_while
CMSC 104, Version 9/01
2
The Hollow Rectangle
Display “Height = “, <height>
Display “Width = “, <width>
Skip a line
CMSC 104, Version 9/01
3
The Hollow Rectangle
<width counter> = 1
While (<width counter> <= <width>)
Display “*”
<width counter> = <width counter> + 1
End_while
Put cursor on next line
CMSC 104, Version 9/01
4
The Hollow Rectangle
If (<height> > 2)
<height counter> = 1
While (<height counter> <= (<height> - 2))
Display “*”
If (<width> > 2)
<width counter> = 1
While (<width counter> <= (<width> - 2))
Display blank space
<width counter> = <width counter> + 1
End_while
End_if
If (<width> > 1)
Display “*”
End_if
Put cursor on next line
<height counter> = <height counter> + 1
End_while
CMSC
104, Version 9/01
End_if
5
The Hollow Rectangle
If (<height> > 1)
<width counter> = 1
While (<width counter> <= <width>)
Display “*”
<width counter> = <width counter> + 1
End_while
Put cursor on next line
End_if
CMSC 104, Version 9/01
6