Question

In: Computer Science

Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer...

Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer help and guidance on this subject

can someone help he with part 4 i have no idea how to approach the problem and how to do it

I have compeleted a few parts to this project they are listed below

Part 1 – Displaying Cards Write a function to display (print) a card. sample program output void displayCard(int card) Prints the name of the card (ten of spades, queen of diamonds etc.). The parameter should be a value between 1 and 13, from which the type of card can be determined (1 = ace, 2 = two, …, 10, == ten, 11 = jack, 12 = queen, 13 = king). The card suit (clubs, diamonds, hearts or spades) should be determined randomly.

Part 2 – Generating Cards Write a function to get a card. int getCard() Returns a random value between 1 and 13, representing a card (ace, 2, …, queen, king). You do not have to keep track of which cards are dealt. So, if the game deals the queen of spades five times in row that is perfectly acceptable.

Part 3 – Determining a Cards Score Write a function to return a card's score. int cardScore(int card) Returns a value between 2 and 11 as described in the rules. Recall that the score is the card's value except that aces are worth 11 and face cards are worth 10. The card parameter represents the card for which the score is to be determined.

Part 4 – Dealing Cards Now that you've completed Parts 1 and 2 you can write a function that handles dealing cards. int deal(bool isPlayer, bool isShown) This function is responsible for: 1. Generating the next card to be dealt (Part 1) 2. Printing out what card was dealt (Part 2) and to whom, if needed (see below) 3. Returning the card's score (Part 3) The two Boolean parameters are related to printing out the card. The isPlayer parameter is used to determine whether the word PLAYER or DEALER should be printed at the start of the output. The isShown parameter is used to determine if the card should be printed – recall that the second card dealt to the dealer is hidden.

MYCODE

#include

#include

#include

#include

using namespace std;

void displaycard(int card, int suits){

string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };

cout << cardtype[card];

string suit[4]={" hearts"," diamonds"," spades"," clubs"};

cout << suit[suits];

}

int getcard(){

int card;

card = rand()%13;

return card;

}

int getsuit(){

int suits;

suits = rand() % 4;

return suits;

}

int cardScore(int card)

{

if (card == 11 || card == 12 || card == 13)

{

card = 10;

}

else if (card == 1)

{

card = 11;

}

else

{

card = card;

}

return card;

}

int deal(bool isPlayer, bool isShown){

int cardWhom;

int dealer;

if (cardWhom == true||dealer == true ){

cout << "PLAYER"<< endl;

}

else {

cout << "DEALER" << endl;

}

}

int main(){

srand((unsigned)time(0));

return 0;

}

Solutions

Expert Solution

#include<bits/stdc++.h>
using namespace std;

void displaycard(int card, int suits){

string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };

cout << cardtype[card];

string suit[4]={" hearts"," diamonds"," spades"," clubs"};

cout << suit[suits];

}

int getcard(){

int card;

card = rand()%13;

return card;

}

int getsuit(){

int suits;

suits = rand() % 4;

return suits;

}

int cardScore(int card){

int score;
if (card == 10 || card == 11 || card == 12)
score = 10;

else if (card == 0)
score = 11;

else
score = card+1;

return score;

}

int deal(bool isPlayer, bool isShown){

 int card = getcard();
 int suit = getsuit();
 
 
 if(isShown){
        
    displaycard(card,suit);
 }
 
 if(isPlayer){
        
        cout<<setw(16)<<"To Player"<<"\n";
 }
 else{
        
        cout<<setw(16)<<"To Dealer"<<"\n";
 }
 
 
 cout<<"Card Score"<<setw(14)<<cardScore(card)<<"\n";
 
 

}

int main(){

srand((unsigned)time(0));


cout<<"Welcome to BlackJack"<<"\n";
bool startWithPlayer=true;
bool showPlayerCards = true;
bool showDealerCards = true;

while(1){
        cout<<"\n";
        cout<<"To deal press 1"<<"\n";
    cout<<"To quit press 0"<<"\n";
        int c;
        cin>>c;
        cout<<"\n";
        
        switch(c){
                
                case 1:{
                        if(startWithPlayer)
                        deal(startWithPlayer,showPlayerCards);
                        else
                        deal(startWithPlayer,showDealerCards);
                        startWithPlayer = startWithPlayer^1;
                        break;
                }
                case 0:{
                        cout<<"Thank you for the wonderful game"<<"\n";
                        return 0;
                        break;
                }
                default:{
                        cout<<"Please enter valid input"<<"\n";
                        break;
                }
        }
        
        
}

return 0;

}

Related Solutions

hello, I was wondering if I can see an example of a statistics prop1ztest. and a...
hello, I was wondering if I can see an example of a statistics prop1ztest. and a bit more information about when to use it.
This is a Python project and I´m wondering if anyone has a simple solution for this?...
This is a Python project and I´m wondering if anyone has a simple solution for this? Write a program, move.py, which asks the user for the position of a virtual character on the x-axis in a coordinate system and then allows the user to move the virtual character to the right or left, indicated by the characters 'r' or 'l'. The user should be able to move the virtual character as often as he/she wishes, but if the input is...
(JAVA) I was wondering if anyone can check if I am implementing this method correctly based...
(JAVA) I was wondering if anyone can check if I am implementing this method correctly based on the instructions? Here are the instructions: buildShape(String input) In the buildShape() method, you will parse the provided input to determine whether to create a CircleShape or SquareShape. Before you create the shape, you need to determine it's size, location and color. Use TestableRandom to randomly generate an int size ranging from 100-200. Randomly generate an x and y index for its location. X...
Hello, I am wondering how I can determine the direction in which a wave is travelling...
Hello, I am wondering how I can determine the direction in which a wave is travelling given a function I must verify if it first is a solution to the wave equation by finding the partial derivatives then I do not know how to extrapolate the direction and speed of a wave. Thanks
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
Hello, I stuck doing c++ program The program will be recieved from the user as input...
Hello, I stuck doing c++ program The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to...
Hello , I have to write a thesis on international trade of agricultural products can anyone...
Hello , I have to write a thesis on international trade of agricultural products can anyone help me find a good topic to talk about please
Hello All, anyone can explain these to me? I. What’s the effect of increasing the capacitance?...
Hello All, anyone can explain these to me? I. What’s the effect of increasing the capacitance? in term of saturation mode II. What’s the effect of decreasing the capacitance? in term of saturation mode III. Does dose saturation mode mean a short circuit? IV. What will happen to the capacitor under saturation mode? V. What's the relationship between the temp and the capacitance? curious to know the answers for these questions
Hello! I am doing an advertisment campaign, I recieved the most vague instructions ever, can anyone...
Hello! I am doing an advertisment campaign, I recieved the most vague instructions ever, can anyone clarify if you have any idea? Step 1: SWOT Analysis for the Advertising Client (20%)  Key communications goals should emerge from this analysis Step 2: Target Market Assignment (20%)  Who, what need, where, when, why client solution and how (solution) Step 3: Brand Identity Assignment (20%)  Key image, message, positioning and rationale supported by Steps 1 &2 Step 4: Promotional Strategy...
Hello, I was wondering if someone could show me the process as to how to answer...
Hello, I was wondering if someone could show me the process as to how to answer this question. The answers were posted by the teacher assistant however I do not actually know how to solve the question: The production function of a firm is given as ? =K 1/2, L1/2 , capital is 200. The rental rate for both labor and capital is 5 and 20. There are total 20 firms that produce the same good. A. Write down the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT