CS 202. Object-Oriented programming
Syllabus
Mailing list.
To join the CS 202 mailing list.
Enter your e-mail address:
Press
ENTER
, or
To send/post a message to the CS 202 mailing list,
click here.
Explore the CS 202 mailing list at
www.egroups.com/group/CS202
.
Read all messages posted.
Send/post messages.
Find email addresses of other members.
To take yourself off the CS 202 mailing list,
click here
.
Homework, tests, and code examples
Guess a number.
Modify this program so that it works with warmer/colder clues.
Add a constructor that works with a single number, which is the top of the range. Set the bottom to 1.
Allow the user to play multiple games. For each new game, the user may enter either 0, 1, or 2 numbers specifying no range (default 1 .. 100), an upper limit (lower limit 1) or both the upper and lower limits.
Rationals
Add operations for inversion (convert to reciprocal), subtraction, multiplication, and division. Write the division operation using inversion, i.e., to divide a number by
x
, multiply the number by the inverse of
x
.
Also add operations for less than, greater than, and equal. These operations do not modify either the object in which they are executing or the argument object. They simply return Boolean (
true
/
false
) values. For these operations, you will have to add prototypes to the .h file as well a implementations to the .cpp file.
Simple Rock, Paper, Scissors
Convert Rock, Paper, Scissors to Prisoner's Dilemma. (You may start with
Simple Prisoner's Dilemma Framework
.) Create an array of
Players
and have them all play against each other. Have the
Players
use a strategy table to determine their moves. Determine the best and worst
Player
and print out the best
Player's
strategy table. Also determine the average winnings.
Simple Prisoner's Dilemma with Population
Add a
Population
Class
to the Prisoner's Dilemma system. Each
Population
object should contain a collection of
Players
. Instead of keeping an array of
Players
in the
main()
function, the
main()
function should have a
Population
variable, which refers to a
Population
object in which the
Players
are kept. Also, instead of determining the winner, loser, and average in the
main()
function, those computations should take place in the
Population
object. Printing the statistics should also occur in the
Population
object. In other words:
Create a
Population
class.
Include a constructor that accepts an integer argument that indicates the number of
Players
in the
Population
. The constructor should create a collection (probably an array, but that is your choice) of as many
Players
as the argument indicates. Each
Player
should be initialized randomly, as we currently do.
Include a
void
playAll(int)
function that plays each
Player
against each other, as we currently do in
main()
. The argument is the number of games to play in each
Match
.
Include a
void
printStatistics(ostream*)
function that accepts as an argument a reference to a file outstream and that then prints statistics to that file outstream. The statistics should be the same as we now compute: the winner, its strategy table and amount won; the least amount won; and the average won by all
Players
.
Midterm
Evolution
Generate a sequence of
Population
objects, each one generated from the previous one by selecting the more successful
Players
to be parents of the next
Population
.
Inheritance
Construct a
PPlayer
class
whose strategy table consists of probabilities instead of 'C' and 'D'. The strategy table entry is the probability that the player will play a 'C' on that move. Modify the
Population
class so that you generate
Populations
of
PPlayers
.
Static declarations
Declare various constants and functions static in the Population, Player, and Match classes.
Final
My home page