CS120
Lab #7
Due at the end of lab.
This is a pair programming lab. You may work in pairs if you want.
If you do work in a pair you may also do Assignment 7 as a pair assignment.
Make sure to put both of your names in the comments at the beginning of the
lab, and assignment, programs.
If you are working in a pair be sure to take turns at the keyboard.
When creating the class alternate between each function.
For this lab you will be creating a card class. The goal of this class is to
create objects representing a single playing card.
Card objects should have the following data members:
- A rank - represented by an integer from 1 to 13.
-
A suit (i.e., clubs, diamonds, hearts, spades) -
which you may represent however you want. Common options are
an integer from 0 to 3; an integer from 1 to 4; or a string storing the actual word.
The class should also have the following function
memebers (methods):
- A constructor that doesn't take any arguments and sets the rank
and suit of a card to a non-sensical default value, for example, the -1 of "no suit".
- A constructor that takes two arguments, rank and suit, and
creates a new card object with that rank and suit.
- A set function that takes a rank and suit as arguments and sets
the card object to have that rank and suit. The set function should make sure
that the rank and suit are valid before setting them. E.g. it should not set
a card to have a rank of 27.
- A random function that takes a card and assigns it a random rank
and suit.
- A cheat function that changes a card object to be the Ace of Spades.
- A print function that prints a card object. It should print cards
with a string like "The X of Y" where X is the rank and Y is the suit.
Aces, kings, queens, and jacks should be printed as such. E.g. it should print
"The Jack of Spades" not "The 11 of Spades".
Test your class by writing a main program that:
- Uses nested loops to print a "deck" of cards in order from the two of clubs up to the ace of spades.
- Generates and prints a "hand" of five random cards (for now it will be okay if two of the cards happen to be identical).
Include a block of comments at the beginning of the program
(or add to the existing block) that lists your name, 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 Lab7SecX.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.