I need this to be implements in c++ using a stack of
arrays with classes
I want to output a deck of cards that's randomly distributed
between two players meaning each player shall get 26 cards.
I also want to add up each players pile of cards and the player
with the highest sum wins
Please help me with this task I am a newbie
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
#include<algorithm>
#include<vector>
using namespace std;
enum Suit{
Spade,Heart ,Diamond,Club
};
template <class T>
class stack{
private:
int top;
int capacity;
T*arr;
public:
stack(int size){
capacity = size;
arr = new T[capacity];
top=-1;
}
bool isEmpty(){
return top==-1;
}
bool isFull(){
return top==capacity-1;
}
T Top(){
return arr[top];
}
void pop(){
top--;
}
void push(T data){
arr[++top]=data;
}
};
class card{
private:
int number;
enum Suit suit;
string description;
public:
card(){}
void setNumber(int n){
number=n;
}
void setSuit(enum Suit s){
suit=s;
}
void setDescription(){
char ch ;
string str="";
if(number>=2&&number<=9)
str+='0'+number;
else if(number==1)str+="Ace";
else if(number==10)str+="10";
else if(number==11)str+="Jack";
else if(number==12)str+="Queen";
else if(number==13)str+="King";
if(suit==0)description="Spade "+str;
else if(suit==1)description="Heart "+str;
else if(suit==2)description="Diamond "+str;
else if(suit==3)description="Club "+str;
}
int getNumber(){
return number;
}
enum Suit getSuit(){
return suit;
}
string getDescription(){
return description;
}
};
int main(){
card deck[52];
stack<card> s(52);
srand(unsigned(time(NULL)));
for(int i=0;i<13;i++){
deck[i].setNumber(i+1);
deck[i+13].setNumber(i+1);
deck[i+26].setNumber(i+1);
deck[i+39].setNumber(i+1);
deck[i].setSuit(Spade);
deck[i+13].setSuit(Heart);
deck[i+26].setSuit(Diamond);
deck[i+39].setSuit(Club);
deck[i].setDescription();
deck[i+13].setDescription();
deck[i+26].setDescription();
deck[i+39].setDescription();
}
vector<card> v;
for(int i=0;i<52;i++)
{
v.push_back(deck[i]);
}
random_shuffle(v.begin(), v.end());
for(int i=0;i<52;i++)s.push(v[i]);
int i=0;
int sum1=0;
cout<<"\n\nPlayer 1 CARDS:\n\n\n";
while(!s.isEmpty()){
card temp = s.Top();
cout<<temp.getDescription()<<"\n";
s.pop();
i++;
if(i==26)
break;
sum1=sum1+temp.getNumber();
}
int sum2=0;
cout<<"\n\nPlayer 2 CARDS:\n\n\n";
while(!s.isEmpty()){
card temp = s.Top();
cout<<temp.getDescription()<<"\n";
s.pop();
sum2=sum2+temp.getNumber();
}
if(sum1>sum2)
{
cout<<"\n\nPLAYER 1 WINS\n\n";
}
else if(sum1<sum2)
{
cout<<"\n\nPLAYER 2 WINS\n\n";
}
else
{
cout<<"\n\nMATCH DRAWS\n\n";
}
return 0;
}

Kindly revert for any queries
Thanks.
I need this to be implements in c++ using a stack of arrays with classes I...
I want to insert a standard 52 card deck into a stack of arrays and then randomly output the deck of cards until the deck is empty. I need this to be implement in c++ using a class of a stacked array please someone help me :(
I need to build the card game of War in C++. It will be a 2 player game. Each player will have their own deck of 52 cards. 2-10, Jack=11, Queen=12, King=13, Ace=14. Each player will draw one card from their deck. The player with the higher card wins both cards. If the card drawn is the same, then each player will draw 3 cards and on the 4th card drawn will show it. The player that shows the higher...
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...
Please help me with this c++ segment of code, I am a newbie. I need help to shuffle a deck of 52 cards using a stack of an array.
C++ program
This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...
How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...
2. Activity Directions: Create a UML diagram and then write the code for the object classes needed for your UNO game. You will need a minimum of three classes: a. A Card class (models an individual UNO card) b. A Hand class (models a player's hand) c. A Deck class (models the entire UNO deck) You may add other classes as you see fit. Test your program by writing a console application (a driver program) that creates a deck of...
I am just curious about this question... please can you answer with applying indent and space clearly. Furthermore, can you make answer shortly as possible..? This is a python question Question 6.34 The two-player card game war is played with a standard deck of 52 cards. A shuffled deck is evenly split among the two players who keep their decks face-down. The game consists of battles until one of the players runs out of cards. In a battle, each player...
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...
C++ Purpose: To practice arrays of records, and stepwise program development. 1. Define a record data type for a single playing card. A playing card has a suit ('H','D','S',or 'C'), and a value (1 through 13). Your record data type should have two fields: a suit field of type char, and a value field of type int. 2. In main(), declare an array with space for 52 records, representing a deck of playing cards. 3. Define a function called initialize()...