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

How would write these functions? Write a function that accepts an array of cards

ID: 3565511 • Letter: H

Question

How would write these functions?

Write a function that accepts an array of cards and an integer (the size of the array) as arguments and prints each card in the array. Write a function that accepts an array of cards and an integer (the size of the array) as arguments and randomizes the array. The easiest way to randomize an array is probably to pick two random locations in the array and swap their contents. If you do this repeatedly the array will end up randimized. Note that to swap two elements of an array you need to copy on element to a temporary object, copy the second object to where the first one was, and then copy the temporary object to where the second object was in the array.

Explanation / Answer

1) void print(card l[], int n){

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

         cout << l[i] << endl;

    }

}

2) void swap(card l[],int n){

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

        int j = random_integer(0,n);
        int k = random_integer(0,n);
       card t = l[j];
       l[j] = l[k];

      l[k] = t;

}

}

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