Homework

Homework Questions? Ask a Tutor for Answers ASAP

Ask an Expert,
Get an Answer ASAP!

Homework
This answer was rated:

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

I have to use enumerated...
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?
Show More
Show Less
Ask Your Own Homework Question
Answered in 22 minutes by:
7/7/2013
R.R. Jha
R.R. Jha, Tutor
Category: Homework
Satisfied Customers: 5,471
Experience: B.Tech
Verified
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
Ask Your Own Homework Question
Customer reply replied 4 years 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 reply replied 4 years ago

Are you working on my question?

Customer reply replied 4 years ago
Relist: Answer came too late.
ATLProg
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 9,151
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
Verified
Do you still need assistance with this?
Ask Your Own Homework Question
Customer reply replied 4 years 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;
}





you should not post code here as it is a public website
Ask Your Own Homework Question
Customer reply replied 4 years ago

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

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?
Ask Your Own Homework Question
Customer reply replied 4 years ago

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

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
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 9,151
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
Verified
ATLProg and 87 other Homework Specialists are ready to help you
Ask your own question now
Are we good?
Ask Your Own Homework Question
Customer reply replied 4 years 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?

Sorry i am out of ideas too for that question
Ask Your Own Homework Question
Customer reply replied 4 years 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.


 


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.
Ask Your Own Homework Question
Customer reply replied 4 years ago

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


 


and


 


File ID: 257104

As i had mentioned earlier I am out of ideas for this one..by when you need this anyways
Ask Your Own Homework Question
Customer reply replied 4 years 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.

Please do so let me see
Ask Your Own Homework Question
Customer reply replied 4 years ago

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


 


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

Sorry but i am out of ideas
Ask Your Own Homework Question
Customer reply replied 4 years ago

Okay. Thanks.

Customer reply replied 4 years 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 reply replied 4 years ago
Relist: Answer came too late.
Please upload what you got on wikisend.com and i will try and make a second attemtpt
Ask Your Own Homework Question
Customer reply replied 4 years 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.

Sorry, this is beyond my expertise
Ask Your Own Homework Question
Customer reply replied 4 years ago

Ok. Thanks

Ask ATLProg Your Own Question
ATLProg
ATLProg
ATLProg, Software Engineer
Category: Homework
Satisfied Customers: 9,151
9,151 Satisfied Customers
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML

ATLProg is online now

A new question is answered every 9 seconds

How JustAnswer works:

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

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

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!!!!

AlexLos 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.

GPHesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

JustinKernersville, 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.

EstherWoodstock, 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.

RobinElkton, 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.

DianeDallas, TX

< Previous | Next >

Meet the Experts:

LogicPro

LogicPro

Engineer

5,672 satisfied customers

Expert in Java C++ C C# VB Javascript Design SQL HTML

Manal Elkhoshkhany

Manal Elkhoshkhany

Tutor

4,549 satisfied customers

More than 5000 online tutoring sessions.

Linda_us

Linda_us

Finance, Accounts & Homework Tutor

3,138 satisfied customers

Post Graduate Diploma in Management (MBA)

Chris M.

Chris M.

M.S.W. Social Work

2,635 satisfied customers

Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)

F. Naz

F. Naz

Chartered Accountant

2,158 satisfied customers

Experience with chartered accountancy

Bizhelp

Bizhelp

CPA

1,887 satisfied customers

Bachelors Degree and CPA with Accounting work experience

Seanna

Seanna

Tutor

1,781 satisfied customers

3,000+ satisfied customers, all topics, A+ work

< Previous | Next >

Related Homework Questions
I need help implementing expectation maximization algorithm
I need help implementing expectation maximization algorithm in python … read more
Dr. Donna Kakonge
Dr. Donna Kakonge
Doctor of Education
179 satisfied customers
I need some one to answere a couple excel question. Excel
I need some one to answere a couple excel question … read more
Jason Jones
Jason Jones
AAS Information Technology
6,316 satisfied customers
For LogicPro only: I need to develop a code using SQL for a
For LogicPro only: I need to develop a code using SQL for a cookbook database. Below are the requirements:Provide the SQL CREATE TABLE commands for the five tables in your cookbook database. Include P… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Program 1) A small company is moving all its employee data
Program 1) A small company is moving all its employee data to a computer. To make a smooth transition, a software program will permit the data entry personnel to enter data into a file. Design a progr… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Paying a large tip to secure a better table in a restaurant
Paying a large tip to secure a better table in a restaurant is the same as offering a bribe in business to secure a contract." Defend or oppose this statement.… read more
KARRY
KARRY
Master's Degree
92 satisfied customers
For a list of numbers entered by the user and terminated by
For a list of numbers entered by the user and terminated by 0. Write a program to find the sum of the positive numbers and the sum of the negative numbers. Needs to be done in Raptor Program.… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Paul's missionary work created a controversy in the church.
Paul's missionary work created a controversy in the church. what was the nature of the Jew-Gentile controversy and how did the church handle it?… read more
Academic Tutor
Academic Tutor
Master\u0027s Degree
380 satisfied customers
Will your tutors assist with an entire exam? I have the
hello, will your tutors assist with an entire exam? … read more
David L.
David L.
Bachelor\u0027s Degree
6 satisfied customers
While arguing with his neighbor, pulls out a Swiss Army
While arguing with his neighbor, Sam pulls out a Swiss Army knife with the intent of merely frightening him. Sam accidentally hits his neighbor's arm with the knife, resulting in a slight nick. Unbekn… read more
RobertJDFL
RobertJDFL
Attorney
Juris Doctorate
5 satisfied customers
Need a biography on Woodrow to include the following info:
Angela, Need a biography on Woodrow Wilson to include the following info: 1. Term of presidency and date of service, date of birth, date of death, birthplace, and family history 2. Political affiliati… read more
Seanna
Seanna
Tutor
1,781 satisfied customers
Again) I have some more Algebra 1 questions for
Hello (again) I have some more Algebra 1 questions for participation.They are,What are two symbolic techniques used to solve a pair of simultaneous linear equations? Provide an example and solve it wi… read more
GLENN
GLENN
Master of Mathematics
328 satisfied customers
Scenario: You notice that the grass around your house is,
Scenario: You notice that the grass around your house is brown, short, and dead. The grass around your neighbor's house is green, tall, and alive. Read more: http://www.justanswer.com/questions/1qmxi-… read more
gpcomputer2000
gpcomputer2000
Bachelor's Degree
34 satisfied customers
Music exams Penn forster college 350700RR Medieval and
Music exams Penn forster college 350700RR Medieval and Renaissance Periods 1. A passage of music is marked "ritardando." The following passage is marked "a tempo." The composer is instructing the play… read more
Dr. Donna Kakonge
Dr. Donna Kakonge
Doctor of Education
179 satisfied customers
Critically evaluate the key developements of the NHS by
critically evaluate the key developements of the NHS by using or appraising the social economic factors as example… read more
ec92
ec92
Substitue teacher
Master\u0027s Degree
8 satisfied customers
Hope all is well. Need assistance on a homework assignment.
Hi, this is Brian hope all is well. Need assistance on a homework assignment. I'm coding a program in JavaScript language and need assistance in getting it to run. I have the container and code for th… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
According to the university's website design request,
According to the university's website design request, students need to order five books, one for each of the five required courses that all students take. You need to design a program that will prompt… read more
Dr. Donna Kakonge
Dr. Donna Kakonge
Doctor of Education
179 satisfied customers
For LogicPro only: Design your own linked list class named
For LogicPro only: Design your own linked list class named IntList in C++ to hold a series of integers. Include the following public member functions, named as shown: Member Function Description Defau… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
This an aspx.net question that has to be done in visual
Hello this an aspx.net question that has to be done in visual studio.I have the basic code but it is not working, just need corrections to be made to it. I need it by 11/18/17 Saturday… read more
LogicPro
LogicPro
Engineer
Bachelor of Technology
5,672 satisfied customers
Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Show MoreShow Less

Ask Your Question

x