Overview

In this lab, you will use a provided Card class to create a simplified game of [Blackjack], where a user draws cards in an attempt to get exactly 21 points. You read a deck of cards in from a input file, and write the game’s results to an output file.

  • Please email me a code related question before class on Thurs 6 Dec.

  • Due Fri 7 Dec 2018 at midnight

Instructions

  • Please fork and edit the following project:

  • Write a card-drawing function:

    1. Take a const reference to a vector of cards (x) and a reference to an integer position index (ipos), and return a Card object (result).

    2. Select the element of x at index ipos, increment ipos, and return the selected card.

    3. After ipos has been incremented, check if ipos equals x.size(). If so, set ipos equal to 0 (i.e., start over in deck).

  • Write a hand-scoring function:

    1. Take a const reference to a vector of cards (x) and a bool (aceHigh), and return an unsigned integer (i.e., a uint).

    2. Add up the the points of each element in x and return their sum.

    3. When scoring each card, pass the aceHigh parameter to the Card points() member function.

  • Write a program that follows the instructions below.

  • Ask 2 different people to play your game.

  • Submit your Repl.it URL and Zip file:

    • Submission Form

    • For this assignment, you do not need to record or submit output from the runs.

Your program should:

  • For each run, count the number of wins, losses, and draws (where a user chooses to stop drawing before reaching 21).

  • Greet the user, ask them for (and store) their name.

  • Create a vectors of Cards (deck)

    1. Read in the file input_deck.txt

    2. Create one card object per line

    3. Add each card to deck

  • Contain an outer while(true) loop (one loop per hand):

    1. Inform the user that a new hand has started

    2. Create a vector of cards (hand)

    3. Use the card-drawing function to select 2 cards from the deck and add them to the hand

    4. Show the user their cards

    5. Ask the user if they want to score aces high or low.

  • Contain an inner while(true) loop:

    1. With the scoring function, score the hand and print the result

    2. If the score exceeds 21, inform the user they’ve lost this hand and break

    3. If the score is exactly 21, inform the user they’ve won and break

    4. Otherwise, ask the user if they want to draw another card.

      1. If yes, draw another card from the deck and continue

      2. Otherwise, break

  • At the end of the outer loop, ask the user if they want to continue playing

    1. If so, continue

    2. Otherwise, break

  • At the end of the program, output the user’s name, total hands played, wins, losses, and draws to the results.txt file.

    • This output should be appended to the file.

Grading

Requirement Points

Program runs, correct implementation

50

User feedback and final output

15

Required runs

15

Code formatting and readability

20