Question
quick easy fix c++ line 212-216 line 253 Deck line 280Dekc getting errors, please help#include #include using namespace std; class Card { private: char rank,
quick easy fix c++
line 212-216
line 253 Deck
line 280Dekc
getting errors, please help#include
#include
using namespace std;
class Card {
private:
char rank, suit;
public:
Card();
Card(char r, char s);
void setCard(char r, char s);
int getValue();
void showCard();
};
Card::Card() {
rank = suit = ' ';
}
Card::Card(char r, char s) {
rank = r;
suit = s;
}
void Card::setCard(char r, char s) {
rank = r;
suit = s;
}
int Card::getValue() {
if (rank == 'A') {
return 1;
}
else if (rank == '2') {
return 2;
}
else if (rank == '3') {
return 3;
}
else if (rank == '4') {
return 4;
}
else if (rank == '5') {
return 5;
}
else if (rank == '6') {
return 6;
}
else if (rank == '7') {
return 7;
}
else if (rank == '8') {
return 8;
}
else if (rank == '9') {
return 9;
}
else if (rank == 'K') {
return 10;
}
else if (rank == 'Q') {
return 10;
}
else {
return 10;
}
}
void Card::showCard() {
cout << rank << suit << ".";
}
class Deck {
private:
Card deck[52];
int cardsCnt;
public:
Deck();
void refreshDeck();
Card deal();
void shuffle();
int cardsLeft();
void displayDeck();
};
Deck::Deck() {
char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' };
char suits[] = { 'S','H','D','C' };
int k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++)
{
deck[k++] = Card(ranks[j], suits[i]);
}
}
cardsCnt = 52;
}
void Deck::refreshDeck() {
char ranks[] = { 'A','1','2','3','4','5','6','7','8','9','J','Q','K' };
char suits[] = { 'S','H','D','C' };
int k = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++)
{
deck[k++] = Card(ranks[j], suits[i]);
}
}
cardsCnt = 52;
}
Card Deck::deal() {
Card c = deck[cardsCnt - 1];
cardsCnt--;
return c;
} void Deck::displayDeck() { for (int i = 0; i < 52; i++) { deck[i].showCard(); } }
void Deck::shuffle() {
srand(0);
for (int i = 0; i < cardsCnt; i++)
{
int r = i + (rand() % (52 - i));
Card temp = deck[i];
deck[i] = deck[r];
deck[r] = temp;
}
}
int Deck::cardsLeft() {
return cardsCnt;
}
int main() { int A; while (true) { cout << "Welcome to Solitaire Prime! 1. A New Deck 2) Display the Deck 3) Shuffle the Deck 4) Play the Solitaire game 5) Exit the game Enter choice: "; cin >> A; switch (A) { case 1: deck.refreshDeck(); cout << " Now New deck is created "; break; case 2: cout << " Deck: "; deck.displayDeck(); cout << endl; break; case 3: deck.shuffle(); cout << " Shuffled deck created "; break; case 4: playGame(); break; case 5: cout << " Thank you for playing!!! "; exit(0); break; default: cout << " Incorrect choice, Please try again "; break; } cout << endl; } } void playGame() { cout << deck.cardsLeft() << endl; int piles = 0, sum = 0; stack
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