Homework Assignment #3

 

CS 161: Introduction to Computer Science 1

 

 

Submit your assignment to the D2L Dropbox (sign on via www.my.pdx.edu)

or Email your answers to: karlafgr@cs.pdx.edu

 

 

***Homework in CS161 consists of written homework and programming***

 

1.      Create an Algorithm for playing a game with two players. You may select any game (card game, board game, video game) except that you may not select tic-tac-toe.

·        Assume you are writing the algorithm for someone who has never played the game

·        Try to group things into related areas – for example what does it mean to (1) play the game, or (2) move a piece (if it is a board game), or (3) switch players. This will allow you to condense how much writing is done for this algorithm!

·        Every time you come to the conclusion “oh, I’ve already done this before” then just place what was done in a group – and name that group (e.g., switch players) and then use it whenever you need.

·        Desk check your algorithm (go through the algorithm as if you were turning in an assignment!)

 

2.      Think about Style. We are getting a better handle on what style is all about. We are going to create our own set of style requirements this term. List 3 things that you think is most important to make for a readable program. We will use these to compile a “style sheet” that our grader can use in the future!

·        Remember, style is all about how readable and/or maintainable a program is.

 

3.      Ethics. We’ve talked about ethics in terms of data and misleading error messages. Now let’s talk about the programmer’s responsibility to accurately calculate the results. Give examples where an incorrect or inaccurate calculation could result in devastating circumstances.

 

4.      Programming. You have two choices for creating a program in homework #2. Only select one of the choices.

 

·        Graphics: (If you are using Dev C++ with graphics.h then you can select this project)

Write a C++ program that take the widget that was created in homework #2 and allow the user to change the appearance (color and size), or move it to a different location on the screen. This will require using variables and some input from the user to find out what the user wants to do. Try to have some fun with this.  The program must use (a) at least 1 if/else statement, (b) at least 1 loop, and (c) at least 1 logical operation (&& or ||).  For extra creditMake the widget move around on the screen (hint…refer to Week #4 slides!)

 

·        Non-Graphics: (If you are using MAC, PC, Unix or Linux then you can select this project)

Write a C++ called “Karla’s Mad Math”. It is a two player game, so once you get your program working you might want to play it with another person. First, let me describe the rules. One player selects two whole numbers and one math operation (multiplication, division, subtraction, and addition). The computer will display the equation and the other player will need to type in the answer. The computer will compare the answer entered with the correct answer that it calculates. If it is correct, the player who answered the question gets a point. If not, the player who created the equation gets the point. Now switch turns. The player who gets 5 points first, wins!

 

You will need two variables for each player’s score (integers). You will need two variables to hold the two numbers (again, integers). And more…

 

The program must use (a) at least 1 if/else statement, (b) at least 1 loop, and (c) at least 1 logical operation (&& or ||).  For extra creditAllow the players to play the game as many times as they want!