Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program to shuffle and deal a deck of cards. The program should consist

ID: 3809593 • Letter: C

Question

Create a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and a driver program. Class Card should provide: a) Data members face and suit of type int. b) A constructor that receives two ints representing the face and suit and uses them to initialize the data members. Class DeckOfCards should contain: a) Two Card objects named deck to store two cards. c) A constructor that takes no arguments and initializes both cards in the deck. You can give these two cards a random face value and suit value, but make sure they are not the same. d) A printCards function that prints the two cards. The driver program should create a DeckOfCards object, and print the cards that this object has. You need to have 5 files in this project: card.hpp, card.cpp, deckofcards.hpp, deckofcards.cpp, main.cpp

Explanation / Answer

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

# define SIZE = 52;
class card
{
public:

card();

card(string cardFace, string cardSuit);

string print();

private:

string face;
string suit;

};


class deckOfCards
{
public:

deckOfCards();
void shuffle();
card dealCard();
currentCard();

private:

card deck[SIZE];

};


{

deckOfCards deck;
deck.shuffle();
for( int i = 0; i <= 2; i++)
{
currentCard = deck.dealCard();

cout << currentCard.print() << endl;

}
return 0;
}

card::card()
{

}

card::card(string cardFace, string cardSuit)
{

face = cardFace;
suit = cardSuit;
}

string card::print()
{

return (face + " of " + suit);
}

deckOfCards::deckOfCards()
{

string faces[] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
string suits[] = {"Hearts", "Diamonds", "Clubs", "Spades"};
deck = new card[SIZE];
currentCard = 0;
for(int count = 0; count < SIZE; count++)
{
deck[count] = card(faces[count % 13], suits[count / 13]);
}

}

void deckOfCards::shuffle()
{

currentCard = 0;

for(int first = 0; first < SIZE; first++)
{

int second = (rand() + time(0)) % SIZE;
card temp = deck[first];
deck[first] = deck[second];
deck[second] = temp;

}
}


card deckOfCards::dealCard()
{
if(currentCard > SIZE)
{
shuffle();
}

if( currentCard < SIZE)
{
return (deck[currentCard++]);
}
return (deck[0]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote