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

Complete and full answer in order to give credit. Do not copy-paste a similar pr

ID: 3793510 • Letter: C

Question

Complete and full answer in order to give credit. Do not copy-paste a similar problem.Program is to be written in C (just plain C) Thank you.

Write algorithms and programs to simulate a deck of cards and deal hands of cards. Conventional deck of cards has 52 cards: 13 ranks and 4 suits. Your simulation should be able to create a deck of cards, display the original deck, shuffle the deck, display the shuffled deck, deal the specified number of cards to the specified number of players and display each of the hands of cards.

Output: Display the original deck, display the shuffled deck, and display each of the hands of cards. Decks, hands and cards should be clean, clear and appropriately labeled - do not simply list as a simple column or row of values.

Input: Accept input via the command-line arguments. Validate command-line input. Input will specify the # of cards/hand and the # of hands (players), in that order.

Explanation / Answer

// C Program to shuffle a given array

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

// A utility function to swap to integers

void swap (int *a, int *b)

{

    int temp = *a;

    *a = *b;

    *b = temp;

}

// A utility function to print an array

void printArray (int arr[], int n)

{

    for (int i = 0; i < n; i++)

        printf("%d ", arr[i]);

    printf(" ");

}

// A function to generate a random permutation of arr[]

void randomize ( int arr[], int n )

{

    // Use a different seed value so that we don't get same

    // result each time we run this program

    srand ( time(NULL) );

    // Start from the last element and swap one by one. We don't

    // need to run for the first element that's why i > 0

    for (int i = n-1; i > 0; i--)

    {

        // Pick a random index from 0 to i

        int j = rand() % (i+1);

        // Swap arr[i] with the element at random index

        swap(&arr[i], &arr[j]);

    }

}

// Driver program to test above function.

int main()

{

    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};

    int n = sizeof(arr)/ sizeof(arr[0]);

    randomize (arr, n);

    printArray(arr, n);

    return 0;

}

// C Program to shuffle a given array

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

// A utility function to swap to integers

void swap (int *a, int *b)

{

    int temp = *a;

    *a = *b;

    *b = temp;

}

// A utility function to print an array

void printArray (int arr[], int n)

{

    for (int i = 0; i < n; i++)

        printf("%d ", arr[i]);

    printf(" ");

}

// A function to generate a random permutation of arr[]

void randomize ( int arr[], int n )

{

    // Use a different seed value so that we don't get same

    // result each time we run this program

    srand ( time(NULL) );

    // Start from the last element and swap one by one. We don't

    // need to run for the first element that's why i > 0

    for (int i = n-1; i > 0; i--)

    {

        // Pick a random index from 0 to i

        int j = rand() % (i+1);

        // Swap arr[i] with the element at random index

        swap(&arr[i], &arr[j]);

    }

}

// Driver program to test above function.

int main()

{

    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};

    int n = sizeof(arr)/ sizeof(arr[0]);

    randomize (arr, n);

    printArray(arr, n);

    return 0;

}

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