Question: Hello, I need help with this poker game example in C++ (im using xcode on the mac btw) There are two parts for this lab
Hello, I need help with this poker game example in C++ (im using xcode on the mac btw)
There are two parts for this lab example but I only need help with the second part right now. The instructions look long, but i promise its just an overkill explanation from the book's part. **AGAIN** I only need help with the second part that i'll show below. After the pictured instructions, I will provide all the source codes mentioned: card, deck
I need help with game1 and hand please!! As well as game2 and hand please!
-------------------------------------------------------------------------------------------------------------------------
The first page and half is just explanation, then the instructions for part 1 begin with the words " write a program that deals out 10,000 five card hands ..."
/ / card.h
#ifndef _CARD_H
#define _CARD_H
class Card {
public:
// Define types for the suit and value
enum Suit { Diamonds, Hearts, Clubs, Spades };
enum Value { NullCard, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King };
private:
static const char *snames[4];
static const char *vnames[14];
Suit s;
Value v;
public:
// Constructors initialize a card
Card();
Card(Suit newSuit, Value newValue);
Suit getSuit(); // Returns a card's suit.
Value getValue(); // Returns a card's value.
void printSuit(); // Print a card's suit.
void printValue(); // Print a card's value.
void printCard(); // Print a card's suit and value.
};
// Return the next suit or card value in succession
Card::Suit nextSuit(Card::Suit);
Card::Value nextValue(Card::Value);
#endif
-------------------------------------------------------------------------------------------------------------------------
/ / card.cpp
#include
#include "card.h"
using namespace std;
const char * Card::snames[4] = {" Diamonds", "Hearts", "Clubs", "Spades" };
const char * Card::vnames[14] = {" Bad Card", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
Card::Card() {
v = NullCard;
}
Card::Card(Suit newSuit, Value newValue) {
s = newSuit;
v = newValue;
}
Card::Suit Card::getSuit() {
return s;
}
Card::Value Card::getValue() {
return v;
}
void Card::printSuit() {
cout
}
void Card::printValue() {
cout
}
void Card::printCard() {
printValue();
cout
printSuit();
}
Card::Suit nextSuit(Card::Suit s) {
return(s+1 > Card::Spades) ? Card::Diamonds : (Card::Suit) (s+1);
}
Card::Value nextValue(Card::Value v) {
return(v+1 > Card::King) ? Card::Ace : (Card::Value) (v+1);
}
-------------------------------------------------------------------------------------------------------------------------
/ / deck.h
#ifndef _DECK_H
#define _DECK_H
#include "card.h"
const int DECKSIZE = 52;
class Deck {
private:
Card inDeck[DECKSIZE]; // These are private data members and
int nextCard; // can be used only by member functions.
public:
Deck(); // Initialization. Called automatically
// when a Deck variable is declared.
void shuffle(int); // Exchange random pairs of cards.
Card getCard(); // Returns top card from the deck.
void addCard(Card); // Put named card in the deck.
int totalCards(); // Returns number of cards left in deck.
};
#endif
-------------------------------------------------------------------------------------------------------------------------
/ / deck.cpp
#include
#include "deck.h"
Deck::Deck() {
int i;
Card::Suit curSuit;
Card::Value curValue;
nextCard = 0;
for(i = 0, curSuit = Card::Diamonds, curValue = Card::Ace; i
inDeck[i] = Card(curSuit, curValue);
curValue = nextValue(curValue);
if (curValue == Card::Ace)
curSuit = nextSuit(curSuit);
}
}
void Deck::shuffle(int swaps) {
Card temp;
for (int i = 0; i
Classes Lab (Poker) For this assignment you will be given the code for two classes (Card and Deck) representing a set of playing cards. Using these classes, you will write a program, of certain poker hands. game1.h and game1.epp, that calculates the frequency of occurrence Note that while I will give a simple description of each of the classes below, it will not be necessary to understand the code (and at this point I don't expect you to for the classes in order to use the classes in your program. You will only need to understand the interface (member functions) to each of the classes. You should able to compile these classes without modification. In fact, I do not want you be to modify the classes, unless your include statement requires a change from iostream to iostream.h and your compiler does not require a namespace declaration The Card class is defined in card.h and card.epp. These files define a class (data type) for representing individual playing cards. A card can be initialized, inspected, and printed using the following methods: getSuit( getValue () printSuit) printValue() printCard()) Note that the Card class defines enumerated data types to represent the suit and value. You can use these types in your program, but since they are defined within the Card class, you have to use the scope resolution operator to access them. it would be declared: That is, if your program needs to define a variable to contain a card value, Card::Value cvi If you want to assign the value ACE to this variable, you would write: cvCard::ACE: Focus on Page 95 g with C++ int i1 = rand() % DECKSIZE;
int i2 = rand() % DECKSIZE;
temp = inDeck[i1];
inDeck[i1] = inDeck[i2];
inDeck[i2] = temp;
}
}
Card Deck::getCard() {
return(nextCard
}
void Deck::addCard(Card newCard) {
if (nextCard > 0)
inDeck[--nextCard] = newCard;
}
int Deck::totalCards() {
return DECKSIZE - nextCard;
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
