CS206 Data Structures

Programing Assignment#2

Due on Tuesday, February 13, 2007

Problem: Do Exercise 9 from Chapter 1 of Miller & Ranum.

Create a class called, Card that models a single playing card. It has a suit: Clubs, Diamonds, Hearts, Spades; and a rank: 1-13 (or Ace, 1, 2, ..., 10, Jack, Queen, King). The following operations should be defined for cards:

  1. A constructor (__init__)
  2. suit() : Returns the suit of the card.
  3. rank() : Returns the rank of the card.
  4. __str__(): A print method

Then, define another class called, CardDeck with the following operations:

  1. A constructor (__init__): That creates a new, sorted deck of 52 cards.
  2. __str__(): A print method
  3. shuffle(): Shuffles the deck
  4. deal(): Deals a single card out of the deck

Write a program that uses these classes to create a deck, print it out, shuffle the deck, print it out, and then deal 5 cards each to two players: print out each player's hand, and the remainder of the deck.

Hand in a printout of your program along with several sample runs of your program.


 

Back to CS206 Materials