Create a C++ program that will create some routines that will later be used in a
ID: 3760575 • Letter: C
Question
Create a C++ program that will create some routines that will later be used in a "Black Jack" program. Your output on this second part will look something like: Player: Fred total=0 hitLimit=18 AS 2H 3D JC Press any key to continue . . . ****************************************************************** I have provided a blackJackMP6A.h file(see below) that you will need to include in your project. I have also provided a mainMP6A.cpp(see below) that will call the modules in your black jack program. You will provide code for the routines defined in the template below for blackJackMP6A.cpp.
#include "blackJackMP5A.h" // Return the numeric value of the card // two, three, four, five, six, seven, eight, nine return 2,3,4,5,6,7,8,9 respectively // Ace always returns 1 (I know Ace can sometimes be 11 in Black Jack, but this is a simplification) // Jack, Queen, and King returns 10 int cardValue(Card & card) { //*****Place your code here } // Return a string name for the card. Some examples: // AC for the Ace of Clubs // 2D for the Two of Diamonds // 9H for the Nine of Hearts // TC for the Ten of Clubs // JD for the Jack of Diamonds // QH for the Queen of Hearts // KS for the King of Spades string cardName(Card & card) { //*****Place your code here (same as on previous question) } // Shuffle a Deck structure. Make sure you set the "nextCardToDeal"=0 void shuffleDeck(Deck & deck) { //*****Place your code here } // Return the card at the index of "nextCardToDeal", then increment this index by one. Card getNextCard(Deck & deck) { //*****Place your code here } // Print out the Deck of cards void printDeck(Deck & deck) { //*****Place your code here } // Fill in the Deck with one of each possible card. This is done by looping through // all of the "Suit" values and all of the "CardID" values (i.e. 2 nested loops) // Although it shouldn't happen, you might want to check to make sure you don't // exceed "NUM_CARDS_IN_DECK" void initializeDeck(Deck & deck) { //*****Place your code here } #include <iostream> #include <iomanip> #include <string> using namespace std; enum Suit {Club, Diamond, Heart, Spade, NumSuits}; enum CardID {ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, NumFaceValues}; struct Card { Suit suit; CardID cardID; }; const int MAX_PLAYER_CARDS = 5; struct Player { string name; int cardsReceived; Card pCards[MAX_PLAYER_CARDS]; int hitLimit; int totalValue; }; string cardName(Card & card); void printPlayer(Player & player); #include "blackJackMP6A.h" // Fill in the players names and hitLimits. You don't need to do anything here. void initializePlayers(Player players[], string names[], int hitLimits[], int numPlayers) { for (int i=0; i < numPlayers; i++) { players[i].name = names[i]; players[i].hitLimit = hitLimits[i]; players[i].cardsReceived = 0; players[i].totalValue = 0; } } void addCard2Player(Player & player, Suit s, CardID ci) { Card card; card.suit =s; card.cardID = ci; player.pCards[player.cardsReceived] = card; player.cardsReceived +=1; } int main() { // Set up the players const int numPlayers = 5; Player players[numPlayers]; string names[numPlayers] = {"Fred", "Ben", "Shark", "Raymond", "Dealer"}; int hitLimits[numPlayers] = {18, 17, 16, 18, 17}; initializePlayers(players, names, hitLimits, numPlayers); addCard2Player(players[0], Spade, ace); addCard2Player(players[0], Heart, two); addCard2Player(players[0], Diamond, three); addCard2Player(players[0], Club, jack); printPlayer(players[0]); }
Explanation / Answer
Sample code:
blackjack.h
blackjack.cpp