Lists all of the journal entries for the day.

Mon, 23 Jul 2007

10:02 AM - Old C++ code

I found this from an old C++ assignment from my first term at WMU. Kind of interesting how my coding style has changed and stayed the same. I don't know if this is the final version or not. I doubt it.


#include
#include
#include
using namespace std;

void initDeck( int[], int );
void printDeck( int[], int );
void printCard( int );
void printFaceValue( int );
void printSuit( int );
void shuffle( int[], int );
void deal( int[], int );
bool isFullHouse( int[], int );
bool isStraight( int[], int );
void printFullHouse( int[], int );
void printStraight( int[], int );
int getRand( int );

const int DECKSIZE = 52;
const int CLUBS = 0;
const int SPADES = 1;
const int DIAMONDS = 2;
const int HEARTS = 3;

int main()
{
int A[DECKSIZE];

srand( time(0) );

initDeck( A, DECKSIZE );
printDeck( A, DECKSIZE );

shuffle( A, DECKSIZE );
printDeck( A, DECKSIZE );

return 0;
}

void initDeck( int A[], int size )
{
for ( int i = 0; i < size; i++ )
A[i] = i;
}

void printDeck( int A[], int size )
{
cout << "current deck:

";

for ( int i = 0; i < size; i++ )
{
printCard( A[i] );

if ( i % 4 == 3 )
cout << endl;
else
cout << ", ";
}

cout << endl;
}

void printCard( int card )
{
printFaceValue( card );
cout << " of ";
printSuit( card );
}

void printFaceValue( int card )
{

int face = card % 13;

switch ( face )
{
case 0:
cout << " 2";
break;
case 1:
cout << " 3";
break;
case 2:
cout << " 4";
break;
case 3:
cout << " 5";
break;
case 4:
cout << " 6";
break;
case 5:
cout << " 7";
break;
case 6:
cout << " 8";
break;
case 7:
cout << " 9";
break;
case 8:
cout << "10";
break;
case 9:
cout << " J";
break;
case 10:
cout << " Q";
break;
case 11:
cout << " K";
break;
case 12:
cout << " A";
break;
}

return;
}

void printSuit( int card )
{

switch ( card % 4 )
{
case CLUBS:
cout << "clubs";
break;
case SPADES:
cout << "spades";
break;
case DIAMONDS:
cout << "diamonds";
break;
case HEARTS:
cout << "hearts";
break;
}

return;
}

void shuffle( int A[], int size )
{
bool notfound = true;

for ( int i = 0; i < size; i++ )
{
A[i] = getRand( size );

do
{
if ( A[i] == A[ i + 1 ] )
notfound = false;
else
notfound = true;

} while ( notfound == false );

}
}

int getRand( int scale )
{
return rand() % scale;
}

(1 comment | )