Question
Hello Learning C++ here. I need to separate my code to .h file and .cpp file. But having trouble doing so. Here is my Code:
Hello Learning C++ here.
I need to separate my code to .h file and .cpp file. But having trouble doing so.
Here is my Code:
#include
using namespace std;
class Card { friend class DeckOfCards; private: int face; int suit; static string faces[13]; static string suits[4]; public: Card() {} Card(int face, int suit) : face(face), suit(suit) {} };
string Card::faces[] = { "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" }; string Card::suits[] = { "Diamonds", "Hearts", "Clubs", "Spades" };
class DeckOfCards { private: Card deck[52]; int currentCard = 51; // last index at deck arr public: DeckOfCards() { int index = 0; for (int suit = 0; suit < 4; suit++) { for (int face = 0; face < 13; face++) { Card newCard(face, suit); deck[index] = newCard; index++; } } } void shuffle() { srand(time(NULL)); for (int i = 0; i < 52; i++) { int random = rand() % 51; Card temp = deck[i]; deck[i] = deck[random]; deck[random] = temp; } } string dealCard() { string str; if (currentCard >= 0) { Card dealCard = deck[currentCard]; str = dealCard.faces[deck[currentCard].face] + " of " + dealCard.suits[deck[currentCard].suit]; currentCard--; } else { throw out_of_range(" No more cards."); } return str; } };
int main() { DeckOfCards cards; cards.shuffle(); bool isRunning = true; while (isRunning) { try { cout < Keep getting error for DeckOfCard.cpp file. Plz help. Thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started