Designing programs with flow charts - Exercise 1

 Draw a flow chart and trace table for the following problem:  
 Here we go again! What processes, decisions, loops and variables do we have?
 
 
Processes: 
  • Sell a bunch of flowers
  • Maintain a counter of bunches sold
  • Store the value of the most expensive bunch
  • Store the value of the least expensive bunch
  • Maintain an average value
  • and in order to find the average price we will need to keep a total of the values
Variables: 
  • Bunches_Sold
  • Price
  • Highest_Price
  • Lowest_Price
  • Average_Price
  • Total_value
 
Decisions: 
  • Find_Highest
  • Find_Lowest
Loops: 
  • Selling flowers
 
I've stated the algorithm in step form initially - this makes the sketching of the flow chart at bit easier:

While there are bunches of flowers to sell

  1.   sell a bunch
  2.   increment the bunches sold counter
  3.  calculate the average so far
  4.  if price of current bunch is greater than price of highest bunch then make price of highest bunch = price of current bunch
  5.  if price of current bunch is less than price of cheapest bunch then make price of cheapest bunch = price of current bunch
  6.  end of while
 
 
I have been a bit inventive with the layout of the symbols in order to make the flow chart more "viewable". The flow chart still follows the rules though.

Take a look at the initialisation of the variables in the first process. Lowest has been set to an initial value of 100 and Highest to 0. Why is this?

It is a fair bet that we will sell a bunch of flowers for more than zero dollars. If we set Highest to some positive initial value there is always risk, although very small, that we may not sell a bunch for more than the initial value. If this situation arose then the Highest value would be wrong.

I have chosen 100 for Lowest's initial value since I decided that we would never sell flowers for more than $100 per bunch. What would it profit a man if he gained the whole world but lost his soul?

 
   
 

 


Return to the lesson


and may not be reproduced by any means without the written
 

This publication is copyright David Beech and Learning Systems 1997-2002
and may not be reproduced by any means without the written permission of
David Beech.
9 Wyndella Street, Tasmania, Australia


db@codelearn.com