Question

I want to have a C++ program that simulates Black jack game with 2 players using vectors along wi...

I want to have a C++ program that simulates Black jack game with 2 players using vectors along with the betting amount. The out put must clearly show the suit and value of cards on the console which was dealt to each player and dealer. and then calculate to check who is the winner. repeat the dealing 5 times.
Code should be clearly sperated into header files, .cpp files and the main.cpp that calls the functions of the respective class.

The output window should show clearly the deck of cards
the shuffled deck of cards Example : Ace of Spades, King of Hearts
Should show each cards dealt to the dealer and player and then the checking for winner.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

enum card_suit{
   S, H, D, C //Spades,Diamonds,Hearts,Clubs
};

int MIN_BET = 5; //Minimum bet is $5

struct account{
   string name; //The name on the account
   string email; //the email address registered to this account
   string username; //the username of this account
   string password; //pasword for the account

   int money; //in case they decide to quit playing when they come back their money will be there may not use this but we'll see

  
   int wins; //games stats
   int total_played; //game stats
   double win_percentage; //game stats
};

struct card{ //how the cards are stored
   int value; //value of the card
   card_suit suit; //suit of the card we have. Not really that important in this game but might as well have it
   bool up; //for the dealer since one card is face down
};

struct player{ //basis of each player in the game including the dealer
   account info; //player's account info
   vector<card> hand; //the players hand
   int bet; //how much the user is betting
   int insurance_bet; //if they take the insurance
};

//prototypes
card deal();
card hitMe();
int score(vector<card>);
bool hasAce(vector<card>);
void printCards(vector<card>);
char printSuit(card);
void doubleDown(player, player&);
int winner(player, player&);
void payout(player, player&);
void split(player&, player&);
void bet(player&);
void insurance(vector<player>&);
account load();
void save(player);
account create();
void play(vector<player>&);
void clear(vector<card>&);
void dealer_play(player&);
void displayMenu();
void displayRules();

int main(){
   unsigned int time_seed = time(0); //so we can get a random number
   srand(time_seed); //seeding the random number
   player user; //creates a player called user
   player dealer; //creates the dealer
   vector<player> players; //creates a vector of players
   char input; //for the Input

   dealer.info.username = "Dealer"; //sets up the dealer info
   players.push_back(dealer); //puts the dealer in the vector

   int menu; // so we can take in input

   do{
       displayMenu(); //displays the menu
       cin >> menu; //take in the user input

       if(menu == 1){ //if the user wants to read the rules
           displayRules(); //displays the rules
       }
       else if(menu == 2){ //if the user wants to play
               cout << "How many players(1 or 2)" << endl; //asks how many players
               int numPlayers; //so we can take in how many players
               cin >> numPlayers; //takes in the input
               for(int i = 0;i< numPlayers;i++){ //cycles through the players
                   cout << "Are you a new player(N) or existing player(E)?" << endl; //asks if they are a new or existig player
                   cin >> input; //takes in their input

                   if(input == 'N' || input == 'n'){ //if they are new
                       user.info = create(); //creates new account info
                       save(user); //saves the player
                       players.push_back(user); //pushes the player on the vector
                   }
                   else if(input == 'E' || input == 'e'){ //if they are a existing player
                       user.info = load(); //loads their account info
                       players.push_back(user); //pushes them on the stack
                   }
          
               }
       }
       else{ //if the user can't follow directions
           cout << "Please enter 1 or 2" << endl; //reiterates their only options
           menu = 0; //resets menu
           cin.ignore(); //ignores what's in the buffer
       }
   }while(menu != 2); //while they don't choose play we will repeat this until we finish the never ending story
  
   bool cond = false; //so we can ask if they want to continue
   int size = players.size();
   do{
       for(int i =1;i<players.size();i++){
           if(players[i].info.money < 5){ //checks to see if they player has any money if not they can add more
               cout << players[i].info.username << " is currently out of money. Would you like to add some, yes(Y) or (N)?" << endl; //Lets them know they are out of funds and if they want to add some
               cin >> input; //takes in input
               if(input == 'Y' || input == 'y'){ //if they say yes
                   cout << "How much would you like to add?" << endl; //how much
                   cin >> players[i].info.money; //takes it in
               }
               else{ //if not we save their info and leave
                   save(players[i]); //saves info
                   players.erase(players.begin() + (i)); //erases player from vector
                   i--;

               }
           }

           if(cond && players.size() > 1){//if they have played at least once
               cout << players[i].info.username << " Would you like to keep playing(P) or quit(Q)" << endl;
               cin >> input; //takes in input
               if(input == 'q' || input == 'Q'){ //player want to quit
                   save(players[i]); //saves info
                   players.erase(players.begin() + (i)); //erases player from vector
                   i--;
               }
           }
       }
       play(players); //and we play
       cond = true; //they finished one hand
   }while(players.size() > 1);
   //!(input == 'q' || input == 'Q')

   return 0;
}
//RuleDisplay
void displayRules(){
   cout << "The rules of blackjack are fairly simple and your only opponent in the game is the dealer. Each player is dealt a two cards face up while the dealer only has one card face up. The goal is to have your two cards added total to be higher than the dealer’s two cards and under 21. If you go over 21 you “bustâ€, or lose, or if the dealers two cards added together are higher than yours you also lose.   If your two card total is equal to the dealers then it is a “stand-off†or a tie. Cards values are usually face value, 2 is 2 and 10 is 10, while all face cards, jack/queen/king, are also 10. The only exception to this rule are Aces, they can take on the value of 1 or 11. To get your two cards total you simply add your two cards together. If you have any combination of an Ace or any card that is 10 points then you have what is called blackjack, 21 pts. Getting blackjack means you get paid more if you win. With all of that being said if you’re not satisfied with your two card total then you can take extra cards, called taking a hit, and for each hit you get you get one more card. The dealer does this as well but has a strict set of rules to follow on whether or not to take a hit. If a dealer’s hand is less than or equal to 16 or a “soft†17, meaning they have an ace and a 6, they must take a hit. If it’s 17 or higher the dealer must stand. So now that we know the dealer rules there are a few options for users. As I stated earlier you can take hits to increase your card total. You may also split your cards and double down. Splitting can be done when your first two cards are of equal value and can only be split from the original hand, split hands cannot be split, the bet has to be equal or greater than the original bet for each hand. For each time you split you will receive and additional card for that hand and then you play like regular blackjack. Users may also double down which consists of a user placing another bet of equal or lesser value when their first two cards total is equal to 9, 10, or 11 without aces. After doubling down you will only get one additional card. Some of you may have realized that if the dealer gets a blackjack or 21 you pretty much always lose, unless you yourself have blackjack. There is a way around this and it’s called insurance. If the dealer is dealt an ace face up then the dealer will ask if you want to take out insurance, equal to half of your original bet, to insure your hand if the dealer has blackjack and only when he has blackjack and helps insure you don’t lose money if he does have blackjack, insurance pays 2 to 1 so your insurance bet will cover the loss of your hand if you bet half." << endl; //displays the rules
}
//MenuDisplay
void displayMenu(){
   cout << "Welcome to the game of Blackjack!" << endl; //output
   cout << "Please select an option below." << endl; //output
   cout << "1) Rules" << endl; //output
   cout << "2) Play" << endl; //output
}
//Dealer_rules
void dealer_play(player &dealer){
   if((score(dealer.hand) < 17) || (score(dealer.hand) == 17 && hasAce(dealer.hand))){ //dealer hits at less than 17 and on soft 17
       dealer.hand.push_back(hitMe()); //dealer gets a card
   }  
}
//Gameplay
void play(vector<player> &players){
   char input; //for our input

   for(int i =1;i<players.size();i++){ //cycles through the players
       bet(players[i]); //players bet here
       cout << "Money: " << players[i].info.money << setw(10) << "Bet: " << players[1].bet << endl; //display their money and bet amount
   }
  
   //Two cards to each player, one at a time
   for(int i = 0;i< (players.size()*2);i++){
       players[(i%players.size())].hand.push_back(deal());
       if((i%players.size()) == 0 && (i%2) == 0){ //the dealers first card
           players[(i%players.size())].hand[(i%2)].up = false; //is set to false since it's face down
       }
   }
   //Score of each player
   for(int i=1;i<players.size();i++){
       cout << players[i].info.username << " has: " << score(players[i].hand) << setw(10) << endl;
   }

   //Cards of each person
   for(int i =0;i<players.size();i++){
       cout << players[i].info.username << " Cards:" << endl;
       printCards(players[i].hand);
   }
  
   //Actual playing
   bool cont = true; //we will use this
   for(int i = 1;i<players.size();i++){ //we cycle through all the players since each player plays on their own
       do{
           if(players[0].hand[1].value == 1 && cont){ //if the dealer has an ace and cont is true - basically this only happens the first time if the dealer doesn't have blackjack
               insurance(players); //asks player if they want insurance
               if(score(players[0].hand) == 21){ //checks to see if the dealer has blackjack - we know the first card is an A
                   players[0].hand[0].up = true; //if they do we set the first card to face up
          
                   printCards(players[0].hand); //prints the dealers cards
                  
                   //Payout
                   for(int i =1;i<players.size();i++){
                       payout(players[0],players[i]);
                   }
                   input = 'S'; //sets input to stay since they just lost
               }
               cont = false; //if the dealer didn't have blackjack this is now false
           }
           if(players[0].hand[1].value >= 10 && cont){ //if the dealer has a 10 or face card showing we don't check for insurance but if they have blackjack that's game
               if(score(players[0].hand) == 21){ //if they have blackjack
                   players[0].hand[0].up = true; //puts the dealers first card face up

                   printCards(players[0].hand); //prints the dealers card
                   /**
                       The below function pays out the players since they just lost
                   */
                   for(int i =1;i<players.size();i++){
                       payout(players[0],players[i]);
                   }
                   input = 'S'; //input is now S since the players lost                  
               }          
               cont = false; //if the dealer doesn't have 21 we don't care about this anymore
           }
           //PlayerScore<21
           if(score(players[0].hand) <= 21){
                   /**
                   The most complicated first - if they have a pair of 5's they can split, double down, hit, or stay
                   */
                   if(((players[i].hand[0].value >= 10 && players[i].hand[1].value >= 10) || players[i].hand[0].value == players[i].hand[1].value) && players[i].hand.size() == 2 && score(players[i].hand) == 10){
                       cout << players[i].info.username << " score: " << score(players[i].hand) << endl; //shows them their score
                       cout << "Would you like to Double Down(D), split(L),take a hit(H), or stay(S), default is to take a stay?" << endl; //ask them
                   }
                   else if(((players[i].hand[0].value >= 10 && players[i].hand[1].value >= 10) || (players[i].hand[0].value == players[i].hand[1].value)) && players[i].hand.size() == 2){ //if they can split their cards
                       cout << players[i].info.username << " score: " << score(players[i].hand) << endl; //shows them their score
                       cout << "Would you like to split(L) your cards, take a hit(H), or stay(S), default is to take a stay?" << endl; //ask them
                   }
                   else if(players[i].hand.size() == 2 && score(players[i].hand) >= 9 && score(players[i].hand) <= 11 && !(hasAce(players[i].hand))){ //can they double down
                       cout << players[i].info.username << " score: " << score(players[i].hand) << endl; //shows them their score
                       cout << "Would you like to Double Down(D), take a hit(H), or stay(S), default is to take a stay?" << endl; //asks them
                   }
                   else{ //they can't do anything special
                       cout << players[i].info.username << " score: " << score(players[i].hand) << endl; //shows them their score
                       cout << "Hit(H) or Stay(S), default is to take a stay?"; //asks them what they want to do
                   }
                   cin >> input; //takes in the input
                   switch(input){ //what did they choose?
                   case 'L': //they wanted to split
                       split(players[0], players[i]); //we split them
                       printCards(players[i].hand); //reprint their cards in case they forgot
                       break;
                   case 'D':
                       doubleDown(players[0], players[i]); //they double down
                       input = 'S'; //sets input to S since now they are done
                       break;
                   case 'H':
                       players[i].hand.push_back(hitMe()); //we give them one more card for their hit
                       printCards(players[i].hand); //reprint their cards
                       cout << players[i].info.username << " score is now " << score(players[i].hand) << endl; //reprint their score
                       break;
                   default: //this is here for people can't follow directions
                       input = 's'; //input is S
                   }
                   if(score(players[i].hand) > 21){ //if they bust they are done
                       input = 'S'; //so we can quit
                   }
           }
       }while(!(input == 'S' || input == 's')); //we continue doing this until they are want to stay
   }

   dealer_play(players[0]); //now the dealer plays

   players[0].hand[0].up = true; //now the everybody can see the first card
  
   //Shows everybody's score and cards including dealers
   for(int i =0;i<players.size();i++){
       cout << players[i].info.username << " score: " << score(players[i].hand) << " Cards: ";
       printCards(players[i].hand);
   }
   //Everbody's Payout
   for(int i =1;i<players.size();i++){
       if(score(players[i].hand) > 21){ //if the player busted we tell them
           cout << "You busted! ";
       }
       int win = winner(players[0], players[i]); //we figure out who wins
       if(win == 1){
           players[i].info.wins += 1; //if the player wins we add one to their win record
       }
       payout(players[0],players[i]); //we payout everybody
       clear(players[i].hand); //we clear out their hands
       players[i].info.total_played+=1; //adds one to the total played  
   }  

   clear(players[0].hand); //clear out the dealers hand
}
/**
   The below method clears out a players hand
*/
void clear(vector<card> &hand){
   hand.clear();
}
/**
Creates new accounts for new players
*/
account create(){
   account user; //creates a new account
   cout << "What is the username you'd like to use?" << endl;
   fstream input; //so we can take in the input
   string filename; //what file we will open

   /**
       The below method basically checks to see if a username is available by checking to see if the file can even be open
   */
   do{
       cin >> user.username; //takes in the username
       filename = user.username + ".dat"; //adds the extension to the file
       input.open(filename); //opens the file
       if(!input.fail()){ //if it didn't fail the name is taken
           cout << "This username is already taken. Please choose another one." << endl; //we tell the user
       }
   }while(!input.fail()); //repeat until it doesn't fail

   cout << "Please enter a password." << endl; //asks for password
   cin.ignore(); // so cin will work
   getline(cin, user.password); //takes in the line b/c it may be more than one word
   cin.ignore(); //so the next line will wokr

   cout << "Please enter your name." << endl; //asks for the users name
   getline(cin, user.name); //takes it in

   cout << "Please enter your email address." << endl; //asks for email address
   cin >> user.email; //takes it in

   cout << "Please enter how much money you'd like to deposit" << endl; //asks for money
   cin >> user.money; //takes it in

   user.total_played = 0; //sets these to 0
   user.wins = 0; //sets these to 0
   user.win_percentage = 0; //set these to 0

   input.close(); //closes the input stream
   return user; //returns the account
}
/**
   For saving account info for when you're done
*/
void save(player user){
   ofstream output; //output stream
   string filename = user.info.username + ".dat"; //so we know what file to save to

   output.open(filename, ios::out); //we want to erase all previous data

   if(!output){//if we can't open output
       cerr << "Output file will not open and data could not be saved. " << endl;
   }

   double percent = 0; //for the win percentage
   if(user.info.total_played == 0){
       percent = 0; //so we don't divide by zero
   }
   else{
       percent = ((double)user.info.wins/user.info.total_played)*100; //win percentage
   }
   output << user.info.username << endl << user.info.password << endl << user.info.name << endl << user.info.email << endl << user.info.money << endl << user.info.total_played << endl << user.info.wins << endl << setprecision (3) << percent; //writes the data to the file

   output.close(); //closes the output stream
}

/**
For loading account info
*/
account load(){
   string username, password; //so we know what the username and password is
   string filename; //how we will save the data
   account user; //sets up an account so we can take in the data
   ifstream input; //file stream

   /**
       We get the users username and password
   */
   do{
       cout << "What is your username?" << endl; //asks for username
       cin >> username; //take it in
       filename = username + ".dat"; //append the file extension
       input.open(filename); //opens the file //opens the file
   }while(input.fail()); //if it fails to open they probably put in the wrong username so we keep doing this until they get it right

   getline(input, user.username); //take in the username
   getline(input, user.password); //take in the password

   do{
       cout << "What is your password?" << endl; //asks for the password
       cin >> password; //takes it in
   }while(!(password == user.password)); //checks password and keeps checking until the user gets it right
  
   /**
       Takes in all the user info
   */
   getline(input, user.name);
   getline(input, user.email);
   input >> user.money;
   input >> user.total_played;
   input >>user.wins;
   input >>user.win_percentage;
  
   input.close(); //close out the file
   return user; //returns the account info
}
/**
   if the dealer is displaying an Ace it asks all the players if they want to take out insurance
*/
void insurance(vector<player> &players){
   int size = players.size(); //gets the size of the vector
  
   for(int i=1;i<size;i++){
       int bet;
       players[i].insurance_bet = 0;
       if((players[i].info.money-(players[i].bet/2)) >=0){ //can the player even make an insurance bet
           do{
               cin.ignore();
               cout << "How much would you like to bet for insurance, up to " << (players[i].bet/2) << players[i].info.username << "?(0 if you don't want to take out insurance)" << endl; //asks if they want to make an insurance bet
               cin >> bet; //takes it in
           }while(!(bet <= (players[i].bet/2) && bet >=0)); //continues to do this until they input the right stuff

           if(bet != 0){ //did they make a insurance bet
               players[i].insurance_bet = bet; //we have the insurance bet set
               players[i].info.money-=bet; //we take it out of their money pile
           }
       }
   }

   if(score(players[0].hand) == 21){ //the dealer has 21
       for(int i = 1; i<size;i++){
           if(players[i].insurance_bet != 0){ //if they took out insurance
               players[i].info.money+=(players[i].insurance_bet*2); //pays out 2 to 1
               players[i].insurance_bet = 0; //clears out the insurance bet
           }
       }
   }
   else{
       for(int i = 1; i<size;i++){
           if(players[i].insurance_bet != 0){ //if they took out insurance
               players[i].insurance_bet = 0; //clears out the insurance bet
           }
       }
   }  
}

/**
   Asks the user what they would like to bet and returns it
*/
void bet(player &user){
   int bet;
   do{
       cout << user.info.username << endl; //so we know what player is betting
       cout << "How much would you like to bet? (Must be greater than the " << MIN_BET << " and less than " << user.info.money << ")" << endl; //we tell them what they can bet
       cin >> bet; //takes in their bet
   }while(!(bet >= MIN_BET && bet <= user.info.money)); //repeat until they get it right
   user.info.money -= bet; //subtract the bet from their money stock pile
   user.bet = bet; //set their bet
}
/**
   If the user chooses to split their cards
   The split hand is completely played here
*/
void split(player &dealer, player &user){
   player split;
   vector<player> players; //creates a new player for the split
   players.push_back(dealer);
  
   split.bet = user.bet; // takes the extra bet
   user.info.money-= user.bet; //takes out the bet from the user money pile
   split.hand.push_back(user.hand[0]); //takes the first card from the user and gives it to the split player
   split.hand.push_back(deal()); //gives the split person a new card
   user.hand[0] = deal(); //gives the user a new card
   split.info.username = user.info.username;
   players.push_back(split); //pushes the split player onto the vect

   printCards(players[1].hand); //prints out the new cards

   char input; //what the input is
   do{
       for(int i =1;i<players.size();i++){
           if(score(players[i].hand) > 21){ //if they bust
               input = 'S'; //they are done
           }
           else{
               cout << "Hit(H) or Stay(S):"; //otherwise we ask them if they want to take a hit
               cin >> input; //take in their input
           }
           /**
               If they take a hit the below code gives them a new card, prints out their new cards and their new score
           */
           if(input == 'H' || input == 'h'){
               players[i].hand.push_back(hitMe());
               printCards(players[i].hand);
               cout << players[i].info.username << " score is now " << score(players[i].hand) << endl;                          
           }
       }
   }while(!(input == 'S' || input == 's')); //we repeat this until they stop taking hits or bust

   dealer_play(players[0]); //dealer plays now since we need to take care of this now rather than later

   /**
       prints the split players cards and score again
   */
   for(int i =1;i<players.size();i++){
       cout << players[i].info.username << " score: " << score(players[i].hand) << " Cards:" << endl;
       printCards(players[i].hand);
   }

   /**
       payouts the split player
   */
   for(int i =1;i<players.size();i++){
       if(score(players[i].hand) > 21){
           cout << "You busted!"; //tells them they busted
       }
       payout(players[0],players[i]); //plays out the player
   }  
}
   //Typical pay out rules. If the player wins he gets 2 to 1 odds.
void payout(player dealer, player &user){
   if(winner(dealer, user) == 1){ //if the player won
       if(score(user.hand) == 21 && hasAce(user.hand) && user.hand.size() == 2){ //if the player has blackjack it's a 3:2 payout
           user.info.money += ((user.bet*3)/2); //I think this is 3:2 odds
           user.bet = 0; //clears out the bet
           cout << user.info.username << " won!" << endl;
       }
       else{
           user.info.money+= (user.bet*2); //adds the bet to the players stash of cash
           user.bet = 0; //clears out the bet
           cout << user.info.username << " won!" << endl;
       }
   }
   else if (winner(dealer, user) == 0){ //they tied
       user.info.money+= user.bet; //players money goes back to his pile
       user.bet = 0; //clears out the bet
       cout << user.info.username << " tied!" << endl;
   }
   else{ //the dealer won.
       user.bet = 0; //player didn't win so all we need to do is clear out.
       cout <<user.info.username << " lost!" << endl;
   }
}
/**
   Figures out if the dealer or the user won
   returns 1 if the player won
   returns -1 if the dealer won
   returns 0 if they tie
*/
int winner(player dealer, player &user){
   if(score(dealer.hand) == score(user.hand)){ //they had a stand off
       return 0;
   }
   else if(((score(dealer.hand) < score(user.hand)) && (score(user.hand) <= 21)) || (score(dealer.hand) > 21 && score(user.hand) <= 21)){ //user won
       return 1;
   }
   else{ //dealer typically wins
       return -1;
   }
}
   //Double down
void doubleDown(player dealer, player &user){
   int bet; //so we can store the new bet
   do{
       cout << "How much would you like to bet? (Must be greater than the " << MIN_BET << " and less than "<< user.info.money <<")" << endl; //asks how much they want to bet
       cin >> bet; //takes it in
   }while(!(bet > MIN_BET && bet <= user.bet && bet <= user.info.money)); //we repeat this until they get it right

   user.bet+=bet; //add the new bet to the original
   user.info.money-=bet; //takes out their double down bet from the money
   user.hand.push_back(deal()); //gives the user one more card
   payout(dealer, user); //pays out the player based on if he/she won      
}
//Returns Suit
char printSuit(card new_card){
   switch(new_card.suit){
       case 0:
           return 'S';
       case 1:
           return 'H';
       case 2:
           return 'D';
       case 3:
           return 'C';
   }
}

//PrintCards
void printCards(vector<card> hand){
   const string CARD_VALUES[14] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "X"}; //makes it easier to print

   for(int i=0;i<hand.size();i++){
       if(hand[i].up){ //if the hand is face up we print this
           cout << CARD_VALUES[(hand[i].value-1)] << printSuit(hand[i]) << " ";
       }
       else{ //if it's face down we print XX
           cout << CARD_VALUES[13] << CARD_VALUES[13] << " ";
       }
   }
   cout << endl;
}
//If Hand has an ace
bool hasAce(vector<card> hand){
   bool has_ace = false; //For now we say there is no ace in the hand
   for(int i =0;i<hand.size();i++){
       if(hand[i].value == 1){ //we have an ace
           has_ace = true; //so we set this to true
       }
   }

   return has_ace;
}
//UserScore
int score(vector<card> hand){
   int total = 0; //setting up the total value
   for(int i = 0; i<hand.size();i++){
       if(hand[i].value >= 10){ //if it's 10, J, Q, or K
           total+=10; //adds 10 to the toal
       }
       else{
           total += hand[i].value; //adds the value to the total
       }
   }

   if(hasAce(hand) && total <= 11){ //if the hand has an ace and we won't bust
       total+=10; //add 10
   }

   return total; //return the total
}
//gets a new card for the player
card hitMe(){
   return deal(); //add another card to the players hand
}
//Returns a card with random value from 1-13 and
card deal(){
   card new_card; //card we will be returning

   new_card.value = 1 + rand() % 13; //makes sure the random number is between 1 and 13 for the value
   int suit = rand() % 4;
   switch(suit){ //makes sure the random number is between 1 and 4 for the suit
       case 0:
           new_card.suit = S;
           break;
       case 1:
           new_card.suit = H;
           break;
       case 2:
           new_card.suit = D;
           break;
       case 3:
           new_card.suit = C;
           break;
   }

   new_card.up = true; //we'll change it later if it's the dealers face down card

   return new_card; //returning the card
}

Add a comment
Know the answer?
Add Answer to:
I want to have a C++ program that simulates Black jack game with 2 players using vectors along wi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program 4: C++ The Game of War The game of war is a card game played by children and budding comp...

    Program 4: C++ The Game of War The game of war is a card game played by children and budding computer scientists. From Wikipedia: The objective of the game is to win all cards [Source: Wikipedia]. There are different interpretations on how to play The Game of War, so we will specify our SMU rules below: 1) 52 cards are shuffled and split evenly amongst two players (26 each) a. The 26 cards are placed into a “to play” pile...

  • C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification...

    C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....

  • C++ programming: Card game Can same one help me out with a example finsih and working...

    C++ programming: Card game Can same one help me out with a example finsih and working programm ? Program the basis for a card game (as a class card game): ● A card is represented by its suit/symbol (clubs, spades, hearts, diamonds) and a value (seven, eight, nine, ten, jack, queen, king, ace). ● A deck of cards consists of a pile of 32 cards that are completely connected to four players are distributed. ● Implement the following menu: ===...

  • War—A Card game Playing cards are used in many computer games, including versions of such classic...

    War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War:    Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • I need to build the card game of War in C++. It will be a 2...

    I need to build the card game of War in C++. It will be a 2 player game. Each player will have their own deck of 52 cards. 2-10, Jack=11, Queen=12, King=13, Ace=14. Each player will draw one card from their deck. The player with the higher card wins both cards. If the card drawn is the same, then each player will draw 3 cards and on the 4th card drawn will show it. The player that shows the higher...

  • Create A Header file and A CPP File for this we want to simulate drawing cards...

    Create A Header file and A CPP File for this we want to simulate drawing cards from a deck,with or without replacement. With replacement means that the card is placed back in the deck after having been drawn. You will want to design a class that represents a deck of card (52 cards. 13 cards: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) The class is to be called “aDeckOfCards”. And it should generate a...

  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June...

    Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...

  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT