rendered paste body//bridge.cpp
#include<iostream>
using namespace std;
const int hand=13;
const int deckSize=52;
string convertRank(int a){
string rank;
int c = a % 13;
switch(c) {
case 0:
rank = "A ";
break;
case 1:
rank = "2 ";
break;
case 2:
rank = "3 ";
break;
case 3:
rank = "4 ";
break;
case 4:
rank = "5 ";
break;
case 5:
rank = "6 ";
break;
case 6:
rank = "7 ";
break;
case 7:
rank = "8 ";
break;
case 8:
rank = "9 ";
break;
case 9:
rank = "10 ";
break;
case 10:
rank = "J ";
break;
case 11:
rank = "Q ";
break;
case 12:
rank = "K ";
break;
}
return rank;
}
int intoSuit(int a[ ]) {
string clubs, spades, hearts, diamonds;
spades = " ";
clubs = " ";
hearts = " ";
diamonds = " ";
for(int n=0;n<hand;n++){
if (a[n]<26) {
spades = spades + convertRank(a[n]);;
}
else if (a[n]>51) {
clubs = clubs + convertRank(a[n]);
}
else if ((a[n]>25) && (a[n]<39)) {
hearts = hearts + convertRank(a[n]);
}
else if ((a[n]>38) && (a[n]<52)) {
diamonds = diamonds + convertRank(a[n]);
}
}
cout << "\nSpades: " << spades << endl;
cout << "Hearts: " << hearts << endl;
cout << "Clubs: " << clubs << endl;
cout << "Diamonds: " << diamonds << endl;
}
int count(int a[ ]){
int total=0;
for(int u=0; u<hand; u++) {
if (a[u] % 13 == 0) {
total = total + 4;
}
else if (a[u] % 13 == 10) {
total = total + 1;
}
else if (a[u] % 13 == 11) {
total = total + 2;
}
else if (a[u] % 13 == 12) {
total = total + 3;
}
}
return total;
}
int main( ) {
int hand1[hand], hand2[hand], hand3[hand], hand4[hand];
int deck[deckSize] = { 13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64 };
//shuffle and deal
int q=0;
srand(time(NULL));
for(int l=0; l<deckSize; l++) {
int m= rand() % (deckSize-l);
int tmp=deck[l];
deck[l]=deck[l+m];
deck[l+m]=tmp;
}
for(int n=0;n<hand;n++){
hand1[n] = deck[n];
}
for(int n=hand;n<(hand * 2);n++){
hand2[q] = deck[n];
q++;
}
q=0;
for(int n=(hand * 2);n<(hand * 3);n++){
hand3[q] = deck[n];
q++;
}
q=0;
for(int n=(hand * 3);n<(hand * 4);n++){
hand4[q] = deck[n];
q++;
}
//output
cout << "Hand 1: " << endl;
intoSuit(hand1);
cout << "Hand 1 total is: " << count(hand1) << " points." << endl;
cout << "\nHand 2: " << endl;
intoSuit(hand2);
cout << "Hand 2 total is: " << count(hand2) << " points." << endl;
cout << "\nHand 3: " << endl;
intoSuit(hand3);
cout << "Hand 3 total is: " << count(hand3) << " points." << endl;
cout << "\nHand 4: " << endl;
intoSuit(hand4);
cout << "Hand 4 total is: " << count(hand4) << " points." << endl;
system("pause");
return 0;
}