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***
*** Arrays are
discussed in Lecture #11 ***
***Late homeworks WILL
be allowed for late point deduction ***
1.
Create an
Algorithm for a program that would be used by an airline to assign seats for
passengers. Assume that an airplane has 13 rows, with 6 seats in each row. Ros 1 and 2 are first class. The remaining
rows are economy class. Discuss in your algorithm how arrays will be used in
the solution.
·
Remember an
algorithm must be written in complete English sentences, and be clear and
complete
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 have some purpose – although it can be
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 word guessing game. The idea of the game is to take a
phrase from the player1 (while player2 looks away), and display it back to the
user with one character missing (display an underscore instead of one of the
characters). If they can correctly guess what character is missing then the
next time around we display a new phrase with two characters missing (display
an underscore instead of the character). This continues until the player
doesn’t get the right answer. Each time they get a correct answer, they get a
point. Once they mess up, it is time to switch turns. 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 an array of characters to hold the phrase.
·
Hint: After one
player enters in a phrase, output a bunch of newlines to “clear” that from the screen.
·
Use cin.get with 3 arguments to read in the phrase
(cin.get(array, size_of_array,’\n’);
·
Remember to always remove newlines from the input
buffer! Always!