GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Aug-2008, 14:16
nanan nanan is offline
New Member
 
Join Date: Aug 2008
Posts: 2
nanan is on a distinguished road

Poker punch and run program problem


I am a beginner in C++ and i have a problem.
this is the detail information of the problem.
You will deal a hand of 5 cards and show those cards and check for the following. You must choose two parts. Part “1” is required and three of parts “2” – “7”. So your program should check for at least 4 kinds of poker hands. Each part done correctly is worth 25 points.
Part
1. Find a pair.
2. Find three of a kind.
3. Find four of a kind.
4. Find two pair.
5. Find a flush.
6. Find a straight flush.
7. Find a full house.

Requirements:
1. Do not include any unused header files.
2. Use arrays.
3. Use a class
4. No global variables
5. Enclose the program so the poker hand can be repeatedly dealt, until the user chooses to quit.
6. Must have a “programmed by …” inline function that works.

Hints:
1. You will need a double scripted array for the card deck and the dealt cards.
2. The rows are the suits of the cards (i.e. hearts, clubs, etc…)
3. The columns are the faces of the cards (i.e. ace, 2, 3, etc…)
4. A pair is two cards with the same faces.

this is what i have, can somebody help please!!!!!!!!!!!!!!!!!!!!!!!

CPP / C++ / C Code:
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>

Using namespace std;

// Portotype for two functions

void shuffle (int[] [13]);
void deal (const int[] [13], const char *[], const char *[]);

// Main program
int main()
{
	const char *suit [4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
	const char *face [13] = {"Ace", "Duece", "Three", "Four", "Five",
		"Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
	int deck [4] [13] = {0};

	srand (time(0));

	shuffle (deck);
	deal (deck, face, suit);

	return 0;
}

// Function used to shuffle a deck of cards
void shuffle (int wdeck[] [13])
{
	int row, column;

	for (int card = 1; card <= 52; card++)
	{
		do
		{
			row = rand() %4;
			column = rand() %13;
		}
		while (wdeck[row] [column] != 0);

		wdeck[row] [column] = card;
	}
}

// Function used to deal the deck of cards
void deal (const int wdeck[] [13], const char *wface[], const char *wsuit[])
{
	cout << "Programmed \n";
	for (int card = 1; card <= 52; card++)
		for (int row = 0; row <= 3; row++)
			for (int column = 0; column <= 12; column++)

				if (wdeck [row] [column] == card)
					cout << setw(5) << setiosflags (ios::right) <<wface[column]
					<< " of " << setw(8) << setiosflags (ios::left) << wsuit[row]
					<< (card %2 == 0 ? '\n' : '\t');
}
Last edited by admin : 11-Aug-2008 at 16:19. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 11-Aug-2008, 15:40
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Poker punch and run program problem


Quote:
Originally Posted by nanan
this is what i have, can somebody help please!!!!!!!!!!!!!!!!!!!!!!!
You post didn't ask a question, so one might assume that you want someone to complete your assignment. We don't do that, but we will offer assistance & guidance so you can resolve any outstanding issues yourself.

Upon first inspection, it appears you need to address the following issues:
  • You need to ensure that a randomized deck contains each unique card once.
  • If a card is dealt, should it not be taken out of the deck of undealt cards?
Other issues exist too, but you need to resolve the above problems first.
Last edited by ocicat : 11-Aug-2008 at 16:13.
  #3  
Old 11-Aug-2008, 15:44
nanan nanan is offline
New Member
 
Join Date: Aug 2008
Posts: 2
nanan is on a distinguished road

Re: Poker punch and run program problem


Quote:
Originally Posted by ocicat
You post didn't ask a question, so one might assume that you want someone to complete your assignment. We don't do that, but we will offer assistance & guidance so you can resolve any outstanding issues.

Upon first inspection, it appears you need to address the following issues:[list]
Other issues exist too, but you need to resolve the above problems first.

i don't even know how to play poker or understands the rules of it. i need guideline as to what to do.
algorithm might help me.
  #4  
Old 11-Aug-2008, 16:02
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Poker punch and run program problem


Quote:
Originally Posted by nanan
i need guideline as to what to do.
If I have 52 cards, & I deal one to you, then I only have 51 remaining cards which can be used for anything else.

From what was described in the initial requirements, you don't need to know poker. Everything else can be discerned from thinking how to manage 52 physical cards, & knowing how pairs, flushes, etc. are defined. If you don't know these descriptions, they can be found at numerous sites across the Internet, one of which is:

http://entertainment.howstuffworks.c...basics-ga1.htm

My suggestion to you is to first:
  • Ensure that any particular card exists in a deck only once.
  • Ensure that the deck is initially randomized.
  • Once you have convinced yourself that you have a randomized deck, extract cards from one end only. If the deck is sufficiently randomized, which end is insignificant.
  • Keep an integer which indicates the "top of the deck". This index will represent the next card to be dealt. Once the card is dealt, increment the index (assuming dealing starts at the beginning of the array...). In this manner, you will never deal out the same card twice unless you write code to "reinsert" the card.
You should be beginning to see that there will be a lot of collateral in modeling a card deck besides a simple array. Collectively, this is also the beginnings of how you can abstract a card deck into a class comprising of all data required to define the deck, shuffling it, & dealing out individual cards.
Last edited by ocicat : 11-Aug-2008 at 16:33.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:31.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.