Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pease, I need to complete this program in C++ The file 3card.cpp needs to be completed, The class is already provided You'll find below the

Pease, I need to complete this program in C++

image text in transcribed

image text in transcribed

The file 3card.cpp needs to be completed,

The class is already provided

You'll find below the class card.h and 3card.cpp

File 3card.cpp

#include #include #include #include #include #include #include "Card.h"

using namespace std;

/********************************************************************/ /* */ /* to randomize shuffling of Card arrays */ /********************************************************************/ class MyRandom { public: ptrdiff_t operator() (ptrdiff_t max) { double tmp; tmp = static_cast(rand()) / static_cast(RAND_MAX); return static_cast(tmp * max); } };

void shuffle(Card *deck) { MyRandom rd; random_shuffle(deck, deck+52,rd); }

// Prototypes go here.

bool isAStraight(Card Hand3[]);

// More prototypes go here. You must write them, along with a complete header block

int main(int argc,char **argv) { Card Deck[52]; Card Hand3[3];

// Seed random number generator srand(time(NULL));

if (argc>2) { // Hand is set from command line for (int i=0;i> Hand3[0] >> Hand3[1] >> Hand3[2]) { // CODE GOES HERE } } } else { // Generate deck to deal random hand generateDeck(Deck); shuffle(Deck); // CODE GOES HERE } return 0; }

// fill deck array with one of each card void generateDeck(Card Deck[]) { for (int i = 0; i

// Functions go here

// determine if the hand is a straight bool isAStraight(Card Hand3[]) // Suppose the cards are A B C. // Then we must check for ABC, ACB, BAC, BCA, CAB, and CBA // We must also check for ace low {if (((Hand3[2].getRank()+2)%13)==((Hand3[0].getRank()+1))&& //CAB ((Hand3[0].getRank()+1)%13)==(Hand3[1].getRank()) && (Hand3[1].getRank()==0 || Hand3[1].getRank()>1)) return(true); if (((Hand3[2].getRank()+2)%13)==((Hand3[1].getRank()+1))&& //CBA ((Hand3[1].getRank()+1)%13)==(Hand3[0].getRank()) && (Hand3[0].getRank()==0 || Hand3[0].getRank()>1)) return(true); if (((Hand3[0].getRank()+2)%13)==((Hand3[2].getRank()+1))&& //ACB ((Hand3[2].getRank()+1)%13)==(Hand3[1].getRank()) && (Hand3[1].getRank()==0 || Hand3[1].getRank()>1)) return(true); if (((Hand3[0].getRank()+2)%13)==((Hand3[1].getRank()+1))&& //ABC ((Hand3[1].getRank()+1)%13)==(Hand3[2].getRank()) && (Hand3[2].getRank()==0 || Hand3[2].getRank()>1)) return(true); if (((Hand3[1].getRank()+2)%13)==((Hand3[2].getRank()+1))&& //BCA ((Hand3[2].getRank()+1)%13)==(Hand3[0].getRank()) && (Hand3[0].getRank()==0 || Hand3[0].getRank()>1)) return(true); if (((Hand3[1].getRank()+2)%13)==((Hand3[0].getRank()+1))&& //BAC ((Hand3[0].getRank()+1)%13)==(Hand3[2].getRank()) && (Hand3[2].getRank()==0 || Hand3[2].getRank()>1)) return(true); return(false); }

// More functions go here

// File Card.h

#ifndef CARD_H #define CARD_H #include #include

using namespace std;

class Card {

enum Rank {two, three, four, five, six, seven, eight, nine,ten, jack, queen, king, ace}; enum Suit {spade, heart, club, diamond};

public: Card(int value = 0); // Sets void setRank(int value);

void setSuit(int value);

void setCard(int value); //Gets string getRankString() const;

char getSuitString() const;

int getRank() const;

int getSuit() const;

bool compareSuit(const Card &right) const;

bool operator

. You will complete 3Card.cpp. It is provided with code for creating and shuffling a deck and determining if a hand is a straight, as well as for handling command-line arguments. You will determine if the hand is a straight and if it is a flush at most once. If there are no pairs, assign the result of checking for a straight and a flush to bool variables, and then make a final determination; order of consideration is important for correctly determining hands. You need not error check that the command line arguments represent the types noted above. You do have to make sure the file opened if the command-line argument is a file name. If the input comes from a file, three cards should be input and processed during each iteration of a loop until the file is exhausted. Documentation is a point of emphasis in this project. In particular (See setCard() for a sample): All member functions in the Card class must be labeled as mutator, facilitator, or inspector. All parameters must be labeled by their type, i.e. one of IMPORT, EXPORT, or IMPORT/EXPORT. Descriptions must be given with all prototypes in the space provided. Stating the name of the function is NOT a description. Stating that Card.cpp is the implementation is stating the obvious. Significant penalties will be assessed for poor, lamc, chintzy, or otherwise defective documentation of files and functions. If you aren't sure, ask!! . . . . . . Here is an algorithm you can follow for determining the hand: A Determine how many of the cards match by rank B. if two or more cards match by rank B.1. if all three match, B.1.1. report: 3 of a kind B.2. otherwise B.2.1. report: pair C. otherwise C.1. Assign a bool value representing: Is the hand a straight? C.2. Assign a bool value representing: Is the hand a flush? C.3. if the hand is both a straight and a flush C.3.1. if the hand is a royal flush C.3.1.1. report: royal flush C.3.2. otherwise C.3.2.1. report: straight flush C.4. otherwise, if the hand is a flush C.4.1. report: flush C.5. otherwise, if the hand is a straight C.5.1. report: straight C.6. otherwise, C.6.1. report: nothing There will be three ways the program can obtain 3-card hands of Poker. If there are no command line arguments, a shuffled deck of cards will be generated, the first three cards will be the hand, and the program will output the hand and its value. If there is one command line argument, it is assumed to be the name of a file of integers. If that file opens successfully, then it will be processed, three values at a time, with the hand(s) and their value(s) output. If there are three command line arguments, they are assumed to be integers in [0,51]. They will be used to form a hand, and that hand will be output with its value. * Possible hands are listed in the box, in descending order of strength. Royal Straight Flush The following functions must be implemented in your application: Straight Flush Generate a deck of 52 cards, using the indices of the deck (0-51). Three-of-a-kind Shuffle the deck. * Flush Create a hand by drawing the top 3 cards off the top of the deck. 2 > Straight parameters: the deck and an array of 3 Card objects One Pair Print the hand; 1 parameter: (the array of Card), returns void No Pairs Report the hand, which calls one or more of the following: Determine how many of the 3 cards match; 1 parameter (the array of Card), returns int Determine if a hand is a flush; 1 parameter (the array of Card), returns bool Determine if a hand is a straight; 1 parameter (the array of Card), returns bool * Determine if a hand is a royal flush; 1 parameter (the array of Card), returns bool *This function is provided . You will complete 3Card.cpp. It is provided with code for creating and shuffling a deck and determining if a hand is a straight, as well as for handling command-line arguments. You will determine if the hand is a straight and if it is a flush at most once. If there are no pairs, assign the result of checking for a straight and a flush to bool variables, and then make a final determination; order of consideration is important for correctly determining hands. You need not error check that the command line arguments represent the types noted above. You do have to make sure the file opened if the command-line argument is a file name. If the input comes from a file, three cards should be input and processed during each iteration of a loop until the file is exhausted. Documentation is a point of emphasis in this project. In particular (See setCard() for a sample): All member functions in the Card class must be labeled as mutator, facilitator, or inspector. All parameters must be labeled by their type, i.e. one of IMPORT, EXPORT, or IMPORT/EXPORT. Descriptions must be given with all prototypes in the space provided. Stating the name of the function is NOT a description. Stating that Card.cpp is the implementation is stating the obvious. Significant penalties will be assessed for poor, lamc, chintzy, or otherwise defective documentation of files and functions. If you aren't sure, ask!! . . . . . . Here is an algorithm you can follow for determining the hand: A Determine how many of the cards match by rank B. if two or more cards match by rank B.1. if all three match, B.1.1. report: 3 of a kind B.2. otherwise B.2.1. report: pair C. otherwise C.1. Assign a bool value representing: Is the hand a straight? C.2. Assign a bool value representing: Is the hand a flush? C.3. if the hand is both a straight and a flush C.3.1. if the hand is a royal flush C.3.1.1. report: royal flush C.3.2. otherwise C.3.2.1. report: straight flush C.4. otherwise, if the hand is a flush C.4.1. report: flush C.5. otherwise, if the hand is a straight C.5.1. report: straight C.6. otherwise, C.6.1. report: nothing There will be three ways the program can obtain 3-card hands of Poker. If there are no command line arguments, a shuffled deck of cards will be generated, the first three cards will be the hand, and the program will output the hand and its value. If there is one command line argument, it is assumed to be the name of a file of integers. If that file opens successfully, then it will be processed, three values at a time, with the hand(s) and their value(s) output. If there are three command line arguments, they are assumed to be integers in [0,51]. They will be used to form a hand, and that hand will be output with its value. * Possible hands are listed in the box, in descending order of strength. Royal Straight Flush The following functions must be implemented in your application: Straight Flush Generate a deck of 52 cards, using the indices of the deck (0-51). Three-of-a-kind Shuffle the deck. * Flush Create a hand by drawing the top 3 cards off the top of the deck. 2 > Straight parameters: the deck and an array of 3 Card objects One Pair Print the hand; 1 parameter: (the array of Card), returns void No Pairs Report the hand, which calls one or more of the following: Determine how many of the 3 cards match; 1 parameter (the array of Card), returns int Determine if a hand is a flush; 1 parameter (the array of Card), returns bool Determine if a hand is a straight; 1 parameter (the array of Card), returns bool * Determine if a hand is a royal flush; 1 parameter (the array of Card), returns bool *This function is provided

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions