Download presentation
Presentation is loading. Please wait.
Published byMatthew Norman Modified over 9 years ago
1
CMSC 104, Version 9/01 1 Functions, Part 3 of 3 Topics: Coding Practice o In-Class Project: The Box o In-Class Project: Drawing a Rectangle Reading: None
2
CMSC 104, Version 9/01 2 Coding Practice Let’s take the algorithms that we developed in “Algorithms, Part 3 of 3”, modularize them, and code them.
3
CMSC 104, Version 9/01 3 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.
4
CMSC 104, Version 9/01 4 The Box - Pseudocode Display “Enter the height: “ Read While ( <= 0 ) Display “The height must be > 0” Display “Enter the height: “ Read End_while
5
CMSC 104, Version 9/01 5 The Box - Pseudocode (con’t) Display “Enter the width: “ Read While ( <= 0 ) Display “The width must be > 0” Display “Enter the width: “ Read End_while
6
CMSC 104, Version 9/01 6 The Box - Pseudocode (con’t) Display “Enter the depth: “ Read While ( <= 0 ) Display “The depth must be > 0” Display “Enter the depth: “ Read End_while
7
CMSC 104, Version 9/01 7 The Box - Pseudocode (con’t) = X X = X = 2 X ( + + )
8
CMSC 104, Version 9/01 8 The Box - Pseudocode (con’t) Display “Height = “, Display “Width = “, Display “Depth = “, Display “Volume = “, Display “Surface Area = “,
9
CMSC 104, Version 9/01 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
CMSC 104, Version 9/01 10 The Rectangle - Pseudocode Display “Enter the height: “ Read While ( <= 0 ) Display “The height must be > 0” Display “Enter the height: “ Read End_while
11
CMSC 104, Version 9/01 11 The Rectangle - Pseudocode (con’t) Display “Enter the width: “ Read While ( <= 0 ) Display “The width must be > 0” Display “Enter the width: “ Read End_while
12
CMSC 104, Version 9/01 12 The Rectangle - Pseudocode (con’t) Display “Height = “, Display “Width = “, Skip a line
13
CMSC 104, Version 9/01 13 The Rectangle - Pseudocode (con’t) = 1 While ( ) = 1 While ( ) Display “*” = + 1 End_while Place cursor on next line = + 1 End_while
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.