Question

C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...

C++

Purpose: To practice arrays of records, and stepwise program development.

1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int.
2. In main(), declare an array with space for 52 records, representing a deck of playing cards.
3. Define a function called initialize() to initialize a deck of cards. It will take an array as a parameter, but will return nothing. You need to store the 13 cards of each of the four suits ('H','D','S',or 'C') in this array, but the order of the cards is not too important. In main(), call your function, giving it your array as input.
4. Stop here, to build and run your program. You may not know whether it is working yet, but it should build and run before going on.
5. Define a function called displaySingleCard() to display a single playing card. Your function should take a record, and display the value and the suit, as follows: The values 2-10 are displayed as numbers. The value 1 should be displayed as A (the "ace"), and the values 11,12,13 should be displayed as J, Q, K ("jack", "queen", "king"), respectively. Display the value first, and then the suit. Here are some examples: 5D AC 10H JH QS. Don't use endl in your function here.
6. Define a function called displayCards() to display an array of playing cards (it should call the previous function, displaySingleCard() repeatedly). Your function should take an array and its size as parameters, and it should display all the cards in the array on a single line in the console. Note that this function can be used to display a full deck (52 cards), or the hand of a player (see part 6 below). You should display the value and the suit as in the following example of a 5 card hand: 5D AC 10H JH QS
7. Demonstrate and test your program so far by calling your function displayCards() in main() on the entire deck. Make sure to check the console to see that you have every card of every suit!
8. Define a function to randomly shuffle the cards in the deck. One way to randomly shuffle the elements of an array is to repeatedly generate two random offsets for the array, and swap the two elements at those offsets (you can use the expression (rand() % 52) to create a random offset into a full deck of cards). If this random swapping is done a lot of times (a few hundred for a deck of 52 cards), then you will have a fairly random ordering of the cards at the end.
9. Demonstrate and test your program by calling your shuffle function in main() on the entire deck, and using your display function in main() to show the shuffled deck. Make sure to check the console to be sure that you still have every card (and that nothing got lost in the shuffle).
10. Declare arrays to store a "hand" of cards for 4 players, assuming each player receives 5 cards. To store each player's hand, you could have a single one-dimensional array for each player that contains the cards in their hand; or you could use a two-dimensional array that has an array of cards for each player.
11. In main(), "deal out" (i.e., copy) the cards from your shuffled deck to each player's hand, and display the 4 players' hands to the console as if at the start of a game. You should use your function from part 4 above to do most of the display work. For example, you might display this: Player 1: 5D 10H QS 8C JH Player 2: JC 2H 8D AS 9C Player 3: 7H 6H 9H 10S 8H Player 4: QD JD QC KH JC
12. Write a function that will find the best card in a player's hand. The best card is the card with the highest value. For this question, assume that aces are "low", and assume that the suit of a card is irrelevant. You just want to find the highest value. Use your function in main() so that you can display the best card from each player, e.g., Player 1's best card: QS Player 2's best card: JC Player 3's best card: 10S Player 4's best card: KH If there is a tie, it doesn't matter which of the equal-valued cards you display.

What to hand in:
1. Your program in a text file called a8q1.cpp.
2. A text file called a8q1_testing.tex (.rtf or .doc are okay too) demonstrating that your program works, showing the result of tasks 11 and 12 above.

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card...

    (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • Programming Langaue(Python 3) Define a function deal that will shuffle and distribute the 52 playing cards...

    Programming Langaue(Python 3) Define a function deal that will shuffle and distribute the 52 playing cards evenly to two players (26 each) and return a tuple of each player's hand (as a list of values). The function does not need to take in any arguments, and should create the deck of values internally (i.e., you should not need to input the deck of values into the function; you may reuse the statement you developed for part 6.1). You may assume...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card. Face cards count as 10. Player starts with $500. Player places bet before being dealt a card in a new game. New game: Deal 2 cards to each...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...

    Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: • Print every card in the...

  • War—A Card game Playing cards are used in many computer games, including versions of such classic...

    War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War:    Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT