Escolar Documentos
Profissional Documentos
Cultura Documentos
Writing a Program
For Homework #5, we will be starting a new program. Part of this assignment will be to reinforce the
process of writing algorithms and learning how best to apply loops and functions. We will move away
from using global variables in this assignment and learn how to create locals and pass (and return) the
information we want functions to have access. For your loops you will want to continue to use WHILE
loops.
In this homework, you will be creating a program to play a word guessing game. It is a 2 player game.
Here is how it will work:
1. The first player types in a word. Your program should clear the screen immediately after
2. The second player will try to guess the word with a maximum of 4 chances
3. In the prompts each time through, your program will provide a variety of hints starting with:
a. First prompt provides the number of characters of the word
b. The second prompt provides the first character
c. The third prompt provides both the first and last characters
d. CHALLENGE (Extra Credit!) - The fourth prompt outputs the first character and each vowel
followed by the last character
4. The word typed in doesnt have to be the same case as what the first player typed in to match.
This means funny will match with FUNNY or Funny
5. If they get it right, give the player 4 points on the first try, 3 points for the second try, 2 points for
the 3rd try and 1 point for the last try. Then give the other player a turn
6. Continue this until a player reaches 10 points or they want to quit.
The next page outlines the steps to take to be successful with writing this program!
Follow these steps. Start by planning! Have a technical assistant check off the first three steps before
starting to program!
_____1. Create the algorithm
_____a. List out the major steps
_____b. How do we clear the screen? Output many newlines!
_____c. Decide how you will handle the points. What variables do you need and what
should their initial values be
_____d. Decide how to handle the different prompt hints. Will you be using an if
statement? What variable will you need to decide how many tries the user has gone
through so far
_____e. Decide how to handle alternating between two players
_____f. Where will you need loops in this program?
_____a. To clear the screen
_____b. To have another turn
_____c. The four tries maximum
_____2. Decide what Modules you need
For each module plan what information the module needs to work with as arguments
and what returned value is needed
Function Headers
_____a. Welcome the user
MODULE welcome()
_____b. Get the word to be guessed MODULE String get_word()
_____c. Clear the screen
_____d. Now it is your turn:
_____3.
_____4.
_____5. AFTER Steps 1-4 are checked off by a technical assistant, start to program! Incrementally
create the program, one module at a time. Translate and compile and then continue with the
next. Never implement more than a single module without first testing what you have created!
_____6.
_____7.
Navigate to the directory for the homework, by changing into that directory:
cd CS161/HW5 <enter>
_____8.
Now start modifying the program to add repetition using pico, nano, vi, vim or emacs:
pico prog5.gp <enter>
or
nano prog5.gp <enter>
variable = sample(number_of_tries)
_____11. After implementing each module make sure to translate, compile and run your software:
_____a. Translate and Compile your source code file. The command to do this is:
./slk prog5<enter>
_____b. Run your program by typing:
./prog5.exe
_____c. Make corrections before implementing the next module!
_____12. Submit your program by typing ./submit in the HW5 directory
UPLOAD TO D2L
_____1. Upload to D2L your answers to Steps 1-4, including the flow chart