SWEN-250

C++ - Stack with Playing Cards

Overview

This exercise requires you to write C++ code that will implement a LIFO stack using a deck of playing cards

In this exercise you will be provided some starter files

  • You will need to write the software to meet the requirements (below)
  • You are provided a Makefile
  • You are provided a test program as part of the Makefile
Requirements

You will write code which will perform the following stack functions for difference card types (Face cards and 'Pip' cards)

  • Push (push a card onto the stack)
  • Pop (pop a card from the stack)
  • Peek (just look at the top card; the stack doesn't change)
  • Count (return how many cards are in the stack)
You are provided class definitions in Card.h and Deck.h. You will note that there is base class, and two derived classes (PipCard and FaceCard). Read the explanations of each class and function so you understand what needs to be implemented. Do not change the class definitions, since the test code (also provided) assumes those definitions. Implement in the .cpp files. You can split up into multiple files if you wish, but you will need to update the Makefile.

Instructions
  1. Download the zipfile:
  2. stacked_deck.zip
  3. Read the files and comments
  4. You will finish implementation of the C++ classes based on Card.h and Deck.h
    • You do not need to change the code in Test.h/Test.cpp, but review for your learning
  5. Implement the code for the functionality described in the requirements
  6. Build the code using make
  7. Test the code by typing ./test or valgrind ./test. This will run your executable from the command line.
  8. Check the results to see what passes/ fails. Note that Test5, in particular, requires you to run valgrind.
      We recommend working incrementally. After you add the skeleton code to get 'make' to work, work one test at a time. Review the test code itself, if you need to understand what the test is looking for.
Submission
  • No submission - this is for practice