cmsc 104, version 9/01 1 the box problem: write an interactive program to compute and display the...

15
CMSC 104, Version 9/01 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.

Upload: jasper-perkins

Post on 24-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/011

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.

Page 2: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/012

The Box - Inputs and Outputs

• Inputs:o heighto widtho depth

• Outputso volumeo surface areao heighto widtho depth

Page 3: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/013

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

Page 4: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/014

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

Page 5: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/015

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

Page 6: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/016

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

Page 7: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/017

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>)

Page 8: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/018

The Box - Final Pseudocode (con’t)

Display “Height = “, <height>

Display “Width = “, <width>

Display “Depth = “, <depth>

Display “Volume = “, <volume>

Display “Surface Area = “, <surface area>

Page 9: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/019

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.

Page 10: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0110

The Rectangle - Inputs and Outputs

• Inputso heighto width

• Outputso heighto widtho the drawing of the rectangle

Page 11: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0111

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

Page 12: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0112

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

Page 13: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0113

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

Page 14: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0114

The Rectangle - Final Pseudocode (con’t)

Display “Height = “, <height>

Display “Width = “, <width>

Skip a line

Page 15: CMSC 104, Version 9/01 1 The Box Problem: Write an interactive program to compute and display the volume and surface area of a box. The program must also

CMSC 104, Version 9/0115

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