Question

The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing it
0 0
Add a comment Improve this question Transcribed image text
Answer #1

0 clang version 7.0.0-3-ubuntu rand() % 4; rand() % 13; 12 13 14 15 16 17 18 19 20 21 22 int main) 23 24 r clang++-7 -pthread

#include <iostream>
#include <cstdlib>

using namespace std;

void shuffleCards(char **cards, char suit[4], char face[13]) {
        short deck[4][13] = {{0}, {0}};

        int r, c;
        for(int i=0; i<52; i++) {
                do {
                        r = rand() % 4;
                        c = rand() % 13;
                } while(deck[r][c] != 0);
                deck[r][c] = 1;

                cards[i][0] = suit[r];
                cards[i][1] = face[c];
        }
}

int main() {
        char suit[4] = {'S', 'H', 'D', 'C'};
        char face[13] = {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};

        char **cards = new char*[52];
        for(int i=0; i<52; i++) {
                cards[i] = new char[2];
        }

        shuffleCards(cards, suit, face);

        for(int i=0; i<52; i++) {
                cout << "Card " << (i + 1) << " is "
                        << cards[i][0] << cards[i][1] << endl;
        }
}

plz plz upvote. Thanks!

Add a comment
Know the answer?
Add Answer to:
The following program simulates shuffling a deck of cards. (The line numbers are not ) part of the code). Without changing its functionality, rewrite the program by replacing the 2D array card [5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

  • (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...

  • Java Write a complete program that implements the functionality of a deck of cards. In writing...

    Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...

  • 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...

  • C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playi...

    C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playing cards contains 52 cards. There are four suits (heart, diamond club +, spade+) and thirteen ranks (ace, 2 thru 10,jack, queen, king) per suit. Rank Numeric Value 10 10 10 10 gueen 10 Write a program that does the following: I. Simulates a randomized shuffling of a 52 card deck 2. Determines how many combinations of 21 exist in the deck by following...

  • Please help in answering these questions: 1 Line 92 deck is a calling parameter. The received...

    Please help in answering these questions: 1 Line 92 deck is a calling parameter. The received number of that parameter is what? copy of original value pointer 2 Line 92, src is a calling parameter. The received number of that parameter is what? copy of original value pointer 3 Line 95 is a debugging technique where the computer prints what it is doing. Give the line number of a similar line in the example 99 101 108 113 4 Line...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • bblem deals with playing cards. The Card API is given below: public class Card ( suit...

    bblem deals with playing cards. The Card API is given below: public class Card ( suit is "Clubs", "Diamonds", "Bearts", or "Spades" Gene=ination s 2", , "10" יי", ,"פ" ,"8" ,"ר" , "6" ,"5י ,-4" ,"ני- * or "A * value is the value of the card number if the card denominat, *is between 2 and 10; 11 for J, 12 for Q, 13 for K, 14 for A public Card (String suit, string denomination){} 1/returns the suit (Clubs, Diamonds,...

  • Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...

    Need help with shuffle function and give 8 cards to user and computer from shuffle deck? #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> typedef struct card_s{     char suit;     int face;     struct card_s *listp; } card; void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) {     thisNode->suit = cardSuit;     thisNode->face = cardFace;     thisNode->listp = nextLoc;     return; } void card_insertAfter(card* thisNode, card* newNode) {     card* tmpNext = NULL;    ...

  • Java programing Write a program that deals a deck of card into 4 hands – Each...

    Java programing Write a program that deals a deck of card into 4 hands – Each hand having 13 cards. The program should be doing the followings use an array to randomly select 52 cards and deal it into 4 hands. Print each hand unsorted Identify the face value of each hand and display it. You should create a class called Card, and all the methods should be defined within the card class. Hints – Import below java utility to...

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