The deadline for this lab is Wednesday 12 April 2006, 17:45:59 hours. Strictly no submissions will be accepted after the deadline.
Suit | Abbreviation |
---|---|
There are 13 suits with their abbreviations as shown, and they are ranked from lowest (2) to highest (Ace):
Rank | Abbreviation |
---|---|
Examine the following sample output to see how the cards are sorted:
Player 1: C3 C8 C9 CK D6 DQ DK HQ S2 S3 S9 SJ SA Player 2: C7 CJ CA D5 D7 H3 H7 H8 HJ HK S5 S7 SK Player 3: C2 C4 C5 CT CQ D4 DJ H2 HT S4 S6 ST SQ Player 4: C6 D2 D3 D8 D9 DT DA H4 H5 H6 H9 HA S8Here is another sample output:
Player 1: C5 C6 D5 DJ DQ H2 H3 H5 HK HA S5 SQ SA Player 2: C2 C4 C8 D6 D7 D9 DK H4 H7 H8 HT S2 S9 Player 3: C9 CJ CQ CK CA D2 D4 D8 DT H6 H9 HJ HQ Player 4: C3 C7 CT D3 DA S3 S4 S6 S7 S8 ST SJ SK
You are reminded to follow the sample output exactly; else marks will be deducted.
Do not use any structures or File I/O in your program, else no credit will be given.
#include <stdio.h> #include <stdlib.h> #include <time.h> /* Declare function prototypes. */ void shuffle(int a[], int n); int rand_int(int a, int b); int main(void) { /* Declare and initialize variables. */ /* ... */ /* Sets the seed to a random value based on the system time. */ /* This is done only once, at the beginning of the program. */ srand((unsigned int)time(NULL)); /* Your code goes here... */ return 0; } /*---------------------------------------------------*/ /* This function shuffles (mixes up) all the */ /* integers in the array. */ void shuffle(int a[], int n) { int i, swapwith, temp; for (i = 0; i < n - 1; i++) { swapwith = rand_int(i, n - 1); if (swapwith > i) { temp = a[i]; a[i] = a[swapwith]; a[swapwith] = temp; } } } /*---------------------------------------------------*/ /* This function generates a random integer */ /* between specified limits a and b (a<b). */ int rand_int(int a, int b) { return rand()%(b-a+1) + a; } /*---------------------------------------------------*/
You are reminded to follow the sample output exactly; else marks will be deducted.
Remember to submit your program using the submit bridge.c command, and check your submission using the check command.
All the best!