Question
November 25, 2008 at 12:20 PM
chid54

Homework Help

by chid54 . Updated 17 years, 9 months ago

I have an assignment due in a week and I have no idea how to begin. If anybody has any ideas I would appreciate it. The assignment is below

Write a program that creates a deck of playing cards in the correct order (i.e. Ace through King, with suits ordered as Clubs, Diamonds, Hearts, Spades) using structs to represent the cards, then “shuffles” the deck of cards a user-defined number of times (without ever moving the actual cards themselves), deals a virtual hand to the user, and finally tells the user how many points their hand is worth when playing Bridge.

Your code should use structs to hold the fifty-two cards in the deck, such that each struct keeps track of the suit and face value of a card. It should then ask the user how many times it should shuffle the deck, and then should make use of a random number generator to “shuffle” the deck of cards that many times without actually moving the cards themselves around in the program.

After “shuffling” the deck, your program should deal a virtual hand of thirteen cards (i.e. select every fourth card, as if dealing to four people at a table) and then determine how many points the hand is worth.

Points scored by a hand are determined as follows:

Ace – 4 points
King – 3 points
Queen – 2 points
Jack – 1 point
No cards of a suit in a hand – 3 points
Only one card of a suit in a hand – 2 points
Only two cards of a suit in a hand – 1 point
So, for instance, if the cards you received in your hand were three Clubs, two Hearts, one Diamond, and seven Spades, and we weren’t considering the points received for the Aces, Jacks, Queens, and Kings, you would get two points for the lone Diamond, and one more point for only having a pair of Hearts. Had you instead received ten Clubs, two Hearts, one Diamond, and no Spades, you would get three points for the lack of Spades, two for the lone Diamond, and one more for the pair of Hearts. As for the face cards, as was mentioned, each Ace yields four points, each King yields three, and so on.

After determining the number of points, output the hand (you don’t need to say “4 of Clubs” or “Jack of Diamond”…”4C” and “11D” would be good enough) and the number of points to the user.

This discussion is locked

All Comments