Hi quick question on this card program im writing. As of now the program should just create the deck and print it from main() using printDeck(). Im not sure why but the deck is printing in a strange format. It should print "Ace" "Spades" for example. Insead the output looks like this:
0x7fff5fbfa4f8 0x7fff5fbfa630
0x7fff5fbfa690 0x7fff5fbfa7c8
0x7fff5fbfa828 0x7fff5fbfa960
0x7fff5fbfa9c0 0x7fff5fbfaaf8
0x7fff5fbfab58 0x7fff5fbfac90
0x7fff5fbfacf0 0x7fff5fbfae28
0x7fff5fbfae88 0x7fff5fbfafc0
0x7fff5fbfb020 0x7fff5fbfb158
0x7fff5fbfb1b8 0x7fff5fbfb2f0
Is this hexadecimal? Why is it printing like this?
// Cards.h
#include <string>
#include <iostream>
using namespace std;
#ifndef __PROGRAMMING_1__Cards__
#define __PROGRAMMING_1__Cards__
#define DECK_SIZE 52
struct Card
{
const string rank[13] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
const string suit[4] = {"Spades", "Hearts", "Clubs", "Diamonds"};
};
class CCardDeck {
public:
CCardDeck();
void Shuffle();
void printDeck();
void Insert();
void Remove();
int getSize(); // # cards left in the deck
private:
Card deck[52]; //Array of 52 cards (suits,rank)
};
#endif /* defined(__PROGRAMMING_1__Cards__) */
-
// Cards.cpp
#include "Cards.h"
#include <iomanip>
CCardDeck::CCardDeck()
{
deck;
}
void CCardDeck::printDeck()
{
for(int i=0; i<52; i++)
{
cout << deck[i].rank << " ";
cout << deck[i].suit << endl;
}
}
int CCardDeck::getSize()
{
// return size of the deck
return sizeof(deck) / sizeof( deck[0]);
}
-
// main.cpp
#include <iostream>
#include "Cards.h"
int main()
{
CCardDeck deck;
deck.printDeck();
cout << endl;
deck.getSize();
return 0;
}