- 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