Overview: In this project, you will create a simple card game. At the start of t
ID: 3776067 • Letter: O
Question
Overview:
In this project, you will create a simple card game.
At the start of the game, ask the player his/her name and the amount of money to start.
Each turn of the game then proceeds as follows: The player is asked how much money he/she wants to bet. Then, the player is dealt one card face up. The player is then asked whether the next card dealt will be higher in rank or lower in rank than the first card. If the player guesses correctly, he/she wins an amount equal to the bet. If not (including if the dealt card is of the same rank), the player loses his/her bet. The player cannot bet an amount larger than the amount of money he/she currently has.
The game continues turns until the player either has a balance equal to or above 5 times their start amount, or the player's money is 0.
In order to do this assignment, you must create two user-defined classes, one called Card and one called Player. The definitions of these classes and their member functions should each be contained in separate files called Card.h and Player.h. IMPORTANT: for this assignment, you are turning in three files: the class definitions Card.h and Player.h, as well as hw4.cpp, the source file that creates your program.
Details:
Card class details:
Card class should have two private integers called rank and suit.
It should have a default constructor that initializes the rank to a random value between 1 and 13 and the suit to a random value between 1 and 4.
It should have accessor member functions get_rank(), get_rank_string(), get_suit_string().
get_rank() should return the integer value of the rank.
get_rank_string() should return a string that represents the rank. If the rank is 1, the function should return "Ace". If the rank is 2, the function should return "Two". This trend continues until the rank is 11, in which case the function should return "Jack". If the rank is 12, the function should return "Queen". If the rank is 13, the function should return "King".
get_suit_string() should return a string that represents a suit. One of each of the possible four suit integers should be assigned to "Diamonds", "Hearts", "Spades", or "Clubs", and the function should return the corresponding string.
Player class details:
You must implement a class called Player that stores the person's name, their current balance, and the amount of money they had to start. You are free to implement this class to your own liking (following general guidelines for user-defined classes). You must use this class to store, update, and access a Player's balance.
Example:
An example of console input and output are below. User input is in red.
Player, what is your name? Turkeyface
How much money would you like to start? 500
Turkeyface, you have $500.
How much do you want to bet? 150
You draw a Seven of Clubs.
Will the next card be higher or lower? Enter "h" for higher, or "l" for lower: h
You draw a Seven of Hearts.
LOSE!!! Too bad Turkeyface. You lose $150.
Turkeyface, you have $350.
How much do you want to bet? 250
You draw a King of Diamonds.
Will the next card be higher or lower? Enter "h" for higher, or "l" for lower: l
You draw a Six of Hearts.
WIN!!! Congratulations Turkeyface, you win $250!
Turkeyface, you have $600.
How much do you want to bet? 600
You draw a Nine of Clubs.
Will the next card be higher or lower? Enter "h" for higher, or "l" for lower: l
You draw a Queen of Spades.
LOSE!!! Too bad Turkeyface. You lose $600.
Too bad Turkeyface. You are out of money! You lose.
Note: Be sure to seed your random number generator appropriately so every execution of your program results in different cards being dealt. Your program should not output the exact same cards every time, given the same inputs.
Explanation / Answer
Test class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.