Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Overall Assignment For this assignment, you are to write a simple computer progr

ID: 3919756 • Letter: O

Question

Overall Assignment For this assignment, you are to write a simple computer program which will use arrays and functions to create a deck of cards, shuffle the deck, deal some hands, and print out the dealt hands. Possible optional enhancements include classifying the hands in a manner similar to a recent lab exercise. Representing Playing Cards Standard playing cards can be easily represented using two integers: One ranging from 0 to 12 for the ranks (numbers) of the cards ranging from deuce (2) to ace, and one ranging from 0 to 3 representing the 4 suits, as shown in the following tables: Rank value Represonts 0 to 8 rank +2 Suit Value Represents Jack Queen King Ace Clubs Diamonds Hearts Spades 10 12

Explanation / Answer

here is your program : ------------->>>>>>>>>

#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int printCard(int rank,int suit){
string ranks[12] = {"two","three","four","five","six","seven","eight","nine","jack","queen","king","ace"};
string suits[4] = {"Clubs","Diamonds","Hearts","Spades"};
if(rank < 0 || rank > 11){
  return -1;
}
if(suit < 0 || suit > 3){
  return -1;
}
cout << ranks[rank] << " of " << suits[suit] << endl;
}

void create52CardDeck(int ranks[],int suits[]){
for(int i = 0;i<52;i++){
  ranks[i] = i/4;
  suits[i] = i%4;
}
}

int shuffle(int ranks[],int suits[],int nCards){
if(nCards < 0){
  return -1;
}
int ind;
int temp;
for(int i = 0;i<nCards;i++){
  ind = rand()%nCards;
  if(ind != i){
   temp = ranks[i];
   ranks[i] = ranks[ind];
   ranks[ind] = temp;
   temp = suits[i];
   suits[i] = suits[ind];
   suits[ind] = temp;
  }
}
return 0;
}

void printDeck(int ranks[],int suits[]){
for(int i = 0;i<52;i++){
  printCard(ranks[i],suits[i]);
}
}

int printHand(int ranks[],int suits[],int hand[],int nCardsInHand,int nCardsInDeck){
if(nCardsInHand < 0 || nCardsInHand > nCardsInDeck){
  return -1;
}
if(nCardsInDeck < 0){
  return -1;
}
for(int i = 0;i<nCardsInHand;i++){
  if(hand[i] < 0){
   return -1;
  }
  printCard(ranks[hand[i]],suits[hand[i]]);
}
}

int main(){
int ranks[52];
int suits[52];
srand(time(0));
int nCardsInDeck = 52;
int nCardsInHand;
int numPlayer;
create52CardDeck(ranks,suits);
shuffle(ranks,suits,52);

while(true){
  cout << " Enter how many hands to deal : ";
  cin>>numPlayer;
  cout << " Enter how many cards to deal : ";
  cin>>nCardsInHand;
  if(numPlayer > 0 && nCardsInHand > 0 || (nCardsInHand * numPlayer) <= 52){
   break;
  }
  cout << " Inappropriate data !!! Please enter again : ";
}
int hand[nCardsInHand];
int counter = 0;
for(int i = 0;i<numPlayer;i++){
  for(int i = 0;i<nCardsInHand;i++){
   hand[i] = counter;
   counter++;
  }
  cout << "Player : " << (i+1) <<endl;
  printHand(ranks,suits,hand,nCardsInHand,52);
}
}