Announcement Do problems in Coding Practice Lab Sessions
Announcement • Do problems in Coding Practice. • Lab Sessions: Monday, 11/18, 11/20, 11/25, from 1: 00 - 2: 00 pm at ECS 122 A. • Because there is no computer lab available during our class period, Monday’s class will be changed to above Lab Sessions. • If you have already finished the Coding Practice programs before this lecture, you don’t need to come to the lab sessions. CMSC 104, Section 301, Fall 2002 1 Lecture 20, 11/18/02
Functions, Part 3 of 3 Topics: • Coding Practice § § In-Class Project: The Box In-Class Project: Drawing a Rectangle CMSC 104, Section 301, Fall 2002 2 Lecture 20, 11/18/02
Coding Practice • Let’s take the algorithms that we developed in “Algorithms, Part 3 of 3”, modularize them, and code them. CMSC 104, Section 301, Fall 2002 3 Lecture 20, 11/18/02
The Box Problem: Write an interactive program using C function 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. CMSC 104, Section 301, Fall 2002 4 Lecture 20, 11/18/02
The Box - Pseudocode 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, Section 301, Fall 2002 5 Lecture 20, 11/18/02
The Box - 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 CMSC 104, Section 301, Fall 2002 6 Lecture 20, 11/18/02
The Box - 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 CMSC 104, Section 301, Fall 2002 7 Lecture 20, 11/18/02
The Box - Pseudocode (con’t) <volume> = <height> X <width> X <depth> <surface 1> = <height> X <width> <surface 2> = <width> X <depth> <surface 3> = <height> X <depth> <surface area> = 2 X (<surface 1> + <surface 2> + <surface 3>) CMSC 104, Section 301, Fall 2002 8 Lecture 20, 11/18/02
The Box - Pseudocode (con’t) Display “Height = “, <height> Display “Width = “, <width> Display “Depth = “, <depth> Display “Volume = “, <volume> Display “Surface Area = “, <surface area> CMSC 104, Section 301, Fall 2002 9 Lecture 20, 11/18/02
Drawing a Rectangle Problem: Write an interactive program using C function 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. CMSC 104, Section 301, Fall 2002 10 Lecture 20, 11/18/02
The Rectangle - Pseudocode 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, Section 301, Fall 2002 11 Lecture 20, 11/18/02
The Rectangle - 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 CMSC 104, Section 301, Fall 2002 12 Lecture 20, 11/18/02
The Rectangle - Pseudocode (con’t) Display “Height = “, <height> Display “Width = “, <width> Skip a line CMSC 104, Section 301, Fall 2002 13 Lecture 20, 11/18/02
The Rectangle - 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 CMSC 104, Section 301, Fall 2002 14 Lecture 20, 11/18/02
Assignment and Next • Read Sections 5. 1 - 5. 8 Next: • Variable Storages and Scopes. • Array. • Project 3 due Monday 11/25, midnight. CMSC 104, Section 301, Fall 2002 15 Lecture 20, 11/18/02
- Slides: 15