I need help with a C++ project. I need to finish the program. The program is supposed to shuffle and deal a deck of cards. Here is what I am given: This is Card.h: #ifndef CARD_H #define CARD_H #include class Card { public: static const size_t FACES{13}; // total number of faces static const size_t SUITS{4}; // total number of suits enum class Face {Ace, Deuce, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King}; enum class Suit {Hearts, Diamonds, Clubs, Spades}; Card(Face cardFace, Suit cardSuit); // initialize face and suit std::string toString() const; // returns a string representation of a Card // get the card's face Face getFace() const { return face; } // get the card's suit Suit getSuit() const { return suit; } private: Face face; Suit suit; static const std::string faceNames[FACES]; static const std::string suitNames[SUITS]; }; #endif   This is DeckOfCards.h: #ifndef DECK_OF_CARDS_H #define DECK_OF_CARDS_H #include #include "Card.h" // DeckOfCards class definition class DeckOfCards { public: DeckOfCards(); // constructor initializes deck void shuffle(); // shuffles cards in deck Card dealCard(); // deals cards in deck bool moreCards() const; // are there any more cards left private: std::vector deck; // represents deck of cards unsigned currentCard; // index of next card to be dealt }; #endif   This is CardDealer.cpp: #include #include #include "DeckOfCards.h" using namespace std; int main() { DeckOfCards myDeckOfCards; myDeckOfCards.shuffle(); // place Cards in random order cout << endl; // print all 52 Cards in the order in which they are dealt for (int i = 1; myDeckOfCards.moreCards(); ++i) { // deal and display a Card cout << left << setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 0) { // output newline every 4 cards cout << endl; } } cout << endl; }   We need to create Card.cpp and DeckOfCards.cpp. No changes are needed to any of the code above. Card.cpp needs to consist of: A constructor that receives two enumeration constants representing the face and suit and uses them to initialize the data members Two static arrays of strings representing the faces and suits to help when using toString() A toString() function that returns the Card as a string in the form of "face of suit" You can use the + operator to concatenate strings DeckOfCard.cpp needs to consist of: An array of Cards named deck to store the Cards An integer currentCard representing the next card to deal A default constructor that initializes the Cards in the deck A shuffle() function that shuffles the Cards in the deck. The shuffle algorithm should iterate through the array of Cards. For each Card, randomly select another Card in the deck and swap the two Cards A dealCard() function that returns the next Card object from the deck A moreCards() function that returns a bool value indicating whether there are more Cards to deal   The Tester program creates a DeckofCards object, shuffles the cards, then deals the 52 cards. No modification needed to the tester.   This is what I currently have for Card.cpp: #include #include #include "Card.h" Card::Card(Face tempFace, Suit tempSuit) {}; static const std::string faceNames[Card::FACES] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; static const std::string suitNames[Card::SUITS] = {"Hearts", "Diamonds", "Clubs", "Spades"}; std::string Card::toString() const{ }   I am really struggling with the toString(). I don't know if I am going in the right direction, either. I also have no idea where to start in DeckOfCards.cpp. If you left notes explaining the code when you are done, that would be great.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question

I need help with a C++ project.

I need to finish the program. The program is supposed to shuffle and deal a deck of cards.

Here is what I am given:

This is Card.h:

#ifndef CARD_H
#define CARD_H
#include <string>
class Card {
public:
static const size_t FACES{13}; // total number of faces
static const size_t SUITS{4}; // total number of suits
enum class Face {Ace, Deuce, Three, Four, Five, Six, Seven, Eight,
Nine, Ten, Jack, Queen, King};
enum class Suit {Hearts, Diamonds, Clubs, Spades};
Card(Face cardFace, Suit cardSuit); // initialize face and suit
std::string toString() const; // returns a string representation of a Card
// get the card's face
Face getFace() const {
return face;
}
// get the card's suit
Suit getSuit() const {
return suit;
}
private:
Face face;
Suit suit;
static const std::string faceNames[FACES];
static const std::string suitNames[SUITS];
};
#endif

 

This is DeckOfCards.h:

#ifndef DECK_OF_CARDS_H
#define DECK_OF_CARDS_H
#include <vector>
#include "Card.h"
// DeckOfCards class definition
class DeckOfCards {
public:
DeckOfCards(); // constructor initializes deck
void shuffle(); // shuffles cards in deck
Card dealCard(); // deals cards in deck
bool moreCards() const; // are there any more cards left
private:
std::vector<Card> deck; // represents deck of cards
unsigned currentCard; // index of next card to be dealt
};
#endif

 

This is CardDealer.cpp:

#include <iostream>
#include <iomanip>
#include "DeckOfCards.h"
using namespace std;
int main() {
DeckOfCards myDeckOfCards;
myDeckOfCards.shuffle(); // place Cards in random order
cout << endl;
// print all 52 Cards in the order in which they are dealt
for (int i = 1; myDeckOfCards.moreCards(); ++i) {
// deal and display a Card
cout << left << setw(19) << myDeckOfCards.dealCard().toString();
if (i % 4 == 0) { // output newline every 4 cards
cout << endl;
}
}
cout << endl;
}

 

We need to create Card.cpp and DeckOfCards.cpp. No changes are needed to any of the code above.

Card.cpp needs to consist of:

A constructor that receives two enumeration constants representing the face and suit and uses them to initialize the data members

Two static arrays of strings representing the faces and suits to help when using toString()

toString() function that returns the Card as a string in the form of "face of suit" You can use the + operator to concatenate strings

DeckOfCard.cpp needs to consist of:

An array of Cards named deck to store the Cards

An integer currentCard representing the next card to deal

A default constructor that initializes the Cards in the deck

shuffle() function that shuffles the Cards in the deck. The shuffle algorithm should iterate through the array of Cards. For each Card, randomly select another Card in the deck and swap the two Cards

dealCard() function that returns the next Card object from the deck

moreCards() function that returns a bool value indicating whether there are more Cards to deal

 

The Tester program creates a DeckofCards object, shuffles the cards, then deals the 52 cards. No modification needed to the tester.

 

This is what I currently have for Card.cpp:

#include <iostream>
#include <string>
#include "Card.h"

Card::Card(Face tempFace, Suit tempSuit) {};

static const std::string faceNames[Card::FACES] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};

static const std::string suitNames[Card::SUITS] = {"Hearts", "Diamonds", "Clubs", "Spades"};

std::string Card::toString() const{

}

 

I am really struggling with the toString(). I don't know if I am going in the right direction, either. I also have no idea where to start in DeckOfCards.cpp. If you left notes explaining the code when you are done, that would be great.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage