#include <iostream>
#include <vector>
using namespace std;
/*
*
*/
/*
a) Data members face and suit of type int.
b) A constructor that receives two ints representing the face and suit and uses them to initialize
the data members.
c) Two static arrays of strings representing the faces and suits.
d) A toString function that returns the Card as a string in the form “face of suit.” You
can use the + operator to concatenate strings. */
class Card
{
public :
Card( int , int ) ;
string toString( ) ;
private :
int suit, face;
static string faceNames[ 13 ] ;
static string suitNames[ 4 ] ;
} ;
string Card:: faceNames [ 13 ] = { "Ace" ,"Two" ,"Three" ,"Four" ,"Five" ,"Six" ,"Seven" ,"Eight" ,"Nine" ,"Ten" ,"Queen" ,"Jack" ,"King" } ;
string Card:: suitNames [ 4 ] = { "Diamonds" ,"Clubs" ,"Hearts" ,"Spades" } ;
string Card:: toString ( )
{
return faceNames[ face] + " of " + suitNames[ suit] ;
}
Card:: Card ( int f, int s)
: face( f) ,
suit( s)
{
}
/*
Class DeckOfCards should contain:
a) A vector of Cards named deck to store the Cards.
b) An integer currentCard representing the next card to deal.
c) A default constructor that initializes the Cards in the deck. The constructor should use
vector function push_back to add each Card to the end of the vector after the Card is
created and initialized. This should be done for each of the 52 Cards in the deck.
d) A shuffle function that shuffles the Cards in the deck. The shuffle algorithm should
iterate through the vector of Cards. For each Card, randomly select another Card in the
deck and swap the two Cards.
e) A dealCard function that returns the next Card object from the deck.
f) A moreCards function that returns a bool value indicating whether there are more Cards
to deal.
*/
class DeckOfCards
{
public :
DeckOfCards( ) ;
void shuffleCards( ) ;
Card dealCard( ) ;
bool moreCards( ) ;
private :
vector< Card> deck( 52 ) ;
int currentCard;
} ;
int main( int argc, char ** argv) {
return 0 ;
}
DeckOfCards:: DeckOfCards ( )
{
//I'm stuck here I have no idea of what to take out of here.
//I still don't fully get the idea of class inside class and that's turning out as a problem.
for ( int i= 0 ; i< deck.size ( ) ; i++ )
{
deck[ i] //....
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgogCnVzaW5nIG5hbWVzcGFjZSBzdGQ7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pmKSBBIG1vcmVDYXJkcyBmdW5jdGlvbiB0aGF0IHJldHVybnMgYSBib29sIHZhbHVlIGluZGljYXRpbmcgd2hldGhlciB0aGVyZSBhcmUgbW9yZSBDYXJkcwp0byBkZWFsLgogKi8KIApjbGFzcyBEZWNrT2ZDYXJkcwp7CiAgIApwdWJsaWM6CiAgIAogICAgRGVja09mQ2FyZHMoKTsKICAgIHZvaWQgc2h1ZmZsZUNhcmRzKCk7CiAgICBDYXJkIGRlYWxDYXJkKCk7CiAgICBib29sIG1vcmVDYXJkcygpOwogICAKcHJpdmF0ZToKICAgCiAgICB2ZWN0b3I8Q2FyZD4gZGVjayg1Mik7CiAgICBpbnQgY3VycmVudENhcmQ7CiAgIAp9OwogCmludCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJndikgewogCiAgICByZXR1cm4gMDsKfQogCkRlY2tPZkNhcmRzOjpEZWNrT2ZDYXJkcygpCnsKICAgIC8vSSdtIHN0dWNrIGhlcmUgSSBoYXZlIG5vIGlkZWEgb2Ygd2hhdCB0byB0YWtlIG91dCBvZiBoZXJlLgogICAgLy9JIHN0aWxsIGRvbid0IGZ1bGx5IGdldCB0aGUgaWRlYSBvZiBjbGFzcyBpbnNpZGUgY2xhc3MgYW5kIHRoYXQncyB0dXJuaW5nIG91dCBhcyBhIHByb2JsZW0uCiAgICBmb3IoaW50IGk9MDsgaTxkZWNrLnNpemUoKTsgaSsrKQogICAgewogICAgICAgZGVja1tpXS8vLi4uLgogICAgICAgCiAgICB9Cn0=
compilation info
prog.cpp: In constructor ‘Card::Card(int, int)’:
prog.cpp:26:15: warning: ‘Card::face’ will be initialized after [-Wreorder]
int suit, face;
^
prog.cpp:26:9: warning: ‘int Card::suit’ [-Wreorder]
int suit, face;
^
prog.cpp:40:1: warning: when initialized here [-Wreorder]
Card::Card(int f, int s)
^
prog.cpp: At global scope:
prog.cpp:75:23: error: expected identifier before numeric constant
vector<Card> deck(52);
^
prog.cpp:75:23: error: expected ‘,’ or ‘...’ before numeric constant
prog.cpp: In constructor ‘DeckOfCards::DeckOfCards()’:
prog.cpp:89:24: error: ‘((DeckOfCards*)this)->DeckOfCards::deck’ does not have class type
for(int i=0; i<deck.size(); i++)
^
prog.cpp:91:14: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
deck[i]//....
^
prog.cpp:93:5: error: expected ‘;’ before ‘}’ token
}
^
stdout