Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Anyone can help me with creating a blackjack game ? everytime i seperate the function and header and main, errors flood the screen i

C++

Anyone can help me with creating a blackjack game ?

everytime i seperate the function and header and main, errors flood the screen i don't know why

use vectors not arrays

You must first create a "struct" named "Card" to represent a playing card. It must have two fields, a rank stored as an int and a suit stored as a string. Since this struct definition will be used in multiple files, you probably would want to create this in its own header file and then include this header in any other file that requires the use of the Card struct.

Before gameplay starts, create a vector of Cards called deck. This vector will hold the current cards to be drawn from. Populate the vector with all 52 card values (Ace of Hearts through King of Spades).

Create a function called printCard() that takes a Card parameter as input and has no output. The function must print "Ace", "Jack", "Queen", or "King" in place of 1, 11, 12, and 13 respectively. The function must print 2-10 for all other respective values.

At this point, print all cards in your vector to ensure you have all 52 cards represented. Once you are satisfied all 52 cards are there, comment out these print statements.

Now, for the most important part, create a function called shuffleDeck that takes a vector of Cards as input. This function randomly selects two cards from the deck and swaps them. This operation must be performed enough times to ensure the entire deck is thoroughly shuffled. To verify the cards have been shuffled, again print all cards in your array. If you are happy with the randomness of the card order, comment out these print statements as well.

Next, create a function called dealNextCard that takes the vector of cards passed by reference as input. The function must return a Card as output. The function must return the card at the back of the deck (i.e., the "top" card in the deck). The function then also needs to remove the last Card from the deck; that is, since we've now "dealt" this card, we don't want to deal it again! Hmm, why do we pass the deck parameter by reference to this function then?

To test our dealing function, create a loop that deals each card and then prints the size of the remaining deck. When you reach the end of the deck and all cards have successfully been dealt once, you can comment out these print statements and continue on.

#Functional Requirements:

Do not use global variables! If you are using a global variable in multiple functions, then you should be passing that variable into the function. If you use global variables, you will lose points so get out of the global variable shorcut habit.

You must declare a Card struct and use Card variables throughout your program and functions.

The user must be inputting strings and you must be comparing string values.

You must use vectors (not arrays) for this assignment.

All functions must be placed in a separate file.

Despite the psuedocode stating "goto step X", your code must not include a literal goto command. You will lose points for using goto. You must structure your loops and conditionals properly to.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago