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 deck. It also needs a method to deal one card at a time.
Write a CardPlayer class. This class should keep a list of card objects. (The class represents a hand of cards.) This class should have a method getCard, that accepts a reference to a card object and adds it to the CardPlayer. The class should also have a method named showCards that will display all of the cards held by a CardPlayer object.
Write a separate Demonstration that creates a deck of cards, creates two CardPlayer objects, deals 5 cards to each CardPlayer object, one at a time, and displays both hands.
Please make sure you comment your code thoroughly.
Thank you for the help!
Program in c++
#include <iostream>
using namespace std;
class Card{
public:
/* string varible for holding suit and values of
the card */
string suit[4];
string value[13];
/* contructor initialized object of card*/
Card(){
suit[0]="Club";
suit[1]="Diamond";
suit[2]="Heart";
suit[3]="Spade";
value[0]="2";
value[1]="3";
value[2]="4";
value[3]="5";
value[4]="6";
value[5]="7";
value[6]="8";
value[7]="9";
value[8]="Jack";
value[9]="Queen";
value[10]="King";
value[11]="Ace";
}
// retrived suit randomly
string getSuit(){
int v=rand() % 4; /* random
method so selecting index */
return suit[v];
}
// retrived value randomly
string getValue(){
int v=rand() % 12;/* random
method so selecting index */
return value[v];
}
//display suit here
void displaySuit(string name){
cout<<" Suit:
"<<name;
}
//display suit here
void displayValue(string name){
cout<<"\n Value:
"<<name<<",";
}
};
/* cardplayer class has 5 object of card because each player can
hold 5 card */
class CardPlayer{
public:Card card[5];
};
int main()
{
// create two objects of cardplayer
CardPlayer cardplayer[2];
int i;
cout<<"\n 1st cardplayer has following 5
Cards \n ";
/* call all object for cardplayer[o] and retrive
all random values and suite and diply it */
for(i=0;i<5;i++){
string
name=cardplayer[1].card[i].getValue();
cardplayer[0].card[i].displayValue(name);
name=cardplayer[1].card[i].getSuit();
cardplayer[0].card[i].displaySuit(name);
}
/* call all object for cardplayer[o] and retrive
all random values and suite and diply it */
cout<<"\n 2nd cardplayer has following 5
Cards \n ";
for(i=0;i<5;i++){
string
name=cardplayer[1].card[i].getValue();
cardplayer[1].card[i].displayValue(name);
name=cardplayer[1].card[i].getSuit();
cardplayer[1].card[i].displaySuit(name);
}
return 0;
}
/*
output
1st cardplayer has following 5 Cards
Value: 9 Suit: Heart
Value: Queen Suit: Spade
Value: 7 Suit: Spade
Value: King Suit: Club
Value: Queen Suit: Diamond
2nd cardplayer has following 5 Cards
Value: 4 Suit: Spade
Value: 4 Suit: Spade
Value: Ace Suit: Heart
Value: 2 Suit: Heart
Value: 6 Suit: Club
*/
Write a class named Card which will represent a card from a deck of cards. A...
IN JAVA - COMMENT CODE WELL 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...
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....
Write in Java! Do NOT write two different programs for
Deck and Card, it should be only one program not 2 separate
ones!!!!!!
!!!!!!!!!!!!!!!Use at least one array defined in your
code and two array lists defined by the operation of your
code!!!!!!!!!!!!!!!!!!!!!
The array should be 52 elements and contain a representation of
a standard deck of cards, in new deck order. (This is the order of
a deck of cards new from the box.)
The 2 Array lists...
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...
A standard 52-card deck has four 13-card suits: diamonds, hearts, 13-card suit contains cards numbered f probability of drawing a black king of hearts clubs, and spades. The diamonds and hearts are red, and the clubs and spades are black Each from 2 to 10, a jack, a queen, a king, and an ace. An experiment consists of drawing 1 card from the standard deck. Find the The probability of choosing a black king of hearts is ype an integer...
A deck of cards contains 52 cards. They are divided into four suits: spades, diamonds, clubs and hearts. Each suit has 13 cards: ace through 10, and three picture cards: Jack, Queen, and King. Two suits are red in color: hearts and diamonds. Two suits are black in color: clubs and spades.Use this information to compute the probabilities asked for below and leave them in fraction form. All events are in the context that three cards are dealt from a...
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...
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...
Consider a standard 52-card deck of cards with 13 card values (Ace, King, Queen, Jack, and 2-10) in each of the four suits (clubs, diamonds, hearts, spades). If a card is drawn at random, what is the probability that it is a spade or a two? Note that "or" in this question refers to inclusive, not exclusive, or.
Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: "Spades", "Diamonds", "Hearts", "clubs" and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and...