Functions, Part 3 of 3 - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Functions, Part 3 of 3

Description:

Let's take the algorithms that we developed in 'Algorithms, ... Skip a line. CMSC 104, Version 9/01. 13. The Rectangle - Pseudocode (con't) height counter = 1 ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 14
Provided by: SusanMi6
Category:
Tags: functions | part | skipa

less

Transcript and Presenter's Notes

Title: Functions, Part 3 of 3


1
Functions, Part 3 of 3
  • Topics
  • Coding Practice
  • In-Class Project The Box
  • In-Class Project Drawing a Rectangle
  • Reading
  • None

2
Coding Practice
  • Lets take the algorithms that we developed in
    Algorithms, Part 3 of 3, modularize them, and
    code them.

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
The Box - 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

5
The Box - 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

6
The Box - 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

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

8
The Box - Pseudocode (cont)
Display Height , ltheightgt Display Width ,
ltwidthgt Display Depth , ltdepthgt Display
Volume , ltvolumegt Display Surface Area ,
ltsurface areagt
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 - 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

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

12
The Rectangle - Pseudocode (cont)
  • Display Height , ltheightgt
  • Display Width , ltwidthgt
  • Skip a line

13
The Rectangle - 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
Write a Comment
User Comments (0)
About PowerShow.com