I have constructed a deck of cards in one file called deckofcards with takes in properties of card. see below, I then want to transfer the array of cards i/e/ deck into a vector in handofcards file but this is where i am having issues.
Card.h file
#ifndef card_h
#define card_h
#include <iostream>
#include <string>
using namespace std;
class card
{
private:
string num; char suit;
public:
card(string cardnum, char cardsuit); string print() const;
string getnumber();
char getsuit();
card(); };
#endif;
the relevant source file
card.cpp
card::card(string cardnum, char cardsuit)
{
num = cardnum; suit = cardsuit;
}
string card::print() const {
return (num + suit);
}
string card::getnumber() {
return num;
}
char card::getsuit() {
return suit;
}
next set of files is the construction of the deck;
deckofcards.h file
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
const int CARDS_PER_DECK = 52; class deckofcards
{
private:
card *deck; int currentcard; card *temp; public:
deckofcards(); void printdeck1() const;
void splitdeck1();
void randemshuffle(); };
#endif
decoofcards.cpp file
#include <iostream>
#include "deck.h"
#include "Hand.h"
#include "card.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
using namespace std;
deckofcards::deckofcards()
{
string num[13] = { "ace", "2", "3", "4", "5", "6", "7", "8",
"9", "10", "jack", "queen", "king" };
char suit[4] = { 3, 4, 5, 6 };
deck = new card[CARDS_PER_DECK]; currentcard = 0;
for (int count = 0; count < CARDS_PER_DECK; count++)
deck[count] = card(num[count % 13], suit[count / 13]);
}
void deckofcards::randemshuffle()
{
currentcard = 0;
for (int i = 0; i < CARDS_PER_DECK; i++)
{
int j = (rand() + time(0)) % CARDS_PER_DECK;
card temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
}
void deckofcards::printdeck1() const
{
for (int i = 0; i < 52; i++)
{
if ((i + 1) % 1 == .0)
deck[i].print();
}
}
void deckofcards::splitdeck1()
{
for (int i = 0; i < CARDS_PER_DECK; i += 2)
if ((i + 1) % 1 == .0)
deck[i].print();
}
last two files is the handofcards files. up until these next two files the code works from here i have issues.
handofcards.h
#ifndef hand_h
#define hand_h
#include "card.h"
#include <iostream>
#include <vector>
#include "deck.h"
using namespace std;
class handofcards :public deckofcards
{
private:
vector <card> Hand_Of_Cards;
public:
handofcards();
void handdelt();
void printhand1() const;
};
#endif
handofcards.cpp
#include <iostream>
#include <ostream>
#include "Hand.h"
#include "deck.h"
#include "card.h"
#include <string>
#include <vector>
using namespace std;
handofcards::handofcards()
{
Hand_Of_Cards.push_back;
}
void handofcards::handdelt()
{
handofcards handC;
deckofcards d;
handC.Hand_Of_Cards;
handC.splitdeck1();
Hand_Of_Cards.insert(Hand_Of_Cards.end(), &deck[0], &deck[CARDS_PER_DECK]);
}
void handofcards::printhand1() const
{
}
any help would be great