Homework Assignment #4
CS 161:
Introduction to Computer Science 1
Email your answers to:
karlafgr@cs.pdx.edu
***Homework in CS161
consists of written homework and programming***
*** Functions are
discussed in Lecture #9 and #10 ***
1.
Create an Algorithm for playing
ping pong (table tennis) or some other two person sport such as Tennis.
·
Remember an
algorithm must be written in complete English sentences, and be clear and
complete
·
Focus on taking turns and keeping score
2. Think about Style. There is
consensus that style includes:
(a)
having header comments with your name, class,
purpose of the program,
(b)
indenting consistently, where all code within {}
blocks is indented the same and that all curly brackets line up,
(c)
have “inline” comments throughout, describing the purpose
of the code that follows
(d)
using meaningful variable names, and
(e)
replace the use of
numbers within a program with variables or constants – using meaningful names
to self document the software.
Write a short program that successfully shows that you understand
program style meeting all five of the above criteria…with these caveats:
·
The program must be entirely of your own creation –
it may not be one of the demo programs, from the book or
from the web.
·
You may not
have used this program on a previous assignment
·
It must include
input, output, and have both an if,
array of characters, and a for loop
·
It must compile
and run
·
Keep it simple!
3.
Ethics. If you were
working at a high-tech company, with access to computers, software, and data –
what three
company rules would you suggest in order to keep from
violating computer ethics?
4.
Programming. In this program,
you will be developing a guessing game. The idea of the game is to take a
number from the player1 (while player2 looks away), and then after outputting
many blank lines – allow the second player to guess a number. If it is a match
they win. If not, they get to guess again. If their second guess is farther
away – then display a message “cooler” and if it is closer display a message
“warmer”. Continue this process. The winner gets 10 points (at most) for a
correct guess – but each time they have to try to guess again, a point is
deducted. The player’s turn ends when they (a) guess the correct answer or (b)
their score reaches 0 (they had 10 tries without luck!). Then it is the next
player’s turn. Stop when the players want to quit. Display the highest score.
·
Write an Algorithm and Place it in your Header Comments!
It should be clear enough to know how to proceed to write the program.
·
Use Functions
·
Keep your main function limited to 10-15 lines long
(not including variables and comments)
·
Hint: After one
player enters in a number, output a bunch of newlines to “clear” that from the
screen.
·
Step #1…write an algorithm. Create one function at a time and
incrementally unit test these functions before moving on!