Please help guys... I need to complete this class to make it work witht his program, and I feel bad already, but I am really clueless. CLasses are hard for me if you could help me out, I'd appreciate it very much.
Code:
#include <iostream>
#include <iomanip>
#include <cstring>
//#include "card.h"
class card
{
public:
card();
card(int num, char suit);
set_num(input from main);
set_suite(input from main);
get_num();
get_suite();
~card();
private:
int number;
char suite;
};
card::card()
{
number=0;
suite=0;
}
card::card(int num, char suit)
{
number=num;
suite=suit;
}
card::~card()
{
}
card::get_num()
{
}
card:: get_suite()
{
}
card::set_num(input from main)
{
}
card::set_suite( input from main)
{
}
// Declare and initialize global variables
// 'HIGH' - the value of the highest card in the deck
// 'LOW' - the value of the lowest card in the deck
// 'HAND_SIZE' - the number of cards in your hand
const int HIGH = 14, LOW = 2;
const int HAND_SIZE = 5;
bool good_card( int num, char suit, int index );
void sort_cards( card _hand[] );
void cards_switcheroo( card _hand[], int num );
bool straight_flush( card _hand[] );
bool four_of_a_kind( card _hand[] );
bool full_house( card _hand[] );
bool flush( card _hand[] );
bool straight( card _hand[] );
bool three_of_a_kind( card _hand[] );
bool two_pair( card _hand[] );
bool pair( card _hand[] );
int main()
{
card hand[HAND_SIZE];
int num = 0;
int suit_num = 0;
char suit;
int discard_counter = 0;
int card_num = 0;
for ( int i = 0; i < HAND_SIZE; i++ )
{
num = rand() % ( HIGH - LOW + 1 ) + LOW;
word_num = rand() % ( 4 - 1 + 1 ) + 1;
if ( word_num == 1 )
word = 's';
if ( word_num == 2 )
word = 'h';
if ( word_num == 3 )
word = 'c';
if ( word_num == 4 )
word = 'd';
if ( word_num > 4 || word_num < 1 )
i--;
else if ( good_card( num, word, i )
hand[i].set_card( num, word );
else
i--;
}
sort_cards( hand );
if (straight_flush( hand ))
{
cout << "You intially have a straight flush." << endl;
}
if (four_of_a_kind( hand ))
{
cout << "You initially have four of a kind." << endl;
}
if (full_house( hand ))
{
cout << "You initially have a full house." << endl;
}
if (flush( hand ))
{
cout << "You initially have a flush." << endl;
}
if (straight( hand ))
{
cout << "You initially have a straight." << endl;
}
if (three_of_a_kind( hand ))
{
cout << "You initially have a kind." << endl;
}
if (two_pair( hand ))
{
cout << "You initially have a two pair." << endl;
}
if (pair( hand ))
{
cout << "You initially have a pair." << endl;
}
cout << "Your hand:";
for ( int i = 0; i < HAND_SIZE; i++ )
cout << "[" << i+1 << "] " << hand[i].get_num() << hand[i].get_suit() << endl;
do
{
if ( discard_counter == 0 )
cout << "Which card(s) would you like to discard ( < 0 to quit)?" << endl;
cin >> card_num;
if ( card_num > 0 && card_num < 6 )
{
card_num -= 1;
card_switcheroo( card _hand[], card_num );
}
if ( card_num == 0 || card_num > 5 )
cout << "Invalid card choice! Try again" << endl;
discard_counter++;
}while ( card_num >= 0 );
return 0;
}
bool good_card( int num, string suit, int index )
{
for ( int i = 0; i < index; i++ )
{
if ( hand[i].get_suit() == suit )
{
if( hand[i].get_num() == num )
{
return false;
}
}
}
return true;
}
void sort_cards( card _hand[] )
{
for ( int i = 0; i < (HAND_SIZE - 1); i++ )
{
for ( int j = (i + 1); j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() < _hand[i].get_num() )
{
int temp_card_type = _hand[i].get_num();
_hand[i].set_num( _hand[j].get_num() );
_hand[j].set_num( temp_card_type );
string temp_suit_type = _hand[i].get_suit();
_hand[i].set_suit( _hand[j].get_suit() );
_hand[j].set_suit( temp_suit_type );
}
}
}
}
void cards_switcheroo( card _hand[], int num )
{
}
bool straight_flush( card _hand[] )
{
int same_suit_count = 1;
int order_count = 0;
for ( int i = 0; i < ( HAND_SIZE - 1 ); i++ )
{
if ( _hand[i].get_suit() == _hand[(i+1)].get_suit() )
same_suit_count++;
}
if ( same_suit_count != 5 )
return false;
for ( int i = 0; i < (HAND_SIZE - 1); i++ )
{
if ( _hand[i].get_num() == ( _hand[i+1].get_num() - 1 ) )
{
order_count++;
}
}
if ( _hand[0].get_num() == 2 &&
_hand[1].get_num() == 3 &&
_hand[2].get_num() == 4 &&
_hand[3].get_num() == 5 &&
_hand[4].get_num() == 14)
{
return true;
}
if ( order_count == 5 )
{
return true;
}
return false;
}
bool four_of_a_kind( card _hand[] )
{
int card_count = 0;
for ( int i = 2; i < 15; i++ )
{
for ( int j = 0; j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() == i )
card_count++;
if (card_count == 4)
return true;
}
card_count = 0;
}
return false;
}
bool full_house( card _hand[] )
{
int first_num = 0;
bool possible_full_house = false;
int card_count = 0;
for ( int i = 2; i <= 14; i++ )
{
for ( int j = 0; j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() == i )
card_count++;
if ( card_count == 3 )
{
first_num = i;
possible_full_house = true;
card_count = 0;
break;
}
}
}
card_count=0;
if ( possible_full_house )
{
for ( int i = 2; i <= 14; i++ )
{
for ( int j = 0; j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() == i && i != first_num )
{
card_count++;
}
if ( card_count == 2 )
return true;
}
card_count = 0;
}
}
return false;
}
bool flush( card _hand[] )
{
int same_suit_count = 1;
for ( int i = 1; i < HAND_SIZE; i++ )
{
if ( _hand[0].get_suit() == _hand[i].get_suit() )
same_suit_count++;
if ( same_suit_count == 5 )
return true;
}
return false;
}
bool straight( card _hand[] )
{
int order_count = 0;
for ( int i = 0; i < (HAND_SIZE - 1); i++ )
{
if ( _hand[i+1].get_num() - _hand[i].get_num() == 1 )
{
order_count++;
}
}
if ( _hand[0].get_num() == 2 &&
_hand[1].get_num() == 3 &&
_hand[2].get_num() == 4 &&
_hand[3].get_num() == 5 &&
_hand[4].get_num() == 14)
{
return true;
}
if ( order_count == 5 )
{
return true;
}
return false;
}
bool three_of_a_kind( card _hand[] )
{
int card_count = 0;
for ( int i = 2; i <= 14; i++ )
{
for ( int j = 0; j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() == i )
card_count++;
}
if ( card_count == 3 )
return true;
card_count = 0;
}
return false;
}
bool two_pair( card _hand[] )
{
bool one_pair = false;
for ( int j = 0; j < HAND_SIZE; j++ )
{
if (one_pair)
{
if ( _hand[j].get_num() == _hand[j+1].get_num() )
return true;
}
if ( _hand[j].get_num() == _hand[j+1].get_num() )
{
one_pair = true;
}
}
return false;
}
bool pair( card _hand[] )
{
int card_count = 0;
for ( int i = 2; i <= 14; i++ )
{
for ( int j = 0; j < HAND_SIZE; j++ )
{
if ( _hand[j].get_num() == i )
card_count++;
}
if ( card_count == 2 )
return true;
card_count = 0;
}
return false;
}