CS120
Assignment #6
Due at midnight on Monday Oct. 20th
For this assignment you will use the card class that you created in lab.
If you did the lab in a team you may use the same team for the assignment.
For the assignment do the following:
-
Write a function that accepts an array of cards and an integer (the size of the array) as arguments and prints each card in the array.
-
Write a function that accepts an array of cards and an integer
(the size of the array) as arguments and randomizes the array.
The easiest way to randomize an array is probably to pick two random
locations in the array and swap their contents. If you do this
repeatedly the array
will end up randimized. Note that to swap two elements of an array you
need to copy
on element to a temporary object, copy the second object to where the
first one
was, and then copy the temporary object to where the second object was
in the array.
Using the two functions you just wrote write a program to do the following:
-
Create an array called deck consisting of the 52 cards found in a normal deck of cards.
The easiest way to do this is to use a pair of nested loops to create the cards in order.
-
Heve the program print the deck.
-
Randomize the deck and have the program print it again to show that it's randomized.
-
Create an array of card objects called hand1 and copy the first five
cards from the deck array into the hand1 array. (You don't need to remove the
cards from the deck array, just use an integer to keep track of where in the
deck the program is.)
-
Create a second array of card objects called hand2 and copy the next five
cards from the deck array into hand2.
-
Print both hand arrays to show that the program works.
-
Extra Credit: Add to the program so that the user can choose up to four
card from their hand to be replaced with four new cards from the deck array (as in draw poker).
Include a block of comments at the beginning of the program
(or add to the existing block) that lists your name (or names if this
was done as a pair programming project), section number, date,
and the assignment number. Also include comments on any parts of the
assignment you didn't finish or on any extra work you did.
Include this comment block at the beginning
of every assignment and lab.
Turn in: Name your code file Assignment7SecX.cpp (where X is your
section number) and turn in the code for your program (the .cpp file,
not a.out) using the
cscheckin command.