Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 hand; cout << " Playing The Solitaire game!! "; while (deck.cardsLeft() != 0) { Card c = deck.deal(); sum += c.getValue(); if (isPrime(sum)) { hand.push(c); printStackReverse(hand); hand = stack(); cout << " Prime: " << sum << endl; piles++; sum = 0; } else { hand.push(c); } } if (sum != 0) { printStackReverse(hand); hand = stack(); cout << " Loser "; } else { cout << " Winner in " << piles << " piles! "; } } bool isPrime(int val) { bool prime = true; if (val == 0 || val == 1) { prime = false; } else { for (int i = 2; i <= val / 2; ++i) { if (val % i == 0) { prime = false; break; } } } if (prime) return true; else return false; } void printStackReverse(stack s) { if (s.empty()) return; Card x = s.top(); s.pop(); printStackReverse(s); x.showCard(); cout << " "; s.push(x); }

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

LO1 Summarize the organizations strategic planning process.

Answered: 1 week ago