Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions