Question

Hi! I need help with a C++ program In this assignment, you will create some routines...

Hi! I need help with a C++ program

In this assignment, you will create some routines that will later be used in 
a  "Black Jack" program.  Your output on this first part will look something
like:
 
card's name is QC with a black jack value of 10

Unshuffled Deck
AC/1  2C/2  3C/3  4C/4  5C/5  6C/6  7C/7  8C/8  9C/9  TC/10 JC/10 QC/10 KC/10
AD/1  2D/2  3D/3  4D/4  5D/5  6D/6  7D/7  8D/8  9D/9  TD/10 JD/10 QD/10 KD/10
AH/1  2H/2  3H/3  4H/4  5H/5  6H/6  7H/7  8H/8  9H/9  TH/10 JH/10 QH/10 KH/10
AS/1  2S/2  3S/3  4S/4  5S/5  6S/6  7S/7  8S/8  9S/9  TS/10 JS/10 QS/10 KS/10


Shuffled Deck
3S/3  9C/9  TD/10 TC/10 5D/5  8D/8  KD/10 5H/5  AH/1  5C/5  7D/7  AD/1  JC/10
6H/6  KC/10 QS/10 QC/10 TH/10 2D/2  3H/3  9S/9  6S/6  4S/4  JS/10 4C/4  KH/10
8C/8  TS/10 QH/10 4D/4  AS/1  7C/7  2S/2  8S/8  3D/3  2H/2  9D/9  2C/2  JH/10
4H/4  KS/10 6C/6  5S/5  9H/9  7S/7  3C/3  QD/10 JD/10 6D/6  8H/8  AC/1  7H/7

card(0) =3S with a value of 3
card(1) =9C with a value of 9
card(2) =TD with a value of 10
card(3) =TC with a value of 10
card(4) =5D with a value of 5
...
card(48) =6D with a value of 6
card(49) =8H with a value of 8
card(50) =AC with a value of 1
card(51) =7H with a value of 7
Press any key to continue . . .

******************************************************************
I have provided a blackJack.h file(see below) that you will need to include in your project.  
I have also provided a main.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 blackJack.cpp.

//blackJack.cpp

#include "blackJack.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
}





  

*******************************************************************
You will start with the 2 files:

 //blackJack.h

#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 NUM_CARDS_IN_DECK= 52;

struct Deck
{
    int nextCardToDeal;
    Card dCards[NUM_CARDS_IN_DECK];
};



int cardValue(Card & card);
string cardName(Card & card);
void shuffleDeck(Deck & deck);
void initializeDeck(Deck & deck);
Card getNextCard(Deck & deck);
void printDeck(Deck & deck);
*******************************************************************
//main.cpp


#include "blackJack.h"


int main()
{
    Card card;
    card.suit = Club;
    card.cardID = queen;

    cout << "card's name is " << cardName(card) << " with a black jack value of " << cardValue(card) << endl;

    Deck deck;

    initializeDeck(deck);  // This is your initializeDeck routine (no shuffling necessary).  
    // Note the deck will get shuffled each time playRound is called.

    cout << endl << "Unshuffled Deck "  << endl;
    printDeck(deck); // Print out the sorted deck

    
    shuffleDeck( deck);
    cout << endl <<  "Shuffled Deck " <<endl;
    printDeck(deck); // Print out the shuffled deck

    for (int i=0; i < NUM_CARDS_IN_DECK; i++)
    {
        Card card = getNextCard( deck);
        cout << "card(" << i <<") =" << cardName(card) << " with a value of " << cardValue(card) << endl;
    }



    
}

PLEASE HELP

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;
int main()
{
    int total=0, nAces=0,value=0;
    char c,response;


    do
    {
        cout<<"Enter cards: ";
        cin>>c;//takes input and applies to c
        c=tolower(c);
        if (c=='j' || c=='q' || c=='k')
            value=10;
        else if (c=='a')
            nAces++;
        else
            value=(char)c;

        while (nAces>0)
        {
            if (total+11<=21)
                total+=11;
            else
                total++;
                nAces--;
        }

        if (total>21)
            cout<<"BUSTED!\n";
        else if (value==10)
            cout<<value<<endl;
        else
            cout<<(char)value<<endl;

        cout<<"Enter more cards? (y/n): ";
        cin>>response;
    } while (response=='y' || response=='Y');
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Hi! I need help with a C++ program In this assignment, you will create some routines...
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
  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • I wrote a card shuffle program and I am trying to see how I can add...

    I wrote a card shuffle program and I am trying to see how I can add a sorting function to the program to sort the players hands before printing them. How would I do this? #include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; void printHand(int []); void deal(vector<int> &, int[], int[], int[], int[]); void unwrapDeck(vector<int> &deck) { for(int i=0; i<=51; i++) deck.push_back(i); } void shuffleDeck(vector<int> &deck) { //Status of cards before shuffling cout << "Before shuffling: "...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Java Write a complete program that implements the functionality of a deck of cards. In writing...

    Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...

  • 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...

  • C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data...

    C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand...

    Need help writing this program! Thanks in advance. Project4 Specifications: Determine Poker Hand A poker hand can be stored in a two-dimensional array. The statement: Dim aryintCards(4,14) as Integer (See AryCardExample.xlsx excel spreadsheet) declares an array which the first subscript 1-4 are the four suits and the second subscript ranges over the card denominations: 1-14: Ace, 2, ..., 10, Jack, Queen, King, Ace (repeated). First subscript of 0 is Total of each denomination. Second subscript of 0 is Total of...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! !!!!!!!!!!!!!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!!!!!!!!!!!!!!!!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in new deck order. (This is the order of a deck of cards new from the box.) The 2 Array lists...

  • //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards...

    //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...

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