Title: The Box
1The Box
- Problem Write an interactive program to compute
and display the volume and surface area of a box.
The program must also display the box
dimensions. Error checking should be done to be
sure that all box dimensions are greater than
zero.
2The Box - Inputs and Outputs
- Inputs
- height
- width
- depth
- Outputs
- volume
- surface area
- height
- width
- depth
3The Box - Rough Algorithm
- Get the height from the user, performing error
checking - Get the width from the user, performing error
checking - Get the depth from the user, performing error
checking - Compute the volume of the box
- Compute the surface area of the box
- Display the height, width, depth, volume, and
surface area of the box
4The Box - Final Pseudocode
- Display Enter the height
- Read ltheightgt
- While (ltheightgt lt 0 )
- Display The height must be gt 0
- Display Enter the height
- Read ltheightgt
- End_while
5The Box - Final Pseudocode (cont)
- Display Enter the width
- Read ltwidthgt
- While (ltwidthgt lt 0 )
- Display The width must be gt 0
- Display Enter the width
- Read ltwidthgt
- End_while
6The Box - Final Pseudocode (cont)
- Display Enter the depth
- Read ltdepthgt
- While (ltdepthgt lt 0 )
- Display The depth must be gt 0
- Display Enter the depth
- Read ltdepthgt
- End_while
7The Box - Final Pseudocode (cont)
- ltvolumegt ltheightgt X ltwidthgt X ltdepthgt
- ltsurface1gt ltheightgt X ltwidthgt
- ltsurface2gt ltwidthgt X ltdepthgt
- ltsurface3gt ltheightgt X ltdepthgt
- ltsurface areagt 2 X (ltsurface1gt
ltsurface2gt -
ltsurface3gt)
8The Box - Final Pseudocode (cont)
Display Height , ltheightgt Display Width ,
ltwidthgt Display Depth , ltdepthgt Display
Volume , ltvolumegt Display Surface Area ,
ltsurface areagt
9Drawing a Rectangle
- Problem Write an interactive program that will
draw a solid rectangle of asterisks (). The
program must also display the dimensions of the
rectangle. Error checking must be done to be
sure that the dimensions are greater than zero.
10The Rectangle - Inputs and Outputs
- Inputs
- height
- width
- Outputs
- height
- width
- the drawing of the rectangle
11The Rectangle - Rough Algorithm
- Get the height from the user, performing error
checking - Get the width from the user, performing error
checking - Display the height and width
- Draw the rectangle
12The Rectangle - Final Pseudocode
- Display Enter the height
- Read ltheightgt
- While (ltheightgt lt 0 )
- Display The height must be gt 0
- Display Enter the height
- Read ltheightgt
- End_while
13The Rectangle - Final Pseudocode (cont)
- Display Enter the width
- Read ltwidthgt
- While (ltwidthgt lt 0 )
- Display The width must be gt 0
- Display Enter the width
- Read ltwidthgt
- End_while
14The Rectangle - Final Pseudocode (cont)
- Display Height , ltheightgt
- Display Width , ltwidthgt
- Skip a line
15The Rectangle - Final Pseudocode (cont)
- ltheight countergt 1
- While ( ltheight countergt lt ltheightgt )
- ltwidth countergt 1
- While ( ltwidth countergt lt ltwidthgt )
- Display
- ltwidth countergt ltwidth countergt 1
- End_while
- Place cursor on next line
- ltheight countergt ltheight countergt 1
- End_while