首页 > > 详细

C辅导:Bonus Lab (Chat Program using Message Queues)辅导php、JSP讲解留学生

Introduction
c,,4,,。
sample,,
Requirement
1
ECE175 Computer Programming for Engineering Applications
Homework Assignment 8
Due Date: Tuesday April 12, 2016 11:59 PM, via D2L
Conventions: Name your C programs as hwxpy.c
where x corresponds to the homework number and y correspondto the problem number.
Write comments to your programs. Programs with no comments will receive PARTIAL
credit. For each program that you turn in, at least the following information should be
included
Author:
Date created:
- Brief (two lines) description of the program:
Submission Instructions: Submit your .c files via D2L Dropbox.
Problem 1 (60 pts): Write a C program to
1) Create a full deck of 52 cards that are in order. In other words, for each of the four
suits, the cards should be in order from Ace (1) through King (13).
each card is consisted of
suit [clubs (♣),spades (♠),hearts (♥), or diamonds (♦))
a face (1(Ace) – 10, Jacks (J), Queens (Q), and Kings (K))
To simulate the deck, and each of the players’ hands, you MUST use a dynamic list of
cards with the following type
typedef struct card_s {
char suit;
int face;
struct card_s *listp;
} card;
At the HW demo time, you will be asked to print the deck that you create.
2) shuffle the deck (52 cards), using the following algorithm:
(a) For each card in the deck, get a random number in the range of 0 to 50 to be
used as the index of the element to swap that card with, i.e.
if deck[0] holds the Jack of clubs (J ♣) and the random number generated was
24, and deck[24] holds the 9 of diamonds (9♦), then
after the first swap, deck[0] would hold the 9 of diamonds (9♦) and
24] would hold the Jack of clubs (J ♣). You would then proceed to
deck[1], find a random index of a card to swap with, and swap those cards,
etc.
(b) Repeat step (a) at least 100 times.
Note: You must seed the random number generator with a call to time() with
srand(). [see sec 2.22 Random numbers in your Zyante book]
At the HW demo time, you will be asked to print the deck after the shuffle is done.
3) deal the cards (after shuffling the deck) by giving one card to the user/player,
followed by one card to the computer/dealer, followed by one card to the
2
user/player, etc. until each player get 8 cards. There are only 2 players
(computer/dealer and one user/player).
The player’s hand is represented as a dynamic list of cards. The list is populated
with the cards drawn by the player.
The dealer’s hand is represented as a dynamic list of cards. The list is populated
with the cards drawn by the dealer.
Note: the card(s) added to each of the player/dealer’s hand (drawn from the deck)
must be added to that player/dealer’s linked list correctly and MUST be removed
from the deck.
At the HW demo time, you will be asked to print both computer’s hand and user’s hand
Note: your program can do one of the followings (pick one):
♣, ♠, ♥, ♦
OR display club, spade, heart, diamond
Sample code execution 1:
Note: your program will NOT
get exactly these shuffle
cards since rand() is used!
Note: you can see that the shuffled
cards are distributed to each hand in
an alternate fashion and starts with a
player/user hand.
- 1st card from the shuffled one is 4 of
club which is assigned to player’s
hand
- 2nd card from the shuffled one is 2
of spade which is assigned to
computer’s hand
- 3rd card from the shuffled one is 10
of spade which is assigned to player’s
hand
- etc.
3
Sample code execution 2:
Note: your program will NOT get
exactly these shuffle cards since
rand() is used!
Note: you can see that the shuffled cards are
distributed to each hand in an alternate fashion
and starts with a player/user hand.
- 1st card from the shuffled one is A ♦ which is
assigned to player’s hand
- 2nd card from the shuffled one is 6 ♦ which is
assigned to computer’s hand
- 3rd card from the shuffled one is 5♣ which is
assigned to player’s hand
- etc.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!