Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need this project in c++ Turn in: Your class, in files Card.h and Card.cpp, your application, named 3Card.cpp, and the makefile. This is the file

Need this project in c++

image text in transcribedimage text in transcribed

Turn in: Your class, in files Card.h and Card.cpp, your application, named 3Card.cpp, and the makefile.

This is the file 3card.cpp

/*********************************************************************/ /* File: 3Card.cpp */ /* Author: */ /* Selected code provided by Dr. Spiegel */ /* */ /* */ /* */ /* Purpose: */ /* */ /* */ /* */ /* */ /*********************************************************************/

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

using namespace std;

/********************************************************************/ /* class and function provided by Dr. Spiegel */ /* 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); }

/**********************************************************************/ /* Function Name: generateDeck */ /* */ /* Description: generates a deck of cards */ /* */ /* Parameters: Card Deck[] - array of 52 */ /* card objects */ /* */ /* Return Value: none */ /**********************************************************************/ void generateDeck(Card Deck[]);

// Prototypes go here.

/**********************************************************************/ /* Function Name: isAStraight */ /* */ /* Description: code provided by Dr. Spiegel */ /* to determine if a hand is a */ /* straight */ /* */ /* Parameters: Card Hand3[] - array of hand */ /* */ /* Return Value: true if a straight otherwise */ /* false */ /**********************************************************************/ 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

This is the 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); void setRank(int value);

void setSuit(int value);

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

char getSuitString() const;

int getRank() const;

int getSuit() const;

bool compareSuit(const Card &right) const;

bool operator

bool operator==(const Card &right) const;

private: Rank rank; Suit suit;

static const string rankStr[]; static const char suitChar[];

};

ostream &operator

ifstream &operator>>(ifstream &out,Card &right);

#endif

The is the makefile:

debugFlag=-g cc=g++ p2: Card.o 3Card.o $(cc) -o p2 3Card.o Card.o $(debugFlag) 3Card.o: 3Card.cpp Card.h $(cc) -c 3Card.cpp $(debugFlag) Card.o: Card.cpp Card.h $(cc) -c Card.cpp $(debugFlag) clean: m -f *.o p2
Program: Complete the implementation of a class to simulate a playing card and a program to generate and cvaluatc one or more three-card hands of poker. Your class, named Card, will represent a simple playing card. It will have attributes for rank (2,3,4....,10,J,Q,K,A) and suit (hearts, diamond, clubs, spades). It will have sets and gets for each data attribute, member operator function overloads to return whether the Card object has the same or lesser rank than another Card object, and another for comparing suits of two Cards for equality. It will have a constructor that will interpret a code for creating a particular card in the deck of 52. It will also have associated, non-member functions that output a card to an output stream (ostream) and input a card from a file (ifstream) 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), retums 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), retums 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 > . Notes: A working executable will be provided in the project directory on acad. It will be named p2. Run it using-/p2 The executable created by the make utility will also create an executable named p2. Again, use ./p2 to run it. Card.h will be provided in complete form. You MUST update the comment boxes to provide parameter types and descriptions for the functions and complete the id block. Up to a two letter grade penalty if you don't complete the boxes well. Do not add or remove functions. You will write Card.cpp and complete 3Card.cpp. Enumeration types for rank and suit are provided. Note that ace is now high. To print a card, you must use the . Notes: A working executable will be provided in the project directory on acad. It will be named p2. Run it using-/p2 The executable created by the make utility will also create an executable named p2. Again, use ./p2 to run it. Card.h will be provided in complete form. You MUST update the comment boxes to provide parameter types and descriptions for the functions and complete the id block. Up to a two letter grade penalty if you don't complete the boxes well. Do not add or remove functions. You will write Card.cpp and complete 3Card.cpp. Enumeration types for rank and suit are provided. Note that ace is now high. To print a card, you must use the

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

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions