Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a c++ console app for a class named PlayingCard with its definition in a header file and its implementation in a separate source code

Create a c++ console app for a class named PlayingCard with its definition in a header file and its implementation in a separate source code file.

The data fields for the class should be two strings to represent the rank and the suit (for example rank: "2" of suit: "Hearts"). Include an additional integer field that assigns a numeric value to the rank. Let 2 - 10 be the values 2 - 10, and let Jack, Queen, and King be a value of 10, and let Aces be worth 11. The default constructor should use random number generation to create a random card from a standard 52 card deck. A 2-arg constructor should initialize a card object using a given rank and suit. Use a private method to pull out any common functionality that the 2 constructors share. Include 3 accessor functions for the private data fields.

There are 2 approaches for randomly initializing a card object. You can use constant vectors to store the ranks, suits and values. Then use random number generation to index the vectors. Another approach is to use the random number generation with an if-else-if structure to determine the random ranks, suits and values.

Test the class from main by implementing a simple game of War. The player and computer opponent both start with scores of zero and are each dealt a random card. Whoever has the higher valued card gets the point values for both cards. For a tie, each player gets the value of the own card. The first player to reach 100 points wins. Because their are no decisions to be made by the player, it isn't really a game. Include a simple menu system that allows for 2 options: player vs computer and computer vs computer. The computer vs computer option should print out the entire game, while the player vs computer option should prompt the player for keyboard input in order to draw a card from the deck.

Note: The PlayingCard class only represents a single card. We will implement a Deck class in a future assignment. For the game, it is possible to be dealt the same card multiple times because they are randomly generated.

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Additional Factors Affecting Group Communication?

Answered: 1 week ago