# Starting the Sample Program

• I would like to build an example program to show you how it is going to work.
• This to demonstrate how programming works.
• I do not expect you to understand everything we do in detail.
• But I do expect you to understand what we are doing.
• I will try to explain what is going on as I do it.
• The problem
• Here is a homework assignment from a few years ago.
• The first step in the problem solving process is to Analyze the problem
• Can you play the game?
• Can you explain to someone how to play the game?
• What types of interaction would you expect from someone playing the game?
• Can you provide a one sentence/paragraph description of what you are supposed to do?
• Can you write down instructions on how to play the game?
• Can you write down detailed instructions on how to play the game?
• For the program what input do you expect from the user?
• What output do you expect to provide to the user?
• The second step of the problem solving process is to write an algorithm.
• As we said before an Algorithm is a set of steps to solve a problem in a finite amount of time.
• The steps are somewhat ambiguous right now, but we will work on that.
• Your job is to convince me that you can write code from your algorithm.
• Algorithm 1:
Play Grandmother's Trunk

• Algorithm 2:
get input from the user
print the output of the game

• Algorithm 3
Get the person owning the container
Get the name of the container

Get the first item in the container
Get the second item in the container
Get the last  item in the container

Print the main phrase (In my owners container I found)
Print a tab
Print the first item
Print a period

Print the main phrase (In my owners container I found)
Print a tab
Print the first item
Print a comma
Print a tab
Print "and a"
Print the first computer item
Print a period

Print the main phrase (In my owners container I found)
Print a tab
Print the first item
Print a comma
Print a tab
Print "and a"
Print the first computer item
Print a comma
Print a tab
Print "and a"
Print the second item
Print a period

Print the main phrase (In my owners container I found)
Print a tab
Print the first item
Print a comma
Print a tab
Print "and a"
Print the first computer item
Print a comma
Print a tab
Print "and a"
Print the second item
Print a comma
Print a tab
Print "and a"
Print the second computer item
Pritn a period

Print the main phrase (In my owners container I found)
Print a tab
Print the first item
Print a comma
Print a tab
Print "and a"
Print the first computer item
Print a comma
Print a tab
Print "and a"
Print the second item
Print a comma
Print a tab
Print "and a"
Print the second computer item
Print a comma
Print a tab
Print "and a"
Print the third item
Print a period

• Algorithm 4
Get the person owning the container
Get the name of the container

Select the computer items

Get the first item in the container
Get the second item in the container
Get the last  item in the container

Print the story with the first item.
Print the story with the first and the first computer item.
...

To Print A story (A sub-algorithm)
Input: A list of items

Print the main phrase (In my owners container I found)
For each item
Print a tab

If it is the first item
Print "a"
else
print "and a "

print the item

If it is the last item
print a period
else
print a comma
Print a newline

• The next step is to test the algorithm
• Why would you want to do this?
• How would you do this?
• Let's try with the third or fourth algorithm
• The next phase is implementation.
• In implementation we turn the algorithm into high level code.
• This is not a mechanical process
• It involves knowledge of everything mentioned on the first day.
• As we implement, we test the solution.
• But testing ramps up as more of the solution is implemented.
• Finally, the program is used and maintenance is performed.
• When problems are found they are (hopefully) corrected.
• We have just discussed the Programming Process as described by your author.
• This is a software engineering paradigm sometimes called the waterfall method