Could someone help me for this Coding Please Thank you CardP

Could someone help me for this Coding, Please! Thank you!   CardPlay is a class which will generate random cards for a user to be used in any card game, and it has the five instance variables: oneHand, suit, maxCount, currSize and a Random class object rand CardPlay - oneHand : int[] - suit : int[] - maxCount : int - currSize : int - rand : Random + CardPlay(int) + generateHand() : void + calcSuitFreq() : void + getSuitFreq() : int + getHand() : String - checkDuplicate(int) : boolean - getSuit(int) : String - getKind(int) : String

1) oneHand is an array object storing randomly generated cards between 0 and 51 as int, 2) suit is an array object storing frequency of suit of user’s cards as int, 3) maxCount is the maximum number of cards, 4) currSize is an int for keeping track of the number of cards generated, and 5) rand is an object of class Random. The class CardPlay must include the constructors and methods in the table: (If your class does not contain any of the following methods, points will be deducted). The public and private access modifiers are represented as \"+\" and \"-\" respectively. 1. CardPlay(int): (4 pts) The constructor is to a. Reserve memory space for the array object oneHand with the length given as parameter variable. b. Reserve memory space for the array object suit with the length 4 (i.e. the different kinds of suit available). c. The maxCount is set as parameter variable, specifying the maximum number of cards that can be held in this array (length of the array oneHand). d. The currSize is set as 0. It is not the length of array but the number of valid cards. In other words, when oneHand is partially filled array, then currSize is used as an END position of valid cards. e. Create an instance rand of Random class-type.

2. GenerateHand():void (3 pts) If there is room (left in) the array oneHand, add a distinct card to the END(currSize) position of the array and adjust the currSize to reflect how many values are in the array oneHand. Use Random class method(s) to generate an integer value between 0-51. Add this value to array oneHand Only If the value is distinct, i.e. oneHand array does not contain a similar value. Q. How to use Random class and it’s methods? A. Check Lecture Slides 4 (slide number 14 and 15)

3. CheckDuplicate(int):boolean (3 pts) This method should perform a linear or sequential search. The method is to look at the elements in the array oneHand until the value of the parameter is found or all values have been examined. If a value occurs in the array, the method should return the true. If the value is not in the array, then the method should return false.

4. calcSuitFreq():void (3 pts) To calculate the suit, we will consider a. The first 13 cards are Clubs (From 0 – 12) b. The next 13 are Diamonds (From 13 – 25) c. After that we have Hearts (From 26 – 38) d. Finally, the last 13 cards are Spades (From 39 – 51) Once the suit is calculated then, update the value for array suit at the appropriate location/index number. Again for the array suit, we will assume that suit[0] is holding the number of Club cards that user has, suit[1] is holding the number of Diamond cards that user has, suit[2] is holding the number of Heart cards that user has and finally, suit[3] is holding the number of Spade cards that user has.

5. getSuitFreq():int (3 pts) This method will calculate how many suits have a count of greater than 1. For example, if user cards are following: Jack of Club 2 of Diamond 5 of Spade King of Diamond Ten of Club Then this method will calculate that user has Clubs with a count of greater than 1 and Diamonds with a count of greater than 1. Therefore, it will return a value 2.

6. getHand():String (3 pts) Return the cards in the array as shown below. Jack of Club 2 of Diamond 5 of Spade King of Diamond Ten of Club

Solution

#include <iostream>

#include <iomanip>

#include <string>

#include <vector>

using namespace std;

const static char FACE_VALUES[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

const static char* FACE_NAMES[] = { \"A\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"J\", \"Q\", \"K\" };

const static char SUIT_VALUES[] = { 0x10, 0x20, 0x30, 0x40 };

const static char* SUIT_NAMES[] = { \"Spades\", \"Hearts\", \"Clubs\", \"Diamonds\" };

const static char MIN_CARD_VALUE = 1 | 0x10;

const static char MAX_CARD_VALUE = 13 | 0x40;

class PlayingCard

{

public:

    const static char SPADES    = 0x10;

    const static char HEARTS    = 0x20;

    const static char CLUBS = 0x30;

    const static char DIAMONDS = 0x40;

     

    PlayingCard() : m_value( 0 ){}

    PlayingCard( const char value ) : m_value( value ){}

    PlayingCard( PlayingCard const& rhs ){ m_value = rhs.m_value; }

    const char getValue() const { return m_value; }

    void setValue( const char value ){ m_value = validateValue( value ) ? value : m_value; }

    std::string toString()

    {

    std::string value;

    if( validateValue( m_value ) )

    {

        std::string face( FACE_NAMES[ (m_value % 0x10) -1 ] );

        std::string suit( SUIT_NAMES[ (m_value / 0x10) -1 ] );

        value = face;

        value += \" \";

        value += suit;

    }

    else

    {

        value = \"Invalid Playing Card!\";

    }

    return value;

    }

    const char getFaceValue() const { return FACE_VALUES[ (m_value % 0x10) -1 ]; }

    const char getSuitValue() const { return SUIT_VALUES[ (m_value / 0x10) -1 ]; }

    static char makeValue( const char face, const char suit ) { return validateValue( face | suit ) ? ( face | suit ) : 0; }

private:

    char m_value;

    static bool validateValue( const char value )

    {

    bool bIsValid = false;

    if( value >= MIN_CARD_VALUE && value <= MAX_CARD_VALUE )

    {

        bIsValid = true;

    }

    return bIsValid;

    }

};

typedef std::vector<PlayingCard> vPlayingCardDeck;

void spew_deck( vPlayingCardDeck& v )

{

    vPlayingCardDeck::iterator it;

    for( it = v.begin(); it != v.end(); it++ )

    {

    cout << (*it).toString() << endl;

    }

}

int main()

{

    vPlayingCardDeck v;

    for( int i = 0x10; i < 0x50; i += 0x10 )

    {

    for( int j = 1; j < 14; j++ )

    {

        PlayingCard card( i | j );

        v.push_back( card );

    }

    }

    spew_deck( v );

    PlayingCard card;

    cout << card.toString() << endl;

    card.setValue( 12 | PlayingCard::SPADES );

    cout << card.toString() << endl;

    cout << \"\\t\" << static_cast<int>( card.getFaceValue() ) << endl;

    cout << setfill( \'0\' ) << showbase << hex << internal;

    cout << \"\\t\" << static_cast<int>( card.getSuitValue() ) << endl;

    card.setValue( PlayingCard::makeValue( 11, PlayingCard::DIAMONDS ) );

    cout << card.toString() << endl;

    return 0;

}

Could someone help me for this Coding, Please! Thank you! CardPlay is a class which will generate random cards for a user to be used in any card game, and it ha
Could someone help me for this Coding, Please! Thank you! CardPlay is a class which will generate random cards for a user to be used in any card game, and it ha
Could someone help me for this Coding, Please! Thank you! CardPlay is a class which will generate random cards for a user to be used in any card game, and it ha
Could someone help me for this Coding, Please! Thank you! CardPlay is a class which will generate random cards for a user to be used in any card game, and it ha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site