In case it wasn’t obvious from the name of the lab, the objective of this lab is to emulate a simple, text-based, slightly less complex blackjack game.
value
and a suit
combination of some kind
1
2
Values: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King
Suits: Hearts, Diamonds, Spades, Clubs
so a card could be Ace of Spades, 3 of Clubs, Queen of Hearts – you get the idea.
Clubs | Hearts | Diamonds | Spades | |
---|---|---|---|---|
Ace | AC | AH | AD | AS |
2 | 2C | 2H | 2D | 2S |
3 | 3C | 3H | 3D | 3S |
4 | 4C | 4H | 4D | 4S |
5 | 5C | 5H | 5D | 5S |
6 | 6C | 6H | 6D | 6S |
7 | 7C | 7H | 7D | 7S |
8 | 8C | 8H | 8D | 8S |
9 | 9C | 9H | 9D | 9S |
(so basically just pair the number/letter of the face with the letter of the suit)
If you’ve played blackjack before, you’re probably familiar with the rules already. But you’ll want to read this section so you understand the specific things you’ll need to implement.
Miscellaneous: You’ll need to format your output so that all of the cards are printed in a left-justified field of 20 characters wide:
1
2
3
4
5
6
7
8
9
10
Dealer has cards: KD 3S (13)
You have cards : QD AS (11)
Hit or stand ? hit
Dealer has cards: KD 3S (13)
You have cards : QD AS 6D (17)
Hit or stand ? stand
Dealer hits : KD 3S KS (23)
Dealer busts, player wins!
Here are the example outputs to reference for your own program’s correctness
1
2
3
4
5
6
7
8
9
10
Dealer has cards: KD 3S (13)
You have cards : QD AS (11)
Hit or stand ? hit
Dealer has cards: KD 3S (13)
You have cards : QD AS 6D (17)
Hit or stand ? stand
Dealer hits : KD 3S KS (23)
Dealer busts, player wins!
1
2
3
4
5
6
7
Dealer has cards: 4S 8D (12)
You have cards : 9D 10H (19)
Hit or stand ? hit
Dealer has cards: 4S 8D (12)
You have cards : 9D 10H 10C (29)
Player busts, dealer wins!
1
2
3
4
5
6
7
Dealer has cards: KS 9D (19)
You have cards : 9D 10H (19)
Hit or stand ? stand
Dealer has cards: KS 9D (19)
You have cards : 9D 10H (19)
Player and dealer draw.
1
2
3
4
5
6
7
8
9
10
Dealer has cards: 2S 9D (11)
You have cards : 10D 10H (19)
Hit or stand ? stand
Dealer hits : 2S 9D 9S (20)
Dealer stands : 2S 9D 9S (20)
Dealer has cards: 2S 9D 9S (20)
You have cards : 10D 10H (19)
Dealer wins!
Those should give you what you need to make your program output according to the rubric.
This is the first lab where you’ll be required to use the following function conventions:
1
2
3
4
5
6
7
8
9
10
11
// #1 format: <return type> <function name> (<types & names of any parameters you'll use>)
int my_function(int arg1, string arg2, double arg3);
// #2 format: <return type> <functoin name> (<types of any paramaters you'll use>)
int my_function(int string, double);
// #1 lists paramters with type AND name
// #2 lists paramaters with JUST type
// choose which one you want to use -- it's up to you
The protoype includes no implementation, just the signature followed by a ;
like any other line of code, and it must come before your actual function definition.
1
2
3
4
// adds two integers and returns their sum
int add(int num1, int num2) {
return num1 + num2;
}
The definition comes after the prototype and includes the actual code that it runs when called.
main
) scope e.g
1
2
3
4
5
6
7
8
9
10
11
12
13
14
```cpp
int main() {
/* we're in main, but you can call a function
from anywhere, this is just an example */
// we make two ints
int a = 1, b = 2;
// we "call" add on our two local int variables
int sum = add(a, b);
// sum becomes 3 after the function call
}
```
This one is pretty self explanatory.
You’ll need to write protoypes, definitions, and calls, for the following routines:
function hint
1
2
3
4
return type: string
parameter type(s): string array[52], vector<string>
desciption: randomly choose an undealt card
& assigns it to the player or deale. Returns the card abbreviation as string.
function hint
1
2
3
4
5
return type: int
name: GetRandom
paramter type(s): int, int
desciption: returns a random int between
[min, max] (inclusive)
function hint
1
2
3
4
return type:
name: InitializeCards
paramter type(s):
desciption: fills array of 52 cards with every suit/face combination
function hint
1
2
3
4
return type: new vector of cards i.e. vector<string>
name: whatever you want
paramter type(s): vector<string>
desciption: