CS 162 Spring 2000 Assignment 6 –Vectors with Generic Functions 100 points

Assigned: 03/20/2000

Due: 03/27/2000 at the start of class.

Pre-Lab (Do Before Lab): Bring a disk. Plan out steps needed for program.

Pairs: You may work in pairs if you want. Note, during the course of the semester, you cannot pair with any one person more than twice. If you work in a pair, turn in ONE copy that is the work of both of you, with both of your names on it. Each member of the pair will receive the same grade for that lab. In such a partnership, students must share as equally as possible the work and learning. Working together with truly shared effort and learning can be a positive experience. However, simply giving/receiving code from someone defeats the learning process. If substantial parts of a program are taken from non-partners, that is plagiarism. The copier and copyee will each receive a zero.

Main Assignment:

You will create a main program that uses a vector of cards and performs a number of actions using generic functions in the C++ Standard Template Library. The Card class and Deck class which is also necessary are updated versions of the classes used in the War assignment. They are available on my WWW page under Review or under Assignments. Your main should 1) Create and Shuffle and show the contents of a deck of cards; 2) Define two vectors of cards; 3) Fill each of the two vectors with 5 cards drawn from the deck; 4) Show the hands; 5) Reverse the order of the hands and show them again; 6) Report on the number of face cards (or better) in each hand; 7) sort the two hands, and show the sorted hands; 8) play the last card from each hand, replace the card and re-show the hands. See example below.

Details:

  1. While this main is not useful by itself, it is a step on the way toward a better implementation of the Player class and the war game. More realistic tasks will be possible as you gain experience.
  2. This is an exercise in using generic functions, you must use them and not write your own. Functions exercised in this assignment include: reverse, count_if, sort, and replace. In addition, you will find functions defined for vectors such as: push_back, back, begin, end and probably size useful, along with possibly functions from Card and Deck.
  3. To see all of the output, one way is to run your program from the DOS prompt. Select DOS PROMPT from Programs. Get to the right folder using cd (change directory), type the name of the executable followed by > and the name of a file to put the reults (e.g.

redmond6 > trace-redmo6

then look at the results using NOTEPAD or WORDPAD

Hand-in:

1) Listing of the program

2) Disk with your .cpp file and your working .exe file. NAME YOUR PROGRAM FILES yourlastname6.cpp. Name your project yourlastname6 so that the executable will be yourlastname6.exe. If you are working in pairs, use both last names (e.g. redmondsmith6.cpp)

Miscellaneous:

1) If you have any questions about what should be done, please ask!!

2) MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Test it more than once - I will!

3) Remember: Indentation, meaningful variable names, symbolic constants, and meaningful comments. Weaknesses in any of these could result in points off. Also make sure you put YOUR NAME(s), section, and e-mail address in comments at the beginning of the program.

Sample Interaction:

Deck is shown for debugging and checking

Deck: (size 52): Jack of Spades | 3 of Diamonds | 6 of Hearts | 3 of Spades | 5 of Spades | 6 of Diamonds | 7 of Spades | 8 of Hearts | 7 of Hearts | 2 of Diamonds | 5 of Clubs | 4 of Spades | 3 of Hearts | 8 of Clubs | 4 of Diamonds | King of Hearts | 3 of Clubs | 9 of Clubs | 4 of Hearts | 8 of Diamonds | Queen of Clubs | Queen of Diamonds | Jack of Hearts | King of Spades | Ace of Clubs | 10 of Hearts | 2 of Clubs | King of Diamonds | 10 of Spades | 5 of Diamonds | 10 of Clubs | 2 of Hearts | Jack of Diamonds | Queen of Hearts | 4 of Clubs | 7 of Clubs | 6 of Spades | Ace of Spades | 10 of Diamonds | 8 of Spades | King of Clubs | 2 of Spades | Jack of Clubs | 9 of Hearts | Queen of Spades | Ace of Hearts | 7 of Diamonds | 6 of Clubs | 5 of Hearts | 9 of Spades | Ace of Diamonds | 9 of Diamonds |

Hand1:

9 of Diamonds

9 of Spades

6 of Clubs

Ace of Hearts

9 of Hearts

Hand2:

Ace of Diamonds

5 of Hearts

7 of Diamonds

Queen of Spades

Jack of Clubs

Hand1 reversed:

9 of Hearts

Ace of Hearts

6 of Clubs

9 of Spades

9 of Diamonds

Hand2 reversed:

Jack of Clubs

Queen of Spades

7 of Diamonds

5 of Hearts

Ace of Diamonds

Hand 1 has 1 face cards

Hand 2 has 3 face cards

Hand1 sorted:

6 of Clubs

9 of Hearts

9 of Spades

9 of Diamonds

Ace of Hearts

Hand2 sorted:

5 of Hearts

7 of Diamonds

Jack of Clubs

Queen of Spades

Ace of Diamonds

Hand 1 played: Ace of Hearts

replaced with: 2 of Spades

Hand 2 played: Ace of Diamonds

replaced with: King of Clubs

Hand1:

6 of Clubs

9 of Hearts

9 of Spades

9 of Diamonds

2 of Spades

Hand2:

5 of Hearts

7 of Diamonds

Jack of Clubs

Queen of Spades

King of Clubs