Computer Programming Deck of Cards Game In C++

User Generated

gxyt11

Programming

Description

Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample of console screen shown below.

This program would contain multiple files, including two .h and three .cpp files as defined in Specifications below.

If you are using IDE to develop this program, name your project (and solution in VS2017) as Cards to hold all files created. If you prefer to g++ and an editor without an IDE, save all files in a folder or directory also called Cards.

Specifications

1- Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get a string representation for each card such as “Ace of Spades”, “2 of Spades”, etc.

2- Use a Deck class to store the 52 cards in a standard playing deck (one card for each rank and suit):

ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace

suits: Clubs, Diamonds, Hearts, Spades

3- To store 52 cards, use a member, deck, which is a vector of Card. To save your time in design this class, its default constructor is provided as following:

Deck::Deck() {
vector<string> ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
vector<string> suits = { "Clubs", "Diamonds", "Hearts", "Spades" };
for (string rank : ranks) {
for (string suit : suits) {
deck.push_back(Card(rank, suit));
}
}
}

4. This class should also include a member function, shuffle(),that shuffles the deck, a member function, count(), that counts the number of cards in the deck, and a member function, deal_card(), that deals a card from the deck, which should reduce the count of the cards in the deck by 1.

Unformatted Attachment Preview

Deck of cards game in C++ Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample of console screen shown below. This program would contain multiple files, including two .h and three .cpp files as defined in Specifications below. If you are using IDE to develop this program, name your project (and solution in VS2017) as Cards to hold all files created. If you prefer to g++ and an editor without an IDE, save all files in a folder or directory also called Cards. Specifications 1- Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get a string representation for each card such as “Ace of Spades”, “2 of Spades”, etc. 2- Use a Deck class to store the 52 cards in a standard playing deck (one card for each rank and suit): ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace suits: Clubs, Diamonds, Hearts, Spades 3- To store 52 cards, use a member, deck, which is a vector of Card. To save your time in design this class, its default constructor is provided as following: Deck::Deck() { vector ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; vector suits = { "Clubs", "Diamonds", "Hearts", "Spades" }; for (string rank : ranks) { for (string suit : suits) { deck.push_back(Card(rank, suit)); } } } 4. This class should also include a member function, shuffle(), that shuffles the deck, a member function, count(), that counts the number of cards in the deck, and a member function, deal_card(), that deals a card from the deck, which should reduce the count of the cards in the deck by 1. Hint: Try to use vectors since they can grow and shrink dynamically. To shuffle the cards, you can use rand() and srand() functions. Because some cards may be already dealt to the user, be sure the random number generated is based on the deck's current size. Store the Card and Deck classes in separate header and implementation files. That is, there should be Card.h, Card.cpp, Deck.h, and Deck.cpp in your Cards (project) folder. When the program (i.e., main.cpp) starts, it should get a new deck of cards, shuffle them, and display a message that indicates the total number of cards in the deck. The program should prompt the user for the desired number of cards. Then, it should deal the user the desired number of cards and display a message that indicates the number of cards left in the deck as shown in the above Console screen. Game screenshot: Deck of cards game in C++ Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample of console screen shown below. This program would contain multiple files, including two .h and three .cpp files as defined in Specifications below. If you are using IDE to develop this program, name your project (and solution in VS2017) as Cards to hold all files created. If you prefer to g++ and an editor without an IDE, save all files in a folder or directory also called Cards. Specifications 1- Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get a string representation for each card such as “Ace of Spades”, “2 of Spades”, etc. 2- Use a Deck class to store the 52 cards in a standard playing deck (one card for each rank and suit): ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace suits: Clubs, Diamonds, Hearts, Spades 3- To store 52 cards, use a member, deck, which is a vector of Card. To save your time in design this class, its default constructor is provided as following: Deck::Deck() { vector ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; vector suits = { "Clubs", "Diamonds", "Hearts", "Spades" }; for (string rank : ranks) { for (string suit : suits) { deck.push_back(Card(rank, suit)); } } } 4. This class should also include a member function, shuffle(), that shuffles the deck, a member function, count(), that counts the number of cards in the deck, and a member function, deal_card(), that deals a card from the deck, which should reduce the count of the cards in the deck by 1. Hint: Try to use vectors since they can grow and shrink dynamically. To shuffle the cards, you can use rand() and srand() functions. Because some cards may be already dealt to the user, be sure the random number generated is based on the deck's current size. Store the Card and Deck classes in separate header and implementation files. That is, there should be Card.h, Card.cpp, Deck.h, and Deck.cpp in your Cards (project) folder. When the program (i.e., main.cpp) starts, it should get a new deck of cards, shuffle them, and display a message that indicates the total number of cards in the deck. The program should prompt the user for the desired number of cards. Then, it should deal the user the desired number of cards and display a message that indicates the number of cards left in the deck as shown in the above Console screen. Game screenshot: Deck of cards game in C++ Create an object-oriented program that creates a deck of cards, shuffles them, and deals the specified number of cards to the player. See a sample of console screen shown below. This program would contain multiple files, including two .h and three .cpp files as defined in Specifications below. If you are using IDE to develop this program, name your project (and solution in VS2017) as Cards to hold all files created. If you prefer to g++ and an editor without an IDE, save all files in a folder or directory also called Cards. Specifications 1- Use a Card class to store the rank and suit for each card. In addition, use a member function, get_str(), to get a string representation for each card such as “Ace of Spades”, “2 of Spades”, etc. 2- Use a Deck class to store the 52 cards in a standard playing deck (one card for each rank and suit): ranks: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace suits: Clubs, Diamonds, Hearts, Spades 3- To store 52 cards, use a member, deck, which is a vector of Card. To save your time in design this class, its default constructor is provided as following: Deck::Deck() { vector ranks = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" }; vector suits = { "Clubs", "Diamonds", "Hearts", "Spades" }; for (string rank : ranks) { for (string suit : suits) { deck.push_back(Card(rank, suit)); } } } 4. This class should also include a member function, shuffle(), that shuffles the deck, a member function, count(), that counts the number of cards in the deck, and a member function, deal_card(), that deals a card from the deck, which should reduce the count of the cards in the deck by 1. Hint: Try to use vectors since they can grow and shrink dynamically. To shuffle the cards, you can use rand() and srand() functions. Because some cards may be already dealt to the user, be sure the random number generated is based on the deck's current size. Store the Card and Deck classes in separate header and implementation files. That is, there should be Card.h, Card.cpp, Deck.h, and Deck.cpp in your Cards (project) folder. When the program (i.e., main.cpp) starts, it should get a new deck of cards, shuffle them, and display a message that indicates the total number of cards in the deck. The program should prompt the user for the desired number of cards. Then, it should deal the user the desired number of cards and display a message that indicates the number of cards left in the deck as shown in the Console screen below. Game screenshot:
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

At...


Anonymous
Nice! Really impressed with the quality.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Content

Related Tags