Examples of Problem Solving
Simple - Calculate the density of a solid cube given the length of one
side in centimeters and the mass of the cube in grams.
Solving the problem
- Understanding - I am given the length of a side of a cube in centimeters
and the mass of the cube in grams. These data will be input by the user.
- Density = mass/volume and I am not given the mass and volume only the
mass so I can't solve directly.
- I haven't solved this problem before.
- I haven't solved anything like this.
- I must divide the problem into smaller parts. Checking the problem, I
find that if I had the volume of the cube, then I could directly solve
the problem. Therefore, one part is find the volume and the other part
is find the density.
Solving the volume problem
- Understand the problem. Find the volume of a cube.
- I can get the volume directly since I'm given the length of a side.
Full Design for solving Density of a cube
- get length of side from user
- get mass from user
- calculate the volume using formula (volume <-- side*side*side)
- calculate the density using formula (density <-- mass/volume)
- print the result to the screen
Complex - Write a non-graphical version of minesweeper.
- show the user a menu (rules, play, quit)
- get the user's choice
- based on the user's choice do one of the following
- show the rules
- play the game
- print a quit message
- repeat the above until the user chooses to quit