CIS247C Lab 2 – Black jack game – Solution Include Visual studio code and word document including uml, 6 screenshots and code – Instant delivery – Perfect Solution

Lab Price = $9
Please feel free to send us your queries at: [email protected]
Payment methods

Add to Cart

Buy Now

View Cart


Problem Statement
Week 2: Lab Overview
TABLE OF CONTENTS

Lab Overview
Scenario/Summary
The purpose of this lab is to practice creating classes and objects from those classes. We will create a small game.
• Blackjack
o Use a Card class
To add a class in Visual Studio, watch the follow video for a step by step walkthrough:
Deliverables
You will create a Blackjack game. Copy the Visio UML class diagram, C++ source code, and screen shots into a single Microsoft Word document. Remember to hold down the Alt key when you make your screenshots so that only the active window gets copied to the clipboard.
Required Software
Microsoft Office: Word
Use a personal copy, or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site.. You can get a personal copy through the Student Software Store.
Final Step (submitting your lab)
Visio
Use a personal copy, or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site.. You can get a personal copy through the Student Software Store.
Step 1
Visual Studio 2015
Use a personal copy, or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site.. You can get a personal copy through the Student Software Store.
Steps 2–8

Please Note: you can get a personal copy of Visio, Visual Studio 2015 and many other software packages through the Student Software Store. Follow these steps:
* Log in to your course in Canvas.
* Click on the Modules button on the left side.
* Click on Course Resources in the Introduction & Resources section (top).
* Scroll down to the Student Software Store section and click the Access Software Store button.
* Click on the Microsoft Imagine Premium tab, which is located just below the Product Search box.
* Click on the item(s) that you want and click the Add to Cart button.
* Follow the on-screen instructions to Check Out and Download your software! If the product has a license key, be sure to save it in case you need to reinstall the product.

Lab Steps
Step 1
Create the UML class diagram for the Card class. You will need to keep track of the suit, face, and value of each card that you create. The suit and face should be character data types, and the value should be a short data type. Remember to hide your data! In addition, you will need a default constructor, toString( ) method, and a flipAceToOne( ) method.
Do you need help? Remember, the more that you get done without help, the more you will learn. If you absolutely need help, watch this video.
Part 1 (Links to an external site.)Links to an external site. – Part 2 (Links to an external site.)Links to an external site. – Part 3 (Links to an external site.)Links to an external site.
Step 2
Create the C++ project, and call it Week 2—Lab (BlackJack). Then, welcome the user, and show them their starting cash amount.
• Create a cash variable (short data type), and initialize it to 100 (i.e., give it an initial value of 100).
• Display welcome message.
• Display starting cash amount.
• Pause the application.
Help:
Transcript (Links to an external site.)Links to an external site.
Step 3
Create an application loop that runs until the user enters 3. Show the menu, and get the user’s choice. Then, run code based on the user’s choice.
• Create choice variable that is a short data type.
• Start a do loop that runs while choice does not equal 3.
• Inside of the do loop do the following.

o Display a menu.
1) Play a hand
2) Show current cash balance
3) Exit
o Get the user’s choice.
o Create a switch block that runs based on the user’s choice. Use stubs for the cases (output messages only). This is called Stubs Programming.
o Pause the application so the user can read the messages.
Help:
Transcript (Links to an external site.)Links to an external site.
Step 4
Now, let’s do some object-oriented programming! Wouldn’t it be great if we could create a Card blueprint and then use the Card blueprint to create as many Card objects as we wanted? In software development, the blueprint is called a class! You created a Card UML class diagram in Step 1. Now, let’s realize the class diagram. In other words, let’s take the class diagram to code.
• Create a Card class using a header file and an implementation file (two files).

o Hint: On the menu bar, click Project and then Add Class.
• Create a private section and a public section in the Card class.
• In the private section, create your attributes (suit, face, value). These variables are called instance variables, and each object will have unique copies.
• In the private section, create a class-wide variable called randomizerSeeded as a boolean data type.
o When you use the static keyword, C++ creates a single variable in memory, and all Card objects share that one variable.
• You need to set the initial value for the static variable in the implementation file at the top (before all method implementations). Add this line of code at the top of your implementation file.

bool Card::randomizerSeeded = false;

• In the public section, create a default constructor prototype. In the implementation file, code the default constructor. The default constructor should do the following.
o Seed the randomizer only once. If randomizerSeeded is false, seed the randomizer, and then set randomizerSeeded to true.
o Set suit to a random number from 3 to 6. ASCII values 3 to 6 represent the heart, diamond, clubs, and spade characters.
o Create a random number from 2 to 14, and then set face and value to appropriate values based on the random number that was generated.
 2 to 9 generated: Set face to the number character (add 48 and then typecast to a character), and set value to the number.
 10 generated: Set face to T and the value to 10.
 11 generated: Set face to J and the value to 10.
 12 generated: Set face to Q and the value to 10.
 13 generated: Set face to K and the value to 10.
 14 generated: Set face to A and the value to 11.
• In the public section of the header file, create a toString( ) prototype. In the implementation file, code the method to return the suit and face combined into one string.
• In the public section of the header file, create a flipAceToOne( ) prototype. In the implementation file, code the method to flip the A value to one, if possible.

o When called, the method checks to see if the value is exactly equal to 11. If it is, then the value is set to 1.
• In the public section, create accessors only (get methods only) for the attributes. You can create in-line methods in the header file as these methods are so small. Because we have accessors only, the attributes are read only. The variables cannot be changed outside of the class. The variables are hidden because they are private, and the outside world can only read the variables through the accessors (get methods).
Help:
Part 1 (Links to an external site.)Links to an external site. – Part 2 (Links to an external site.)Links to an external site. – Part 3 (Links to an external site.)Links to an external site. – Part 4 (Links to an external site.)Links to an external site.
Step 5
We are going to use a resizable array for the dealer’s cards and the player’s cards. The resizable array is just like a regular array, but the size is increased automatically when you add items. The resizable array has code built into it that takes care of the memory management for you. All of the items are created sequentially in memory, just like a regular array; however, when you put in too many items, a regular array crashes. A resizable array, on the other hand, simply grows bigger automatically.
The resizable array is called an ArrayList in many languages. In C++, the resizable array is called a vector. If you want to learn more about the vector, do a Google search with the words “C++ vector”: http://lmgtfy.com/?q=C%2B%2B+vector (Links to an external site.)Links to an external site.
• Create a showCards( ) method that receives a vector that holds Card objects and then shows the cards on one line.
o Create a prototype for the method above the main method and below the includes section.

string showCards( vector cards );
o Below the main method, create the showCards( ) method that loops through each card and returns a single string with the values. Here is the code to show you how the vector works.

/// Show the cards in the vector
string showCards( vector cards )
{
string output = “”;
for each ( Card c in cards )
{
output += c.toString( ) + ” “;
}

return output;
}
• Create a sumCardValues( ) method that receives a vector that holds Card objects and then adds up the values for the cards.
o Create a prototype for the method above the main method and below the includes section.

short sumCardValues( vector cards );
o Below the main method, create the sumCardValues( ) method that loops through each card and returns a sum of the card values.
Help:
Part 1 (Links to an external site.)Links to an external site. – Part 2 (Links to an external site.)Links to an external site.
Step 6
It is time to create the playHand( ) method. This method should accept the cash variable as a parameter. Now, let’s think about it. The cash variable needs to change in the playHand( ) method. When the player wins, we give the player more cash. When the player loses, we take cash away from the player. How do we set up the parameter so that the variable changes in the method where it is called? Google search these terms: “C++”
• Create a prototype for the playHand( ) method above the main method and below the includes section.
• Below the main method, create the playHand( ) method.
o At the top of the method, create two resizable arrays that can hold Card objects. Remember, the resizable array is called a vector in C++. The first resizable array should be called dealerCards, and the second resizable array should be called playerCards.
o Create two variables. One will hold the player’s total for all cards. The second one will hold the dealer’s total for all cards.
o Create a bet variable and get the bet amount from the player.
o Create two Card objects for the dealer, and add them to the dealer’s resizable array. You can use the push_back method to add the card to the vector.
 Wasn’t that cool! The Card objects randomly create their own suit, face, and value. You can create as many Card objects as you want using the Card class. Anytime we want to see the suite, face, or value, we can use the dot operator to access the Card object’s information.
o Use the sumCardValues( ) method to add up the values for the dealer’s cards into the dealer’s total variable.
o Display the dealer’s first card only. Can you display the first card using the resizable array? Remember, the resizable array is a standard array under the hood. That means that you can access the objects in the array using the index position: dealerCards[0].toString( )
o Create two Card objects for the player, and add them to the player’s resizable array.
o Use the sumCardValues( ) method to add up the values for the player’s cards into the player’s total variable.
o Use the showCards( ) method to display the player’s cards.
o Give cards to the player until they choose to stand.
 Create an answer variable that is character data type.
 Create a do loop that runs while the answer does not equal S.
 In the do loop, ask the player if they want to hit or stand.
 If the answer is H, do the following.

 Create a Card object, and show it to the player.
 Put the card in the player’s resizable array.
 Add up the player’s card values using the sumCardValues( ) method.
 If the player’s total is more than 21, go through each of the cards and look for a value of 11. If you find one, use that card’s flipAceToOne( ) behavior because aces can have a value of 11 or 1 as needed.
 If you find an ace, tell the player that they exceeded 21, but you found an ace that was converted to a 1 value.
 If the player’s total is now less than 21, break out of the loop.
 Show the player’s cards using the showCards( ) method.
 Show the player’s total card value.
 If the player’s total card value is greater than 21, set the answer variable to S so that the do loop ends.
 Now, we need to check to see if the player busted, and, if not, then deal cards to the dealer.
 If the player’s card total is greater than 21, tell the player that they busted, and take their bet amount away from their cash.
 Otherwise, deal cards to the dealer until the dealer hits 17 or greater.
 Create a Card object, and show the card.
 Show all of the dealer’s cards using the showCards( ) method.
 Add up the dealer’s cards using the sumCardValues( ) method, and then show the total.
 Check to see if the player wins.
 If the dealer’s card total is greater than 21, state that the dealer busted, and increase the player’s cash by the bet amount.
 Otherwise, if the dealer’s card total is greater than the player’s card total, state that the dealer wins, and subtract the bet amount from the player’s cash.
 Otherwise, if the player’s card total is greater than the dealer’s card total, state that the player wins, and add the bet amount to the player’s cash.
 Otherwise, state that the player pushed the dealer (tied).
• Find the switch block in the main method. In the case 1, call the playHand( ) method, and give it cash as a parameter.
Help:
Part 1 (Links to an external site.)Links to an external site. – Part 2 (Links to an external site.)Links to an external site. – Part 3 (Links to an external site.)Links to an external site. – Part 4 (Links to an external site.)Links to an external site.
Step 7
Let’s test the program.
• Run the program, and test it. How does it play? Does the cash increase when the player wins? Does the cash decrease when the player loses?
• Put a breakpoint in the Card class inside of the default constructor. Step through the code until the suit, face, and value variables have been set. Now, use the Immediate window to change these values to whatever you want so you can test your application. For example, set the suit to 3 (heart), the face to A, and the value to 11.
• Put a breakpoint in the playHand( ) method, and step through it so that you can verify that this method is working correctly.
Help:
Part 1 (Links to an external site.)Links to an external site. – Part 2 (Links to an external site.)Links to an external site.
Step 8
Create a Word document called Week 2 Lab. At the top, put your information, including your name, course, Week 2 Lab, and the date.
Copy and paste your UML class diagram from Step 1 into the Word document.
Run your application. Take screenshots while your application is running to demonstrate that it works properly. Remember to hold down the Alt key and the PrtScrn key at the same time (Alt + PrtScrn) to take screenshots of the active window only. Paste these screenshots into your Word document below the UML class diagram.
Put the file name for each file in the Word document below the screenshots. Bold the file name, and increase the font. Copy and paste the code for each file below its file name. You should have three files for your project.
Submit the Word document to the Week 2 Lab page underneath Assignments.
PreviousNext

Relevant Material
Screenshots
Lab 2: You Busted
Lab 2: You Busted
Lab 2: UML Diagram
Lab 2: UML Diagram
Lab 2: Dealer Busted
Lab 2: Dealer Busted
Instructions
* If you want to purchase multiple products then click on “Buy Now” button which will give you ADD TO CART option.Please note that the payment is done through PayPal.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Privacy Policy
We take your privacy seriously and will take all measures to protect your personal information.
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
Refund Policy
Incase you face any issues with the tutorial, please free to contact us on [email protected]
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.
Payment Details
Lab Price = $9
Please feel free to send us your queries at: [email protected]

Payment methods

Add to Cart

Buy Now

View Cart

Leave a Reply