Assignment 8
Due Tuesday, October 25 at 3:20pm on Catalyst

Assignment 8.1: Playing Cards (10 pts)
  • This will be one of the most challenging assignments you will do in this class, so get started early!
  • Open up a new C++ file in CodeBlocks and name it cards.cpp.
  • Add the necessary structure to your C++ program (block comments, iostream library, standard namespace, and a main() function)
  • Make sure you have correct indentation.
  • The goal of this program is to take in user input describing a playing card in the following shorthand notation:
A                    Ace
2....10            Card Values
J                    Jack
Q                   Queen
K                    King
D                    Diamonds
H                    Hearts
S                    Spades
C                    Clubs
  • Your program will take in as user input a shorthand notation for a single card.
  • Your program will then output the full description for that card.
  • See the sample output below:
Enter the Card Notation: QS
You Entered: Queen of Spades
  • Here is another sample output:
Enter the Card Notation: 4H
You Entered: 4 of Hearts
  • To accomplish the goals of this program, you will need to use if statements, else if statements and an else clause.
  • There are two approaches to the program
    • Complete the program using 52 if statements (one for each of the possible value and suit combinations of the playing cards). For example, your 52 if statements will include the one below:
if (input == "QS") {
   cout << "You entered: Queen of Spades\n";
} else if (input == "QH")
    cout << "You entered: Queen of Hearts\n";
    • OR, Complete the program with fewer if statements, making use of the substr(i,n) and length() functions
  • Both approaches work, and you may choose whichever option makes better sense to you.
  • Important note: The tricky part will be to handle the 10 correctly.
  • When you are finished, upload your cards.cpp program to Catalyst.

Example set of 52 playing cards; 13 of each suit clubs, diamonds, hearts, and spades

Ace 2 3 4 5 6 7 8 9 10 Jack Queen King
Clubs Ace of clubs 2 of clubs 3 of clubs 4 of clubs 5 of clubs 6 of clubs 7 of clubs 8 of clubs 9 of clubs 10 of clubs Jack of clubs Queen of clubs King of clubs
Diamonds Ace of diamonds 2 of diamonds 3 of diamonds 4 of diamonds 5 of diamonds 6 of diamonds 7 of diamonds 8 of diamonds 9 of diamonds 10 of diamonds Jack of diamonds Queen of diamonds King of diamonds
Hearts Ace of hearts 2 of hearts 3 of hearts 4 of hearts 5 of hearts 6 of hearts 7 of hearts 8 of hearts 9 of hearts 10 of hearts Jack of hearts Queen of hearts King of hearts
Spades Ace of spades 2 of spades 3 of spades 4 of spades 5 of spades 6 of spades 7 of spades 8 of spades 9 of spades 10 of spades Jack of spades Queen of spades King of spades

image source