War C Program Classes 1The CardDeck class which will create

War (C++ Program)

Classes:

1)The CardDeck class which will create the deck of cards

2)The Card class which creates cards

The main logic of the program will be in the main class. You will use the Card class and the CardDeck class to play the game.

Here the methods you will need to build. Feel free to add more if you need them.

public class CardDeck

public CardDeck( // constructor which creates a deck of 52 cards

public void displayCardAt(int) // display the card at particular location (array index)

public int deal( ) // deal a card – return the point value of the card

public int cardsLeft( ) // how many cards are left in the deck

public void shuffle( ) // shuffle the cards in the deck

public class Card

public Card (char s, int r ) // constructor to create a card, setting the suit and rank

public int getValue( ) // return the point value of the card. Ace = 1, 2 thru 10, face cards = 10

public void displayCard( ) // display the card

*** Arrays are to be used to implement classes. Not vectors

You will need to provide a menu with the following choices:

1)Get a new card deck

2)Show all cards in the deck

3)Shuffle

4)Play WAR!

5)Exit

Thank you ahead of time.

Solution

#include #include #include #include using namespace std; string suits[4]={\"Hearts\", \"Diamonds\", \"Spades\", \"Clubs\"}; string faces[12]={\"Ace\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"Jack\", \"Queen\", \"King\"}; class Card { public: int face,suit; Card(int face,int suit) { this->face=face; this->suit=suit; } string toString() { string nameSuit = suits[suit]; string nameFace = faces[face]; return nameFace+\" of \"+nameSuit; } }; class DeckOfCards { private: vector deck; int currentLocation, location; public: DeckOfCards() /*create deck*/ { for(int i=0;i<13;i++) for(int k=0;k<4;k++) { Card card(i,k); deck.push_back(card); currentLocation++; } } void shuffle() /*shuffle the deck*/ { for(int i=0;i<52;i++) { location=rand()%52+1; Card holder=deck[location]; deck[location]=deck[i]; deck[i]=holder; } } void dealCard() /*deal the shuffled cards*/ { while(currentLocation >0) { Card returnCard = deck[currentLocation]; returnCard.toString(); currentLocation--; } } bool moreCards() { int size = (int) deck.size(); if(size == 0) return false; else return true; } }; int main () /*main function*/ { DeckOfCards deck; deck.shuffle(); deck.dealCard(); };
War (C++ Program) Classes: 1)The CardDeck class which will create the deck of cards 2)The Card class which creates cards The main logic of the program will be i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site