Question

In: Computer Science

How to do a blackjack game with the following rules and WITHOUT USING ARRAY Part 1...

How to do a blackjack game with the following rules and WITHOUT USING ARRAY

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.


Part 5 – Playing a Hand
Parts 1 to 4 should be enough to get you started, and the detailed instructions end here. Your next function should be to play a hand of Blackjack, following the rules described above.
int playhand()
Responsible for playing a hand of Blackjack. Returns 1 if the player won, -1 if the player lost and 0 if the player drew (magic number alert).
There is quite a lot that goes into this function, and it is the heart of the assignment. I would strongly recommend breaking it down into other functions that implement the various phases of a hand of Blackjack.


Part 6 – Game Loop
In your main function (or in another function called by main) write a loop to ask the user if they want to play Blackjack, as shown in the sample program output. The user should continue to play hands of Blackjack until they choose to quit (enter a character other than 'y').
Your program should keep track of whether the user wins, loses or draws a hand (see the return value of the hand function) and print a summary of these results when they exit the program.
The random sequence for the game must not be the same each time it is played.


User Input and Program Output
Assume that the user enters correct input (lowercase 'y' to play a hand, and lowercase 'h' or 's' to hit or stand) – but see Extras.
Your output, wording, spacing and so on may differ from the samples shown above. To receive full marks, it must correctly describe the game and must be at least as pretty as mine (not that mine is particularly pretty).

Solutions

Expert Solution

Part 1 answer: Following are the snapshot of the above program in c language. In the above question language is not mentioned. To run the below program the user needs to write it on the c programing editor.

Output: The snaposhot of the output of the above program for the input value of 11 is :-


Related Solutions

C program simple version of blackjack following this design. 1. The basic rules of game A...
C program simple version of blackjack following this design. 1. The basic rules of game A deck of poker cards are used. For simplicity, we have unlimited number of cards, so we can generate a random card without considering which cards have already dealt. The game here is to play as a player against the computer (the dealer). The aim of the game is to accumulate a higher total of points than the dealer’s, but without going over 21. The...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both...
Design a c++ program to simulate the BlackJack game. Rules: 1) single deck, 52 cards -both player and dealer are taking cards off the same deck (the same 52 values). 2) display BOTH cards of the players, and ONE card of the computer. 3) Check for blackjack (starting value of 21 for computer or player) -if either side has a blackjack end of the game, next hand of blackjack 4) Computer must hit if 16 or below. 5) Computer must...
Is there a way to do this without the binomial probability? Consider the following game: You...
Is there a way to do this without the binomial probability? Consider the following game: You roll six 6-sided dice d1,…,d6 and you win if some number appears 3 or more times. For example, if you roll: (3,3,5,4,6,6) then you lose. If you roll (4,1,3,6,4,4)then you win. What is the probability that you win this game? The answer is 119/324
1. In the game of blackjack as played in casinos in Las Vegas, Atlantic City, Niagara...
1. In the game of blackjack as played in casinos in Las Vegas, Atlantic City, Niagara Falls, as well as many other cities, the dealer has the advantage. Most players do not play very well. As a result, the probability that the average player wins a hand is about 0.29. Find the probability that an average player wins A. twice in 5 hands. Probability = B. 11 or more times in 26 hands. Probability = There are several books that...
Discuss the Classical Gold Standard and critically explain how following “the rules of the game” creates...
Discuss the Classical Gold Standard and critically explain how following “the rules of the game” creates a price-flow mechanism capable of correcting international payments imbalances. Word Count (500 words)    
java program that coverts base13 to decimal. without using array and methods.
java program that coverts base13 to decimal. without using array and methods.
Rewrite your program for part 1. Do not declare the array globally, declare it in the...
Rewrite your program for part 1. Do not declare the array globally, declare it in the loop function. This now requires that you add two parameters to your fill array and print array functions. You must now pass the array name and array size as arguments, when the program calls these functions. The program has the same behavior as problem 1, but illustrates the difference between globally and locally declared variables. The program code for part 1 was: int Array[15]...
What are the rules of the game in The capitalist economy and how did they develop?
What are the rules of the game in The capitalist economy and how did they develop?
Using the below question and values how do you calculate the standard deviation without using a...
Using the below question and values how do you calculate the standard deviation without using a calculator (by hand) of (s1^2/n1+s2^2/n2) with the standard deviation answer being 1.4938 and 1.1361 /sqrt(1.4938^2/10 + 1.1361^2/10) Choose two competing store and compare the prices of 10 items at both stores. Preform a two-sample hypothesis test to try an prove if one store is more expensive than the other based on your sample. Store A item #1-$5.49, #2 $3.77, #3 $0.87, #4 $3.29, #5...
Imagine we are using a two-dimensional array as the basis for creating the game battleship. In...
Imagine we are using a two-dimensional array as the basis for creating the game battleship. In the game of battleship a '~' character entry in the array represents ocean (i.e., not a ship), a '#' character represents a place in the ocean where part of a ship is present, and an 'H' character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, a ship with all 'H' characters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT