1 / 15

The Box

The 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. The Box - Inputs and Outputs. Inputs: height

lemosm
Download Presentation

The Box

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The 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.

  2. The Box - Inputs and Outputs • Inputs: • height • width • depth • Outputs • volume • surface area • height • width • depth

  3. The 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

  4. The Box - Final Pseudocode Display “Enter the height: “ Read <height> While (<height> <= 0 ) Display “The height must be > 0” Display “Enter the height: “ Read <height> End_while

  5. The Box - Final Pseudocode (con’t) Display “Enter the width: “ Read <width> While (<width> <= 0 ) Display “The width must be > 0” Display “Enter the width: “ Read <width> End_while

  6. The Box - Final Pseudocode (con’t) Display “Enter the depth: “ Read <depth> While (<depth> <= 0 ) Display “The depth must be > 0” Display “Enter the depth: “ Read <depth> End_while

  7. The Box - Final Pseudocode (con’t) <volume> = <height> X <width> X <depth> <surface1> = <height> X <width> <surface2> = <width> X <depth> <surface3> = <height> X <depth> <surface area> = 2 X (<surface1> + <surface2> + <surface3>)

  8. The Box - Final Pseudocode (con’t) Display “Height = “, <height> Display “Width = “, <width> Display “Depth = “, <depth> Display “Volume = “, <volume> Display “Surface Area = “, <surface area>

  9. Drawing 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.

  10. The Rectangle - Inputs and Outputs • Inputs • height • width • Outputs • height • width • the drawing of the rectangle

  11. The 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

  12. The Rectangle - Final Pseudocode Display “Enter the height: “ Read <height> While (<height> <= 0 ) Display “The height must be > 0” Display “Enter the height: “ Read <height> End_while

  13. The Rectangle - Final Pseudocode (con’t) Display “Enter the width: “ Read <width> While (<width> <= 0 ) Display “The width must be > 0” Display “Enter the width: “ Read <width> End_while

  14. The Rectangle - Final Pseudocode (con’t) Display “Height = “, <height> Display “Width = “, <width> Skip a line

  15. The Rectangle - Final Pseudocode (con’t) <height counter> = 1 While ( <height counter> <= <height> ) <width counter> = 1 While ( <width counter> <= <width> ) Display “*” <width counter> = <width counter> + 1 End_while Place cursor on next line <height counter> = <height counter> + 1 End_while

More Related