Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Definition Write a Card class and a Deck class that stores a deck of these Cards. Then, use the Monte Carlo method to determine

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Problem Definition Write a Card class and a Deck class that stores a deck of these Cards. Then, use the Monte Carlo method to determine the odds of receiving at least one pair in a hand of cards. A pair is any two cards with the same rank Recall we used the Monte Carlo method to determine the value of Pl in LAB 1 this quarter. Along with outputting to the terminal the percentage of times a pair is found, your program should also give the user the option to output to a file the contents of each hand and whether it found a pair in that hand. Be sure to reshuffle the deck between each deal (each simulation), Your main function should seed the random function with the seed 2222 Be sure to first implement (AND UNIT TEST!) the Card class first. Then implement (AND UNIT TESTI!) the Deck class. Then implement the hasPair function (AND UNIT TEST!!!) before finally using all of the above to write the program to determine the odds of receiving at least one pair in a hand of cards. Given a random seed of 2222, here is what a sample run of your program will look like in Jupyterlab if the user chooses NOT to output to a file: Do you want to output all hands to a file? (Yes/No) No Enter number of cards per hand: 5 Enter number of deals (simulations): 10000 chances of receiving a pair in a hand of 5 cards is: 49.344 Here is what a sample run of your program will look like in JupyterLab if the user DOES choose to output to a file: Do you want to output all hands to a file? (Yes/No) Yes Enter name of output file: hands.dat Enter number of cards per hand: 5 Enter number of deals (simulations): 10 chances of receiving a pair in a hand of 5 cards is: 400 And the file hands.dat in this case would look like this: 10 of Hearts, Ace of Spades, 6 of clubs, 8 of Spades, Jack of Hearts Found Pair!! Jack of Diamonds, 3 of Diamonds, 2 of Clubs, 2 of Diamonds, 7 of Diamonds Found Pair!! 6 of clubs, Queen of Hearts, 4 of Spades, 2 of Hearts, 6 of Hearts 7 of Spades, 8 of clubs, Queen of Hearts, 10 of Spades, 4 of Hearts Found Pair!! 9 of Hearts, King of Clubs, 5 of Spades, 9 of Diamonds, 6 of Diamonds 9 of Spades, 3 of Spades, 4 of Diamonds, Ace of Hearts, Queen of Diamonds 5 of Clubs, 7 of clubs, 9 of Hearts, Jack of clubs, 8 of Hearts Jack of Diamonds, 4 of Hearts, 6 of Hearts, Queen of Diamonds, 7 of Diamonds Jack of Spades, 7 of Spades, 10 of Diamonds, 5 of clubs, 3 of Clubs Found Pair!! 8 of Clubs, Queen of Hearts, 5 of Hearts, Queen of Spades, 10 of clubs 375598345344 day LAB ACTIVITY 4.14.1: PROGRAM 3: Deck/Card classes w/ file output testing 0/100 Submission Instructions Downloadable files Card.h Deck.cpp main.cpp and Deck. Download Compile command g++ Deck.cpp Card.cpp main.cpp -Wall -Werror - Wuninitialized - We will use this command to compile your code a.out Upload your files below by dragging and dropping into the area or choosing a file on your hard drive. Deck.cpp Drag file here or Choose on hard drive. Card.cpp Drag file here or Choose on hard drive. main.cpp Drag file here or Choose on hard drive Submit for grading (Global Scope) Deck.h X Card.h main.cpp* Card.cpp Deck.cpp* Miscellaneous Files 1 #ifndef DECK H 2 #define DECK_H 3 4 #include 5 using namespace std; 6 7 #include "Card.h" 8 9 class Deck { 18 private: 11 vector theDeck; 12 vector dealtCards; 13 public: 14 y Constructs a Deck of 52 cards: 15 Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King of each suit. 16 Cards should start off in this order with the order of suits being: 17 Clubs, Diamonds, Hearts, Spades. 18 For best efficiency, top of Deck should be stored at 19 back end of vector. 2e 21 Deck(); 22 23 /* Deals (returns) the top card on the deck. 24 Removes this card from theDeck and places it in the dealtcards. 25 As mentioned in comments for constructor, for best efficiency, 26 top card should be at back end of vector. 22 28 Card dealcard(); 29 30 31 /* Places all cards back into theDeck and shuffles them into random order. 32 Use random_shuffle function from algorithm library. 33 This function goes forward through dealtcards pushing each Card 34 onto back end of theDeck, then clears dealtcards. 35 */ 36 void shuffleDeck(); 37 38 39 /* returns the size of the Deck Chow many cards have not yet been dealt). 40 */ 41 unsigned deckSize() const; 42 }; 43 44 tiendif 45 Deck.cpp (Global Scope) Card.h x main.cpp* Card.cpp Miscellaneous Files 1 W/Card interface file 2 #ifndef CARD H 3 #define CARD H 4 5 #include 6 7 using namespace std; class Card { private: char _suit; int _rank; public: /" Assigns a default value of 2 of Clubs Card(); y Assigns the card the suit and rank provided. suits: C - Clubs, d - Diamonds, h - Hearts, 5 - Spades If an invalid suit is provided, sets the suit to Clubs ranks: 1 - 13 (1 = Ace, 11 - Jack, 12 = Queen, 13 = King) If an invalid rank is provided, sets the rank to 2 Accepts lower or upper case characters for suit 7 Card(char, int); 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 /* Returns the card's suit */ char suit) const; /* Returns the card's rank as an integer */ int rank() const; /* Outputs a Card in the following format: Rank of Suit For example, if the rank is 3 and the suit is h: 3 of Hearts Or, if the rank is 1 and the suit is d: Ace of Diamonds Or, if the rank is 12 and the suit is c: Queen of clubs etc. friend ostream& operator 2 #include 3 #include 5 8 9 10 11 12 13 14 15 16 17 18 19 20 21 using namespace std; #include "Deck.h" [#include "Card.h" // Returns true if vector of Cards contains at least 2 cards with the same rank. bool hasPair(const vector &hand); // Sends to output stream a Card's value as: Rank of suit 1// i.e., Ace of Spades ostream& operator &); e int main() { srand(2222); return 0

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

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions