Question

Create A Header file and A CPP File for this we want to simulate drawing cards...

Create A Header file and A CPP File for this

we want to simulate drawing cards from a deck,with or without replacement. With replacement means that the card is placed back in the deck after having been drawn.

You will want to design a class that represents a deck of card (52 cards. 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King)

The class is to be called “aDeckOfCards”. And it should generate a random card drawn out of the deck.

The card should be printable with a string of the form: “Brand-Suit” where the brands are A,2,3,4,5,6,7,8,9,T,J,Q,K and the suits are “S,H,D,C for Spades, Heart, Diamond and Clubs)

You should be able to have statements such as:

// Declare a deck of cards

aDeckOfCards deck;

// Get a random card from the deck

aCard c = deck;// Draw a hand of N cards

Vector<aCard> hand = deck.draw(N);

Using your aDeckOfCards class, simulate the result of drawing 4 hands of 5 cards each (as in playing poker) and show each hand by printing the 5 cards of each hand. You should have a print method for a card so that you can print each card of the hand as in 4-S, K-H, K-D, 3-C, T-H for 4 of SPADE, King of HEART, KING of Diamond,3 of Club and TEN of Heart
0 0
Add a comment Improve this question Transcribed image text
Answer #1

---------File name- aDeck.h-----------

class aDeckOfCards
{
  vector<string> brand = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
  vector<string> suit = {"S","H","D","C"};
  srand (time(NULL));
  string draw()
  {
      int brandIndex = rand()%13;
      int suitIndex = rand()%4;
      string card = brand[brandIndex]+'-'+suit[suitIndex];
      return card;
  }
  void printCards(vector<int> hand)
  {
      for(int i=0;i<hand.size();i++)
      cout<<hand[i]<<", ";
      cout<<endl;
  }
};

------------End of file-----------------

-----------File name- aDeck.cpp-----------------------

#include <bits/stdc++.h>
#include <aDeck.h>
using namespace std;

int main() {
    aDeckOfCards deck = new aDeckOfCards();
    int hands; // no of hands to be played;
    cin>>hands;
    int noOfCardsToDraw;
    cin>>noOfCardsToDraw;
    while(hands--)
    {
        vector<string> hand;
        for(int i=0;i<noOfCardsToDraw;i++)
        {
            string card=deck.draw();
            hand.push_back(card);
        }
        deck.printCards(hand);
    }
    return 0;
}
-----------------End of File-----------------

Add a comment
Know the answer?
Add Answer to:
Create A Header file and A CPP File for this we want to simulate drawing cards...
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
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