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

Write a structure (struct card) that will represent a card in a standard deck of

ID: 3787359 • Letter: W

Question

Write a structure (struct card) that will represent a card in a standard deck of playing cards. You will need to represent both the suit (clubs, diamonds, hearts or spades) as well as the rank ( A, K, Q, J, 10, 9, 8, 7, 6, 5, 6, 7, 2) of each card. Note that a deck of playing cards can be represented as an array declared as struct card deck[52]

b.Write a function that will perform a perfect shuffle on a deck of cards represented using the data structures from part a. In a perfect shuffle, the deck is broken exactly in half and rearranged so that the first card is followed by the 27th card, followed by the second card, followed by the 28th card, and so on.

c.Write a program that tests how many perfect shuffles are necessary to return the deck to its original configuration.

I am having trouble b and c. please give me some tips

Explanation / Answer

a) sturct card{
       string suit;
       string rank;
   }

b) function perfectShuffle(card deck[]){
       card newDeck[52];
       int j=1;
       for(int i=1; i<=26; i++){
           newDeck[j] = deck[i]
           newDeck[j+1] = deck[i+26]
           j=j+2;
       }
       return newDeck;
   }

c)   function numOfPerfectShuffle(card deck[]){
       card newDeck[52];
       int count=0;
       while(newDeck!=deck[] && count>0){
           newDeck = perfectSuffle(deck);
           count++;
       }
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote