C++ programming: Card game
Can same one help me out with a example finsih and working programm ?
Program the basis for a card game (as a class card game):
● A card is represented by its suit/symbol (clubs, spades, hearts,
diamonds) and a value (seven, eight, nine, ten, jack, queen, king,
ace).
● A deck of cards consists of a pile of 32 cards that are
completely connected to four players are distributed.
● Implement the following menu:
=== Card Game Menu ===
1 shuffle cards
Deal 2 cards
View 3 cards of a player
0 EXIT
Selection (0-3): _
● Explanation of the individual menu items:
1. shuffle cards: To do this, implement a shuffle method that uses
the
Shuffles the cards. At the end, enter the control message "Cards
ready
mixed!" on the screen.
Deal two cards: To do this, implement a method of dealing
the cards are completely distributed to the four players. At the
end, deal the
Control message "Cards dealt!" on the screen.
3. view a player's cards: Implement another menu for this
purpose,
with the help of which it is possible to select one of the four
players and to
display maps on the screen. The output should only be made
if the cards have been distributed before (i.e. only if the
last
menu item 2 and not menu item 1 was selected).
The following is the code for the given problem explained along with comments :-
(screenshots of an example run of the program and the screenshots of the code are also included. If this answer helped you, kindly up vote it. In case of any query regarding this solution, feel free to ask through the comments)
*************************************************************************************************************
#include <iostream>
#include <stdlib.h> // srand, rand
#include <time.h>
#include<algorithm>
#include <random> // std::default_random_engine
using namespace std;
pair<int,char> deck[32];
// cards will be stored as an array of a pair of an integer and
character
//the integer values will be 1,7,8,9,10,11,12,13
//1 represents ace,11 represents jack,12 represents queen and 13
represents king
// and the characters will be as follows:-
//s is for spades
//c for clubs
//h for hearts
//d for diamonds
int flag = 0; // to check whether cards have been dealt or not
// the following arrays of pairs keep the cards of the 4 players
pair<int,char> player1[8];
pair<int,char> player2[8];
pair<int,char> player3[8];
pair<int,char> player4[8];
void menu()
{
cout<<"press 1 to shuffle the cards\n";
cout<<"press 2 to deal the cards\n";
cout<<"press 3 to view a player's cards\n";
cout<<"press 0 to exit\n";
}
void shuffleCards()
{
// To obtain a time-based seed
unsigned seed = 0;
// Shuffling the array
shuffle(deck, deck + 32,default_random_engine(seed));
flag = 0;
cout<<"Cards ready mixed!\n";
}
void dealCards()
{ int j =0; // to track the index of the deck
// player 1:-
for(int i =0;i<8;i++)
{
player1[i].first = deck[j].first;
player1[i].second = deck[j].second;
j++;
}
// player 2:-
for(int i =0;i<8;i++)
{
player2[i].first = deck[j].first;
player2[i].second = deck[j].second;
j++;
}
// player 3:-
for(int i =0;i<8;i++)
{
player3[i].first = deck[j].first;
player3[i].second = deck[j].second;
j++;
}
// player 4:-
for(int i =0;i<8;i++)
{
player4[i].first = deck[j].first;
player4[i].second = deck[j].second;
j++;
}
flag = 1; //cards have been dealt
cout<<"Cards dealt!\n";
}
void displayCards()
{
bool display = true;
if(flag == 0)
{
cout<<"cards not dealt yet\n";
return;
}
while(display == true){
cout<<"choose player 1,2,3 or 4\n or choose 0 to
stop\n";
int player;
cin>>player;
if(player!=0)
cout<<"value suit\n";
switch(player)
{
case 1:{
{
for(int i = 0;i<8;i++)
{
cout<<player1[i].first<<"
"<<player1[i].second<<endl;
}
}
}
break;
case 2:{
for(int i = 0;i<8;i++)
{
cout<<player2[i].first<<"
"<<player2[i].second<<endl;
}
}
break;
case 3:{
for(int i = 0;i<8;i++)
{
cout<<player3[i].first<<"
"<<player3[i].second<<endl;
}
}
break;
case 4:{
for(int i = 0;i<8;i++)
{
cout<<player4[i].first<<"
"<<player4[i].second<<endl;
}
}
break;
case 0:
display = false;
break;
default:
cout<<"invalid player\n";
}
}
}
int main()
{
int choice; // choice for user to select from the menu;
bool play = true; // boolean to control for how long to run the
program
//initialize the placement of cards to get an initial unshuffled deck:-
int j = 0; // index for the deck
//spades placed first
for(int i=7;i<=14;i++)
{ if(i!=14)
deck[j].first = (i);
else
deck[j].first = 1;
deck[j].second = 's';
j++;
}
//clubs
for(int i=7;i<=14;i++)
{ if(i!=14)
deck[j].first = (i);
else
deck[j].first = 1;
deck[j].second = 'c';
j++;
}
//hearts
for(int i=7;i<=14;i++)
{ if(i!=14)
deck[j].first = (i);
else
deck[j].first = 1;
deck[j].second = 'h';
j++;
}
//diamonds
for(int i=7;i<=14;i++)
{ if(i!=14)
deck[j].first = (i);
else
deck[j].first = 1;
deck[j].second = 'd';
j++;
}
while(play)
{
menu();
cin>>choice;
switch(choice)
{
case 1:
shuffleCards();
break;
case 2:
dealCards();
break;
case 3:
displayCards();
break;
case 0:{
cout<<"exit game\n";
play = false;
}
break;
default:
cout<<"invalid choice, please enter again\n";
}
}
}
***************************************************************************************************************************
screen shots of example finish output :-



***************************************************************************************************************
the screen shots of the code are:-








C++ programming: Card game Can same one help me out with a example finsih and working...
Program 4: C++ The Game of War The game of war is a card game played by children and budding computer scientists. From Wikipedia: The objective of the game is to win all cards [Source: Wikipedia]. There are different interpretations on how to play The Game of War, so we will specify our SMU rules below: 1) 52 cards are shuffled and split evenly amongst two players (26 each) a. The 26 cards are placed into a “to play” pile...
C++ programming: lottery Can same one help me out with a example finsih and working programm ? Program a simple lottery game (7 out of 21) (as class lotto): ● There are 3 players participating. At the beginning each player receives a lottery ticket ○ consisting of 21 numbers (the values from 0 to 20), ○ on which he "ticked" 7 numbers. ● After "handing in" the betting slips, 7 numbers are drawn. ● After the draw, the winners are...
C++
Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....
War—A Card game Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. War: Deal two Cards—one for the computer and one for the player—and determine the higher card, then display a message indicating whether the cards are equal, the computer won, or the player won. (Playing cards are considered equal when they have the same value, no matter what their suit is.) For this game, assume the Ace (value 1) is...
CS102 : JAVA Object-Oriented Programming.
1 Write a class Card whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties an integer for the rank (1 (corresponding to Ace) ,2,3, 13 (correspond ing to King) and suit (Spades, Hearts, Diamonds, or Clubs). Make the suit an enumerated data type. Include getters and setters and a method that tests if a card is valid. Write a class named Deck whose instances are full...
2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...
NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...
I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...
C++ Programming: Customer file Can same one help me out with a example finsih and working programm ? Program a simple customer file. Each customer should be defined as a class customer can be modelled with the following attributes: Last name, first name, unique Customer number, postcode, place of residence. Implement the following menu for this: (e) Enter a new customer from Keypad (l) Deleting a customer (a) Output of all customers (x) Exit Comments: - At point (e) the...
This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...