Question

Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...

Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriate accessors, constructors, and mutators.

Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to:

• Print every card in the deck

• Shuffle the cards in the deck. You can implement this by randomly swapping every card in the deck.

• Add a new card to the deck. This function should take a Card object as a parameter and add it to the vector.

• Remove a card from the deck. This removes the first card stored in the vector and returns it.

• Sort the cards in the deck ordered by name.

Next, create a Hand class that represents cards in a hand. Hand should be derived from Deck. This is because a hand is like a more specialized version of a deck; we can print, shuffle, add, remove, or sort cards in a hand just like cards in a deck. The default constructor should set the hand to an empty set of cards.

Finally, write a main function that creates a deck of cards, shuffles the deck, and creates two hands of 5 cards each. The cards should be removed from the deck and added to the hand. Test the sort and print functions for the hands and the deck. Finally, return the cards in the hand to the deck and test to ensure that the cards have been properly returned.

You may add additional functions or class variables as desired to implement your solution.

Using C++ Programming Language

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Debug Stop Share H SaveBeautify Run main.cpp 1 //Card. java 3 public class Card f 4 private int suit; private int name; 7 pub32 34 35 public int getSuitO 36 37 38 39 40 return suit; 41 42 43 45 public int getNameO 46 47 48 49 return name; 50 51 52 5363 64 65 str+name ; else ifCname 1) 67 68 69 str -Ace; 70 else ifCname 11) 71 72 73 str Jack; 74 else ifCname 12) 75 76 selse if(suit 3) 94 95 str += Hearts. 96 97 98 else str + Spades; 100 101 102 103 104 105 106 107 return str; 108 109 110125 126 public Deck) 127 128 129 130 131 / create a deck of 52 cards deck new ArrayList<Card O; 132 133 134 135 for(int i-1;i​​​​​156 157 158 159 160 161 162 ArrayList<Card temp new ArrayList<Card>O; Random ran new RandomO whileC! deck.isEmptyO) 163 164 1187 str +- deck.get(i).toStringO+In; 188 189 190 191 return str; 192 193 194 195 196 197 public void addCard(Card card) 198219 220 221 public void sortO 223 224 int min; 225 226 for(int i-0;i<deck.sizeO-1;i++ 227 228 229 230 231 232 233 234 min = 1249 250 251 deck.add(i, temp); 252 253 temp deck.remove(i+1); 254 255 256 deck.add(temp); 257 258 259 260 261 262 public statSystem.out.printLn(hand[i]); 280 281 282 283 284 285 /return the cards in the hand to the deck 286 287 System.out.println( nROutput: Remove 5 cards 8 of Hearts 7 of Diamonds 6 of Clubs King of Diamonds 10 of Clubs Returned the 5 cards back to deck So7 of Spades 7 of Diamonds 7 of Hearts 7 of Clubs 8 ot Hearts 8 of Diamonds 8 of Clubs 8 of Spades 9 of Hearts 9 of Diamonds 9

Add a comment
Know the answer?
Add Answer to:
Use inheritance and classes to represent a deck of playing cards. Create a Cardclass that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack) along with appropriat...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • Write a class named Card which will represent a card from a deck of cards. A...

    Write a class named Card which will represent a card from a deck of cards. A card has a suit and a face value. Suits are in order from low to high: Clubs, Diamonds, Hearts and Spades. The card values from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace. Write a Deck class that contains 52 cards. The class needs a method named shuffle that randomly shuffles the cards in the...

  • *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card...

    *in Java 1. Create a card class with two attributes, suit and rank. 2.In the card class, create several methods: a. createDeck – input what type of deck (bridge or pinochle) is to be created and output an array of either 52 or 48 cards. b.shuffleDeck – input an unshuffled deck array and return a shuffled one. + Create a swap method to help shuffle the deck c. countBridgePoints – inputs a 13-card bridge ‘hand’-array and returns the number of...

  • Prisha has a standard deck of 52 playing cards. The deck contains 4 suits (hearts, diamonds, clubs, and spades), and each suit contains 13 cards labeled 2 through 10, as well as jack, queen, king, and...

    Prisha has a standard deck of 52 playing cards. The deck contains 4 suits (hearts, diamonds, clubs, and spades), and each suit contains 13 cards labeled 2 through 10, as well as jack, queen, king, and ace. Four friends are trying to determine some probabilities related to drawing cards from the deck. Two cards will be randomly drawn from the deck, and after the first card is drawn, it is not replaced before the second card is drawn. Consider the...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • 1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it...

    1. create a class called MemoryBoard. a. MemoryBoard will represent a grid of memory squares. it needs to track all of the squares on the board, the cars set it's using, the width and the height of the board, the number of turns that have been taken, and the current player's id. 2. create a arraylist to store the squares on the board. it should store Square objects. the class should also store the width(an int), the number of turns...

  • While using JAVA , solve this. There are three basic classes we'll need this week: Card:...

    While using JAVA , solve this. There are three basic classes we'll need this week: Card: A class like the one presented in the modules, but with a few changes. Hand: A class that represents the cards held by a single player. Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands...

  • In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,...

    In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT