Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in C++, assignment begins below dashed line ---- In this lab you will write a program that will list certain cards from a

Please code in C++, assignment begins below dashed line

----

In this lab you will write a program that will list certain cards from a standard deck of playing cards.

The program should begin by prompting the user for a "match word" and reading in that choice.

If the match word is ".", the program should print out the names of all 52 cards from the deck:

  • Suits listed in this order: Clubs, Hearts, Spades, Diamonds.
  • Ranks within each suit: Ace, Two, Three, , Nine, Ten, Jack, Queen, King.

If the match word is the name of a suit or the name of a rank then the program should output only the names of cards that match.

For example, if the user entered "Queen", then just the four queens would be listed. If the user entered "Clubs", then just the thirteen club cards would be listed. If the word entered by the user matches neither suit nor rank, the program should report "(no matches)".

The list of cards should start and end with a "line" of 20 dashes.

Here is the output of some sample runs:

Enter match word ('.' for match all): Jack -------------------- Jack of Clubs Jack of Hearts Jack of Spades Jack of Diamonds -------------------- 
Enter match word ('.' for match all): Three -------------------- Three of Clubs Three of Hearts Three of Spades Three of Diamonds -------------------- 
Enter match word ('.' for match all): Spades -------------------- Ace of Spades Two of Spades Three of Spades Four of Spades Five of Spades Six of Spades Seven of Spades Eight of Spades Nine of Spades Ten of Spades Jack of Spades Queen of Spades King of Spades -------------------- 
Enter match word ('.' for match all): Swords -------------------- (no matches) -------------------- 
Enter match word ('.' for match all): . -------------------- Ace of Clubs Two of Clubs Three of Clubs Four of Clubs Five of Clubs ... Nine of Diamonds Ten of Diamonds Jack of Diamonds Queen of Diamonds King of Diamonds -------------------- 

In this last example, all 52 cards will be listed. It's been shortened here for brevity.

Hints:

1) Output a newline after reading the user input.

2) Use an outer loop for the suits, and an inner loop for the ranks.

3) Within the loops, assign a string to the suit name and another to the rank name and if the keyword matches either, print it out

4) Use switch statements to set name variables based on the loop variables.

5) Skip printing the card name when it does NOT match the user's word.

6) You might want to count the matches, so you know when none have matched.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago