Question

Problem 1: Create a card game called flash card using class data structure when each player...

Problem 1: Create a card game called flash card using class data structure when each player draws three cards for random numbers (1-4) as Diamond, Spade, Clubs and Hearts respectively and another set of random numbers of card value 1-13. The cardScore is defined as highest (say cardScore =100 for three A s’ (cardValue 1), followed by three Jacks (cardValue 11) (say cardScore 90), followed by three Kings (cardValue 13)(say cardScore =80) and then three Queens (cardValue 12)(say cardScore = 70). Other than the above said combinations the cardScore is defined by the sum of the cardValue of each draw. The player which has the highest score after three draws win. Display the cards drawn by each player and the cardScore and the winner. Write the C++ code and algorithm in words for the following problem (Marks 20)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ CODE :

#include<iostream>
#include<time.h>
using namespace std;

class FlashCard {
int cardVariety[3];
int cardValue[3];
int gameScore;
public :
void setcards(int cardVariety[3], int cardValue[3]) {
for (int k = 0; k < 3; ++k) {
this -> cardVariety[k] = cardVariety[k];
this -> cardValue[k] = cardValue[k];
}
}
void totalScore();
int scoreResult();
};

void FlashCard :: totalScore() {
gameScore = 0;
int acefreq = 0;
int jackfreq = 0;
int kingfreq = 0;
int queenfreq = 0;
for (int k = 0; k < 3; ++k) {
if (cardValue[k] == 1) {
acefreq++;
} else if (cardValue[k] == 11) {
jackfreq++;
} else if (cardValue[k] == 13) {
kingfreq++;
} else if (cardValue[k] == 12) {
queenfreq++;
} else
gameScore += cardValue[k];
}
if (acefreq == 3) {
gameScore = 100;
} else if (jackfreq == 3) {
gameScore = 90;
} else if (kingfreq == 3) {
gameScore = 80;
} else if (queenfreq == 3) {
gameScore = 70;
}
  
}

int FlashCard :: scoreResult() {
return gameScore;
}

int main() {
srand(time(NULL));
int numOfPlayers;
  
cout << "Enter the number of Player/s: ";
cin >> numOfPlayers;
  
FlashCard players[numOfPlayers];
  
int Maxiscore = -1, MaxiscorePlayer;
  
for (int py = 0; py < numOfPlayers; ++py) {
cout << "\nThe Generated cards for the player " << py + 1 << " are: \n";
int generatedCardVariety[3];
int generatedCardValue[3];
for (int gameDraw = 0; gameDraw < 3; ++gameDraw) {
generatedCardVariety[gameDraw] = rand() % 4 + 1;
generatedCardValue[gameDraw] = rand() % 13 + 1;
  
if (generatedCardValue[gameDraw] == 1) {
cout << "Ace of ";
}
else if (generatedCardValue[gameDraw] == 11) {
cout << "Jack of ";
}
else if (generatedCardValue[gameDraw] == 13) {
cout << "King of ";
}
else if (generatedCardValue[gameDraw] == 12) {
cout << "Queen of ";
}
else {
cout << generatedCardValue[gameDraw] << " of ";
}
  
if (generatedCardVariety[gameDraw] == 1) {
cout << "Diamonds\n";
} else if (generatedCardVariety[gameDraw] == 2) {
cout << "Spades\n";
} else if (generatedCardVariety[gameDraw] == 3) {
cout << "Clubs\n";
} else {
cout << "Hearts\n";
}
  
}
players[py].setcards(generatedCardVariety, generatedCardValue);
players[py].totalScore();
if (Maxiscore < players[py].scoreResult()) {
Maxiscore = players[py].scoreResult();
MaxiscorePlayer = py + 1;
}
}
cout << "\nThe Max Score is: " << Maxiscore << "\nAnd the game Winner is Player "<< MaxiscorePlayer << "\n";   
}

C++ PROGRAM CODE SCREEN:

C++ PROGRAM OUTPUT:

When the players are 4 :-

ALGORITHM:

  • Inside the loop of a program:

      1. Randomly generated 3 numbers within the range of 1-13 for the card value and
      3 numbers for the card variety/type in the range of 1-4
      2. Calculated game score as per the given rules in the question.
      3. Repeated the above steps (1-3) for the second player as well
      4. Updated the card scores for each round for the results.

  • At the end of 3 rounds:

      1. Compared the game scores and print the winner based on the maximum score evaluation.

Happy to help!

Please gives thumbs up if you like. And also share your feedback in the comment section.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Problem 1: Create a card game called flash card using class data structure when each player...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. (25 total points) Probability and card games; Recall that an ordinary decdk of playing cards...

    1. (25 total points) Probability and card games; Recall that an ordinary decdk of playing cards has 52 cards of which 13 cards are from each of the four suits hearts, diamonds, spades, and clubs. Each suit contains the cards 2 to 10, ace, jack, queen, and king. (a) (10 points) Three cards are randomly selected, without replacement, from an or- dinary deck of 52 playing cards. Compute the conditional probability that the first card selected is a spade, given...

  • Program 4: C++ The Game of War The game of war is a card game played by children and budding comp...

    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...

  • Previous Problem Problem List Next Problem (1 point) 4 cards are drawn at random from a...

    Previous Problem Problem List Next Problem (1 point) 4 cards are drawn at random from a standard deck. Find the probability that all the cards are hearts. 0.00264 Find the probability that all the cards are face cards. 0.00995 Note: Face cards are kings, queens, and jacks. Find the probability that all the cards are even. 0.0393 (Consider aces to be 1, jacks to be 11, queens to be 12, and kings to be 13) Note: You can earn partial...

  • Problem 3 [25 pts (4(2,2),6,10,5)]: Information and Entropy An on-line card game uses a deck of 3...

    Problem 3 [25 pts (4(2,2),6,10,5)]: Information and Entropy An on-line card game uses a deck of 32 cards containing 4 Aces, 8 Kings, 16 Queens, 2 Jacks and 2 Tens. In each round of the game the cards are shuffled, the players make a bet about what type of card will be drawn, then a single card is drawn and the winners are paid off. The drawn card is reinserted into the deck before the next round begins i. How...

  • While using JAVA , solve this. There are three basic classes we'll need this week: Card:...

    While using JAVA , solve this. There are three basic classes we'll need this week: Card: A class like the one presented in the modules, but with a few changes. Hand: A class that represents the cards held by a single player. Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands...

  • determine: 1. P(A and B) 2. P(A or B) 3. P( B|A ) Suppose one card...

    determine: 1. P(A and B) 2. P(A or B) 3. P( B|A ) Suppose one card is selected at random from an ordinary deck of 52 playing cards. A standard deck of cards contains for suits: red hearts, red diamonds, black clubs, black spades. Each suite contains 13 cards: Ace, 2,3,4,5,6,7,8, 9, 10, Jack, Queen, King. The Jack, Queen, and King are also called Face Cards. Let A = event a jack is selected B = event a spade is...

  • Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June...

    Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...

  • the card game Acey Deucey, which is also known by several other names. In general, the...

    the card game Acey Deucey, which is also known by several other names. In general, the game is played with three or more people that continue to gamble for a pot of money. The pot grows and shrinks depending on how much General description of the game ● Two cards are dealt face up to a player from a shuffled deck of cards. ○ If the face of each card is the same then the player adds $1 into the...

  • Java programing Write a program that deals a deck of card into 4 hands – Each...

    Java programing Write a program that deals a deck of card into 4 hands – Each hand having 13 cards. The program should be doing the followings use an array to randomly select 52 cards and deal it into 4 hands. Print each hand unsorted Identify the face value of each hand and display it. You should create a class called Card, and all the methods should be defined within the card class. Hints – Import below java utility to...

  • This has to be done in Haskell only. Write a program that: Given 2 poker hands...

    This has to be done in Haskell only. Write a program that: Given 2 poker hands (5 cards) in list of tuples form (ex. hand1 = [(1,0),(2,0),(3,0),(4,0),(5,0)]). Each tuple represents a card where first number of a tuple is its value (1=Ace, 2=2,...,10=10, 11=Jack, 12=Queen, 13=King) and second number its suit (0=Clubs, 1=Diamonds, 2=Hearts, 3=Spades) so (1,0) will be Ace of Clubs, or (5,2) will be 5 of Hearts, etc. Rule website: https://www.fgbradleys.com/et_poker.asp These hands are generated by an end...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT