Okay I have no idea what Im doing could someone please show

Okay, I have no idea what I\'m doing, could someone please show me where to start, help me get the code down something! I\'m struggling so bad.

Class Card

It has a suit and a rank.
o Suit should be declared from an enumerate data type that you build which allows

JOKER, CLUBS,DIAMONDS,HEARTS,SPADES
o Rank can be an integer from 0 to 13, Assign Aces the rank of 1.

The default constructor will create a JOKER with a rank of 0

A parameterized constructor that accepts rank and suit for convenience.

o Throw an exception if the input is not correct.

Be sure to have set and get methods. The set methods should be private to prevent

someone from changing the card.

The Card class should provide a method to returns its description in a string object. That

is it will have a ‘toString() method that returns a string object that looks like: Ace of Hearts

Seven of Clubs.

Joker

Be sure to test each method you create. I know it will be difficult to test the private set

methods. Have the parameterized constructor call them.

With the toString() function, the Card object should be easy to print. Test with

cout<<Card.toString()

Remember this should have both a specification file (.h) and an implementation file

(.cpp)

The enum for the suits should be declared outside the class (in the header file). This is to

be sure it is available others needing it.

Main Program

The main or driver program create an array of 52 cards and print them. Randomly pick a card and print it.
makefile

Please include a makefile for compilation. There will be 3 files in it!

Solution

#include #include #include #include using namespace std; int suits[4]={1, 2, 3, 4}; int faces[12]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; class Card { public: int face,suit; Card(int face,int suit) { this->face=face; this->suit=suit; } string toString() { string nameSuit; string nameFace; if (suit == 1) nameSuit = \"Hearts\"; else if(suit == 2) nameSuit = \"Diamonds\"; else if(suit == 3) nameSuit = \"Spades\"; else if (suit == 4) nameSuit = \"Clubs\"; if (face == 1) nameFace = \"Ace\"; else if(face == 10) nameFace = \"Jack\"; else if(face == 11) nameFace = \"Queen\"; else if(face == 12) nameFace = \"King\"; else { for (int i = 2; i < 10; i++) { nameFace = \"\" + i; } return nameFace+\" of \"+nameSuit; } }; class DeckOfCards { private: vector deck; int currentCard,index; public: DeckOfCards() /*create deck*/ { currentCard=1; for(int i=0;i<13;i++) for(int k=0;k<4;k++) { Card card(i,k); deck.push_back(card); currentCard++; } } void shuffle() /*shuffle the deck*/ { for(int i=0;i<52;i++) { index=rand()%52+1; Card holder=deck[index]; deck[index]=deck[i]; deck[i]=holder; } } Card dealCard() /*deal the shuffled cards*/ { Card temporary = deck[currentCard]; currentCard--; return temporary; } bool moreCards() { if(currentCard == 52) return false; else return true; } }; int main () /*main function*/ { DeckOfCards deck; deck.shuffle(); for( int i = 0; i < 52; i++) { cout<
Okay, I have no idea what I\'m doing, could someone please show me where to start, help me get the code down something! I\'m struggling so bad. Class Card It ha
Okay, I have no idea what I\'m doing, could someone please show me where to start, help me get the code down something! I\'m struggling so bad. Class Card It ha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site