Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Part 1
Create a standard deck of cards using an array. (1-dimensional or 2-dimensional, up to you). The deck should have 52 cards. The deck should have 13 ranks (1 to King) for each of the 4 suits (Spades, Hearts, Clubs and Diamonds). 
After that, add in code that will be able to draw a card randomly from the deck.

Part 2
Next implement a 3-card guessing game that will do the following:
1.Draw ONE card each for LEFT, MID and RIGHT.
2.Indicate (or show) the user the cards drawn and their original position. 
3.Clearly point out the card in MID.
4.Flip the cards around and shuffle them. (don’t show the player which card is in which position)
5.Let the player guess where the original MID card is.
6.If the player guess correct, declare the player as a winner. If the player guess wrongly, show where the correct card is and declare the player as loser.
7.Ask the player if he/she wish to play again.


What I have tried:

C++
#include<iostream>
#include<cassert>
#include<fstream>
#include<string>
#include<iomanip>

using namespace std;


const unsigned int DECK_SIZE=52;
const unsigned int MAX_RANK=13;
const unsigned int MAX_SUIT=4;

const string ranks[MAX_RANK]=
{
	"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"
	
};

const string suits[MAX_SUIT]=
{
	"Spades","Hearts","Clubs","Diamonds"
};

struct Card
{
	string ranks;
	string suits;
};
Card deck[DECK_SIZE];
void initializeDeck();

void initializeDeck()
{
	int i,j;
	int k=0;
	
	
	for(i=0; i<MAX_RANK; i++)
	{
		for(j=0; j<MAX_SUIT;j++ )
		{
			deck[k].ranks=ranks[i];
			deck[k].suits=suits[j];
			k++;
		}
	}
	
}


int main()
{
	initializeDeck();
	
	for(int i=0; i<52; i++)
	{
		int j=(rand()%52);
	 	Card temp=deck[i];
		deck[i]=deck[j];
		deck[j]=temp;
	}
	

	for(int i=0; i<52; i++)
	{
		cout<<setw(10)<<deck[i].ranks;
		cout<<setw(8)<<deck[i].suits;
	
		if	(i%4==3)
		{
		    cout<<  endl;
		}
	}
	

	
	
	return 0;
}
Posted
Updated 9-Nov-18 23:22pm
v2
Comments
Patrice T 10-Nov-18 5:05am    
what is the problem with the code ?
Po Yang 10-Nov-18 5:16am    
I need people help me part 2 question
Patrice T 10-Nov-18 6:53am    
Describe the problem in your code.
Po Yang 10-Nov-18 5:29am    
Anyone can help me,please.

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

You've made a start, so test that, and when you are happy it works (and that's not a good shuffle at all but your homework doesn't mention shuffling) move on to the next part of the exercise. Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
Po Yang 10-Nov-18 5:37am    
I need some begin in part 2
OriginalGriff 10-Nov-18 5:42am    
Would you mind explaining that in better detail?

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Po Yang 10-Nov-18 6:32am    
Card deck[3];

void initializeDeck();

initializeDeck();

int x,y;
int k=0;


for(x=0; x<3; x++)
{
for(y=0; y<MAX_SUIT;y++ )
{
deck[k].ranks=ranks[x];
deck[k].suits=suits[y];
k++;
}
}
Po Yang 10-Nov-18 6:32am    
Is it correcct?
OriginalGriff 10-Nov-18 6:42am    
What happens when you try it?
What testing did you do?

What did the testing show you?

Yes, I could just tell you - but then you'd have to ask about the next bit, and the next, bit, and ... this is not a "remember everything" course - this is a "think about everything" course because it is trying to build a skill set into you - and you only learn skills by using them!
Give it a try - see what you can find out!
What is your problem?
Are you able to complete part 1 (show a random card)?
Do you need to actually draw the cards (i.e. do you have to use graphic library)?
As it stanbds, it is difficult to answer your question.
 
Share this answer
 

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