Due tonight at 11:59pm Eastern Time in the US.
1. Write a program that sorts and evaluates bridge hands according to the rules outlined below.
2. For the purposes of this assignment, the ranks and the suits will be given as
A Ace S Spades
2 two H Hearts
3 three C Clubs
4 four D Diamonds
5 five
6 six
7 seven
8 eight
9 nine
T ten
J Jack
Q Queen
K King
3. The input will consist of zero or more lines of input, where each line represents a single bridge hand. Each line will contain a stream of 13 character pairs as shown in this example.
2C QD TC AD 6C 3D TD 3H 5H 7H AS JH KH
The input will be error free and there will always be 13 cards available in every input line. There will be no duplicate cards in any hand. Your program should process each line, in turn, producing the output described below for each hand until the end-of-file.
4. The output will be a display of the hand in a more “readable” format, followed by a numerical evaluation of the hand using the standard bridge values (given below). The hand should be displayed by rank with suit in the following fashion, with the evaluation point count following it:
Spades A
Hearts K J 7 5 3
Diamonds A Q 10 3
Clubs 10 6 2
---------
Points = 16
Notice the conversion of TC (ten of Clubs) into ‘‘Clubs 10’’.
5. The rules for evaluating bridge hands are:
Aces count as 4 points
Kings count as 3 points
Queens count as 2 points
Jacks count as 1 points
Voids (no cards in a suit) count as 3 points
Singletons (one card in a suit) count as 2 points
Doubletons (two cards in a suit) count as 1 points
Long suits (more than 5cards in a suit) count as 1 point for each card over 5
(a void means that you have a hand of cards, say, clubs, diamonds, spades, and no hearts --- a suit is missing. if you had one heart you would have a singleton, two hearts are a doubleton, etc.)
6. Your program should accept its input from stdin and print its output to stdout. A sample input is:
2C QD TC AD 6C 3D TD 3H 5H 7H AS JH KH
3D QC TS 9S 4H 6D 6H 8S 2S 4D 7H 6C 9C
6D 9C 2S 2D TS 4H TD 7S 4C 3C 8H 8D 6S
AS AD AH AC KS KH KD KC JC JH JD QH QC
7D TS 8S TC 2C 2H 7C 8C QS QD JS 9D 4C
You can test your program thoroughly using your own test data, as well.
7. This is not a difficult problem. (If you're a C++ pro and not a student, I would comment to my professor) Work on understanding the problem and coming up with a good design. Move slowly toward the implementation and coding.
8. This problem lends itself to object-oriented design using C-strings, multidimensional arrays, and classes. But remember that “object-oriented” is more than just a measure of how many classes and objects you can create and cram into your program.
My problem:
As simple as the problem might seem to be, I have never used strings or multidimensional arrays along with classes that converts a two character code into a card number and suit and keeps track of their points. I have set up the basic format of how the output should look, it should give you a good headstart on what the program should look like. Feel free to edit whatever bit of coding I made that obviously is messed up. If you can put in the sample input from Step 3 and get the output from Step 4, you've got it down. Thanks for the help in advance.
What I got so far:
//begin program
#include <iostream>
#include <string>
using namespace std;
//create Bridgehand class to hold types for card suits and numbers
//use a string-type for full suit names
class Bridgehand
{
public:
char Min(char);
};
//declare main
int main()
{
char cardNumber[13][4]={{'SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'ST', 'SJ', 'SQ', 'SK'},
{'HA', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'HT', 'HJ', 'HQ', 'HK'},
{'DA', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'DT', 'DJ', 'DQ', 'DK'},
{'CA', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'CT', 'CJ', 'CQ', 'CK'}};
string inputCards;
int i = 0, points = 0;
//accept user input for 13 cards
cout << "Enter your Bridge Hand.";
//store card input into an array
for (i = 0; i < 13; i++)
{
char card;
cin << inputCards;
cout << "\t"
}
//output the number of Spades in the hand; use for-loop until all are displayed
cout.put << "\nSpades\t\t ";
for (i = 0; i < Spades; i++)
{
cout.put << Spade.cardNumber[1][i];
}
//output the number of Hearts in the hand; use for-loop until all are displayed
cout.put << "\nHearts\t\t ";
for (i = 0; i < Hearts; i++)
{
cout.put << Heart.cardNumber[2][i] << "\t";
}
//output the number of Diamonds in the hand; use for-loop until all are displayed
cout << "\nDiamonds\t\t ";
for (i = 0; i < Diamonds; i++)
{
cout.put << Diamond.cardNumber[3][i] << "\t";
}
//output the number of Clubs in the hand; use for-loop until all are displayed
cout.put << "Clubs\t\t ";
for (i = 0; i < Clubs; i++)
{
cout.put << Club.cardNumber[4][i];
}
if ([i] == 1)
{
points = points+2;
}
else-if (SuitName[i] == 2)
{
points = points+1;
}
else(SuitName[i] == 0)
{
points = points+3;
}
//follow point-table and keep score of the hand
//output the amount of total points for the current Bridge hand
cout.put << "---------\n";
cout.put << "Points = " << points << endl;
system("pause");
return EXIT_SUCCESS;
}
//end main
//end program
MOD EDIT: When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 09 December 2010 - 03:47 PM

New Topic/Question
Reply




MultiQuote





|