Quote
error: request for member ‘get_value’ in ‘deck’, which is of non-class type ‘card_deck ()()’
#ifndef DECK_HPP
#define DECK_HPP
/*
A class that defines a card_deck type to represent a deck a cards
*/
class card_deck
{
private:
/*
An array of ints with a size of 52 which is the standard size of a deck of cards
*/
int cards[52];
public:
/*
Prototypes for the class methods
See deck.cpp for method implementations
*/
card_deck();
const int get_value(int element);
};
#endif
card.cpp
#include <cstdlib>
#include <ctime>
#include "deck.hpp"
/*
A constructor method to fill cards[] with int card values then uses
a Fisher Yates card shuffling algorithm and cstdlib's random to evenly
shuffle cards[]
*/
card_deck::card_deck()
{
int value = 1;
int n = 52;
int k;
int temp;
for(int i = 0;i < 52;++i)
{
cards[i] = value;
++value;
if(cards[i] == 13)
{
value = 1;
}
}
std::srand(std::time(0));
while(n > 1)
{
k = (std::rand() % n);
--n;
temp = cards[n];
cards[n] = cards[k];
cards[k] = temp;
}
}
/*
A method that will return the requested element of cards[]
if it is in range and return -1 if the the element is out of range
*/
const int card_deck::get_value(int element)
{
if(element > -1 && element < 52)
{
return cards[element];
}
else
{
return -1;
}
}
Edited by Coder Zombie, 09 January 2009 - 09:05 PM.


Sign In
Create Account


Back to top









