Playing cards are used in many computer games, including versions of such classi
ID: 3683962 • Letter: P
Question
Playing cards are used in many computer games, including versions of such classics as solitaire, hearts, and poker. Design a Card class that contains a string data field to hold a suit (spades, hearts, diamonds, or clubs), an integer data field for a value from 1 to 13, and a string representation of rank “Ace”, “2”, “3, … “Jack”, Queen”, and “King.” Include get and set methods for each field. Save the class as Card.java. FullDeck.java (#3 of GameZone on page 436) Create an array of 52 Card objects, assigning a different value to each Card, and display each Card. Save the application as FullDeck.java. Extra Credit (5 points) – make sure each card is unique (e.g. there is only one Ace of clubs). Suit.java, Card2, java, and FullDeck2.java (#3 of GameZone on page 489) In Chapter 8, you created an application class named FullDeck that implemented a 52-element array that represented each card in a standard deck of playing cards. Now, create an enumeration that holds the four suits SPADES, HEARTS, DIAMONDS, and CLUBS. Save the enumeration in a file named Suit.java. Modify the Card class from Chapter 8 to use the enumeration, and save the class as Card2.java. Modify the FullDeck application to use the new Card class, and save the application as FullDeck2.java
Explanation / Answer
Hi below i have given the sample code for your reference,
#include<iostream>
#include<string>
/*Display the numeric suit and point-value names of all 52
cards.Save the file as CardDeck.cpp.
*/
usingnamespace std;
//Createan enumeration to represent the four standard suits of cards (CLUBS, DIAMONDS, HEARTS,
and SPADES).
enum suits {CLUBS = 1, DIAMONDS, HEARTS, SPADES};
/*Createanother enumeration for the words that represent card
point-valuenames (TWO, THREE, and the rest of the number cards through TEN, then
JACK,QUEEN, KING, and ACE). */
enum pointValue {TWO=2, THREE, FOUR, FIVE,SIX,SEVEN,EIGHT,NINE,TEN, JACK, QUEEN, KING, ACE};
intmain()
{
string suitsName[]={"CLUBS","DIAMONDS", "HEARTS", "SPADES"};
string pointValueName[]={"TWO","THREE", "FOUR", "FIVE","SIX",
"SEVEN","EIGHT","NINE","TEN",
"JACK", "QUEEN", "KING", "ACE"};
// int i,j;
int i,j;
for(i=CLUBS;i<=SPADES; i++)
{
for( j=TWO;j<=ACE;j++)
cout<<suitsName[i-CLUBS]<<""<<pointValueName[j-TWO]<<"; ";
cout<<endl;
}
// cout << "Hello world!"<< endl;
return 0;
}