Polya's How to Solve It
Adapted into a method for writing simple C++ functions
What is the Goal
What is the function supposed to produce?
Think of a short descriptive name for the function.
If there is more than one value as a goal:
give each one a name
what type of data? integer, rational, string, object,...
Are they to be shown/output to the user?
Are they the value returned by the function?
What are the Givens
These are values that the function will be given.
Give them a short descriptive name.
Answer these questions:
Are they constant or variable?
What type of data? integers, rational, strings, objects?
Do you know there initial value?
Where does the value come from?
The problem statement (constants)
Input to the program (variables)
Supplied when the function is called (arguments)
Write declarations for the variables and constants.
What are the relations between the Givens and the Goals?
Write down the mathematical formulae for the goals
in terms of the givens (and perhaps other goals).
Make sure they are in the write order.
Add statements to
output goals to the user
return function value.