Click here to Skip to main content
15,877,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C++
#ifndef card_h
#define card_h
#include <iostream>
#include <string>

using namespace std;


class card
{
private:
    string num;  // #YT
    char suit;    // modified to output char instead of string

public:
    card(string cardnum, char cardsuit); // modified to take in char
    string print() const;
    string getnumber();
    char getsuit();
    card(); // constructor
};
#endif;


the relevant source file
card.cpp
C++
card::card(string cardnum, char cardsuit)
{
    num = cardnum; // changed varable name
    suit = cardsuit;
}

// prints to the console the cards
string card::print() const  //#YT slightly modified but main purpose is the same
{
    return (num + suit);
}

string card::getnumber() //will be used to determin a snap
{
    return num;
}

char card::getsuit() //will be used to determin a snap
{
    return suit;
}


next set of files is the construction of the deck;
deckofcards.h file
C++
#include <iostream>
#include <string.h>
#include <string>
using namespace std;

const int CARDS_PER_DECK = 52; // deck of cards constanly has 52 cards
class deckofcards
{
private:

    card *deck; // YT pointer from card to deck
    int currentcard;//YT name variable of current card, type interger
    card *temp; // creates a tempary card to be used in shuffle function
public:
    deckofcards(); //constructor
    void printdeck1() const;
    void splitdeck1();
    //void splitdeck();
    void randemshuffle(); // this is my code to randemly shuffle my deck of cards
};
#endif


decoofcards.cpp file
C++
#include <iostream>
#include "deck.h"
#include "Hand.h"
#include "card.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>

using namespace std;


// #YT mostly origonal code with some modifications
// this code incroments the elements of the array
//takes in the card number and suit and stores it in the array
deckofcards::deckofcards()
{
	string num[13] = { "ace", "2", "3", "4", "5", "6", "7", "8",
						"9", "10", "jack", "queen", "king" };
	//char a[4] = { 3,4,5,6 } - my modification
	char suit[4] = { 3, 4, 5, 6 }; // modified to print symbols instead of a string 

	deck = new card[CARDS_PER_DECK]; // #YT link origional code some changes to variable names 
	currentcard = 0; 
	for (int count = 0; count < CARDS_PER_DECK; count++)
		deck[count] = card(num[count % 13], suit[count / 13]);
}
//this is the random/shuffle function
//there is a new property in deck called temp card
//this takes in a tempary card am moves it with and exsiting card
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
{
	// this loop prints to the screen the array of cards 
	for (int i = 0; i < 52; i++)
	{
		if ((i + 1) % 1 == .0) // modified to print one card per line 

			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
C++
#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
C++
#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
Posted
Updated 10-Aug-15 23:38pm
v2
Comments
Richard MacCutchan 11-Aug-15 5:35am    
Help with what? You need to explain what the issues are and where they occur.
KarstenK 11-Aug-15 8:13am    
Set a debug point at the last clear code point and step through. Watch some Youtube videos. There is a bunch of good tutorials. ;-)
Ujesh Mohanan 12-Aug-15 8:24am    
Please be specific about the issues that you are getting. Your code contains some very basic mistakes. Is this a homework assignment where you are asked to correct the mistakes?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900