How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask ATLProg Your Own Question

ATLProg
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 8652
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
44910485
Type Your Homework Question Here...
ATLProg is online now
A new question is answered every 9 seconds

I am working on a project for shuffling and dealing cards.

Resolved Question:

I am working on a project for shuffling and dealing cards. I have to use enumerated types for the suits and ranks. I have been given partially filled out code, card.cpp, card.h, deck.cpp, dech.h, hand.h, rands.cpp, and rands.h. The random number generator provided is fully functional for my use. I am told what the Card class, StandardDeck class, and the Hand class should contain. Can you provide a similar sample type of project that will allow me to work through my particular project?
Submitted: 1 year ago.
Category: Homework
Expert:  R.R. Jha replied 1 year ago.
Hi there,

I'd be glad to help with your project. Please send your requirements. You may upload the requirements document, and your code so far on wikisend.com or mediafire.com and post download link here.


Thanks
Customer: replied 1 year ago.



Shuffling and Dealing Cards


For this project, you will create a program that will shuffle and deal hands of cards. You can use the attached Rands class for a good random number generator (one is needed for shuffling). The program should consist of classes Card, StandardDeck, Hand, and a driver program. Define enumerated types Suit, and Rank in the card.h header file. The Card class should contain


1. private data members suit and rank of types Suit and Rank.


2. A constructor with two input parameters of type Suit and Rank which are used to initialize the private data members.


3. Two static arrays of strings representing the suits and ranks. This is needed for outputting cards. They should be initialized in the global namespace in the file card.cpp (it is a compiler error to initialize them within the class). This is already done for you in the attached card.cpp file.


4. I will provide the code for overloading the outstream << operator so that you can print out a card simply by writing cout << myCard << endl; (for details see the note about printing Cards)


The class StandardDeck should contain


1. A private vector of Cards named deck;


2. A private integer top which is an index into the deck for the next card to the deal, i.e. the current top of the deck.


3. A private variable r of type Rands (if you use the attached generator).


4. A default constructor which initializes the top of the deck to 0, seeds the random number generator, and initializes the Cards in the deck. Initialize the deck as follows. Call “deck.reserve( 52 )” to allocate space for 52 cards. Then call “deck.push_back( Card() )” for each of the 52 distinct cards in the deck.


5. A function dealCard which returns a copy of the top card in the deck. Returning a reference to the top card would allow a user of this class to modify the deck! (this is why we should return a copy of the card)


6. A function numRemaining which returns the number of cards remaining in the deck.


7. A function shuffle that shuffles the deck and restores the deck to a full state. The standard way to randomly shuffle an array or vector named a from indexes start through stop is


for (int i=start; i <= stop-1; i++)


swap( a, a[ rand( i, stop ) ] );


where rand( i, stop ) is a function which returns uniformly random integer in the range from i through stop (note: changing the function call to rand( start, stop ) will shuffle the array/vector but the distribution will no longer be uniformly random!)





The class Hand should contain



1. A private vector of cards names hand.


2. A constructor that takes an integer argument, say n, and reserves n cards. You should either declare a default value of 0 for the integer argument or instead define a default constructor that does nothing (i.e. no initialization).


3. A function addCard that takes a constant Card reference as a parameter and adds it to the hand.


4. A function print that prints out the contents of the hand.


5. A function clear that restores a hand to an empty state.



The driver program should declare a deck of cards, shuffle it, and repeat the following seven times; deal two five card hands, and print out those hands. You should reshuffle the deck when there aren’t enough cards left to deal out the two hands.



You can combine all your files into a single zip file and submit it as an attachment using your Assignments folder.





Using the Provided Random Number Generator




To use the provided random number generator in the StandardDeck class, you need a private data member of type Rands. You then use this object to call any of the functions in the Rands class. The constructor should call the function rand_seed(). If you don’t, then you will get the exact same sequence of numbers every time you run your program. In order to get a different sequence of numbers and hence a different ordering of cards for different runs, you can use the current time to seed the generator. To do this, you need to include the header <ctime> and get the time by calling time(0). So if “r” is your data member of type Rands, you seed the generator as follows.


#include <ctime> // needed for the time() function



r.rand_seed( (Uint) time(0) ); // seed the generator according to the time



Tip: In the StandardDeck constructor, comment out the call to seed the random number generator until you get your program working. If you don’t, then your program could produce an error at a different point each time you run it which makes it extremely difficult to track down the problem. With the seed call removed, your program should always break at the same point making it much easier to locate the error. Once you get your program working, you should then remove the comment so that the cards are in a different order each time.


Customer: replied 1 year ago.

Are you working on my question?

Customer: replied 1 year ago.
Relist: Answer came too late.
Expert:  ATLProg replied 1 year ago.
Do you still need assistance with this?
Customer: replied 1 year ago.

Yes I am stuck. What I have so far will not compile.


 


#ifndef CARD_H
#define CARD_H

#include <iostream>
using namespace std;

enum Suit {CLUBS, DIAMONDS, HEARTS, SPADES};
enum Rank {ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, };
class Card
{
friend ostream& operator<<( ostream &stream, const Card &card );
public:


private:
static char *suit_str[4]; // output strings for suit
static char *rank_str[14]; // output strings for rank
};

#endif


 


#ifndef DECK_H
#define DECK_H

#include <vector>
#include "card.h"
#include "rands.h"


class StandardDeck
{
public:
void shuffle(); // shuffle the deck
private:
vector<Card> deck; // the deck of cards
Rands r; // random numbers used for shuffling
void swap( Card &, Card & ); // used for shuffling
int top; // top of deck index
Card card;
};

#endif


 


#ifndef HAND_H
#define HAND_H

#include <vector>
#include "card.h"


class Hand
{
public:
private:
};

#endif


/******************************************************************/
/* concatenation of the two 16-bit multiply with carry generators */
/* x(n)=a*x(n-1)+carry mod 2^16 and y(n)=b*y(n-1)+carry mod 2^16, */
/* with the number and carry packed within the same 32 bit */
/* integer. Algorithm due to Marsaglia */
/******************************************************************/
#ifndef RANDS_H
#define RANDS_H

typedef unsigned int Uint;


class Rands
{
public:
Rands();

void rand_seed( Uint ); // seed the generator
Uint rand(); // returns a random 32-bit integer
double rand_float(); // returns a random float in (0,1]
int rand( int lo, int hi ); // returns a random int from lo through hi

private:
Uint SEED_X;
Uint SEED_Y;
};

#endif


#include "card.h"

#include <iostream>
using namespace std;

Card::Card(Suit s, Rank r)
{
suit = s;
rank = r;
for (Card::Suit s = Card::CLUBS; s<=Card::SPADES; s = Card::Suit(s+1))
{
for (Card::Rank r = Card::TWO;r <= Card::ACE; r = Card::Rank(r+1))
{
deck.push_back (Card (s, r));
}
}


ostream& operator<<( ostream &stream, const Card &card )
{
char *Card::rank_str[14] = {ace, two, three, four, five, six, seven,
eight, nine, ten, jack, queen, king };
char *Card::suit_str[4] = {clubs, diamonds, hearts, spades};
stream << Card::rank_str[ card.rank ] << " of "
<< Card::suit_str[ card.suit ];
return stream;
}

#include "deck.h"
#include <iostream>
#include <ctime>

using namespace std;



void StandardDeck::shuffle()
{
for (Uint i=0; i < deck.size()-1; i++)
swap( deck, deck[ r.rand(i,deck.size()-1) ] );
top = 0;
}


void StandardDeck::swap( Card &c1, Card &c2 )
{
Card temp = c1;
c1 = c2;
c2 = temp;
}





Expert:  ATLProg replied 1 year ago.
you should not post code here as it is a public website
Customer: replied 1 year ago.

I did not know that. How should I post then?

Expert:  ATLProg replied 1 year ago.
For future reference you may upload it on wikisend.com

Can you please go to www.wikisend.com and upload your file ? Once you do that you will get a page that has the "File ID" and "Download Link". Copy the "Download Link" or "File ID" and please paste it in your reply here.


For now i will post the solution i worked on, will that work?
Customer: replied 1 year ago.

Yes go ahead and post the solution you worked on. In the meantime I will go to www.wikisend.com.

Expert:  ATLProg replied 1 year ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 8652
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
ATLProg and 8 other Homework Specialists are ready to help you
Expert:  ATLProg replied 1 year ago.
Are we good?
Customer: replied 1 year ago.

I have a question that was put into the waiting room that another professional said he did not know the answer to. I really need an answer ASAP. I wonder if you would take a look at it. I assume that it is available for you to see or do I have to resubmit the question?

Expert:  ATLProg replied 1 year ago.
Sorry i am out of ideas too for that question
Customer: replied 1 year ago.

"For ATLProg only"


 


The question is somewhat long with some code provided and it would be easier to just upload a zip file to you.


 

Expert:  ATLProg replied 1 year ago.

Can you please go to www.wikisend.com and upload your file ? Once you do that you will get a page that has the "File ID" and "Download Link". Copy the "Download Link" or "File ID" and please paste it in your reply here.
Customer: replied 1 year ago.

http://wikisend.com/download/257104/Instructions and Code.zip


 


and


 


File ID: 257104

Expert:  ATLProg replied 1 year ago.
As i had mentioned earlier I am out of ideas for this one..by when you need this anyways
Customer: replied 1 year ago.

I need it by tomorrow. I also have some additional information I can upload if you are willing to take another try at it.

Expert:  ATLProg replied 1 year ago.
Please do so let me see
Customer: replied 1 year ago.

http://wikisend.com/download/212064/Rules_And_Variants.zip


 


I am sending more information after this file that I think will help

Expert:  ATLProg replied 1 year ago.
Sorry but i am out of ideas
Customer: replied 1 year ago.

Okay. Thanks.

Customer: replied 1 year ago.

"For ATLProg only"


 


You said you were out of ideas on my last question. Since that time I have found that there were errors in the code that I provided that would have prevented the program from compiling. If you were running into problems because the provided code had bugs, then the question is would you take third and final look at the problem with the corrected code to see if you can help me with it? But if you just don't want to look again that is fine too. I understand.

Customer: replied 1 year ago.
Relist: Answer came too late.
Expert:  ATLProg replied 1 year ago.
Please upload what you got on wikisend.com and i will try and make a second attemtpt
Customer: replied 1 year ago.

http://wikisend.com/download/572326/I added some notes that might help.zip


 


I added a word document with some code that might help. Again it is a long project I know but I just need somewhere to start if nothing else. Thanks.

Expert:  ATLProg replied 1 year ago.
Sorry, this is beyond my expertise
Customer: replied 1 year ago.

Ok. Thanks

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience
 
 
 

Related Homework Questions