Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a main to test my bridge game. This program evaluates the strength of han

ID: 3636716 • Letter: I

Question

I need a main to test my bridge game. This program evaluates the strength of hand.

I can't wrap my head around what I need to write for a main. If I do not have a main, it gives me a link error.

***********
.cpp *
***********

// Author: GL
// Date: 1.5.2012
// Lab1 - Evaluate the strength of a bridge hand

#include "bridgehand.h"

// need a main to test my program
int main ()
{

}

BridgeHand::BridgeHand()
{
for (int x = 0; x < MAX_LENGTH; x++)
{
clubs[x] = false;
diamonds[x] = false;
hearts[x] = false;
spades[x] = false;
}
points = 0;
}

void BridgeHand::readCards()
{
cout << "Please enter in " << MAX_LENGTH << " bridge

cards ";
string temp;
for (int x = 0; x < MAX_LENGTH; x ++)
{
cin >> temp;
setCard(temp);
}
calcPoints();
}

void BridgeHand::setCard(string card)
{
int rank = getRank(card);
char suit = ' ';
string temp = card.substr(1,1);
if (temp == "C")
suit = 'C';
else if (temp == "D")
suit = 'D';
else if (temp == "H")
suit = 'H';
else if (temp == "S")
suit = 'S';
if (validCard(rank, suit))
{
switch(suit)
{ case 'C': clubs[rank] = true; break;
case 'D': diamonds[rank] = true; break;
case 'H': hearts[rank] = true; break;
case 'S': spades[rank] = true; break;
}
}
}

void BridgeHand::calcPoints()
{
points = points + calcSuit( clubs );
points = points + calcSuit( diamonds );
points = points + calcSuit( hearts );
points = points + calcSuit( spades );
}

int BridgeHand::calcSuit( bool arrayOfCards [] )
{
int tempCounter = 0;
int tempPoints = 0;
for( int i = 0 ; i < MAX_LENGTH ; i++ )
{
if( arrayOfCards[i] )
{
tempCounter = tempCounter + 1;
if( i == 0 )
{
tempPoints = tempPoints + ACE_VAL;
}
if( i == 1 )
{
tempPoints = tempPoints + KING_VAL;
}
if( i == 2 )
{
tempPoints = tempPoints + QUEEN_VAL;
}
if( i == 3 )
{
tempPoints = tempPoints + JACK_VAL;
}
}// end if
} // end for loop
if( tempCounter == 0 )
{
tempPoints = tempPoints + VOID_VAL;
}
else if( tempCounter == 1 )
{
tempPoints = tempPoints + SINGLETON_VAL;
}
else if( tempCounter == 2 )
{
tempPoints = tempPoints + DOUBLETON_VAL;
}
return tempPoints;
}

bool BridgeHand::validCard( int, char )
{
return true;
}

int BridgeHand::getRank( string a )
{
string temp1;
int temp2;
string temp3;
temp1 = a.substr(0,1);
if ( temp1 == "A" )
{
temp3 = "0";
}
if( temp1 == "K" )
{
temp3 = "1";
}
if( temp1 == "Q" )
{
temp3 = "2";
}
if( temp1 == "J" )
{
temp3 = "3";
}
if ( temp1 == "T" )
{
temp3 = "4";
}
if( temp1 == "9" )
{
temp3 = "5";
}
if( temp1 == "8" )
{
temp3 = "6";
}
if( temp1 == "7" )
{
temp3 = "7";
}
if( temp1 == "6" )
{
temp3 = "8";
}
if( temp1 == "5" )
{
temp3 = "9";
}
if( temp1 == "4" )
{
temp3 = "10";
}
if( temp1 == "3" )
{
temp3 = "11";
}
if( temp1 == "2" )
{
temp3 = "12";
}
temp2 = atoi(temp3.c_str());
return temp2;
}

void BridgeHand::print()
{
cout << "CLUBS: ";
printSuit( clubs );
cout << endl << "DIAMONDS: ";
printSuit( diamonds );
cout << endl << "HEARTS: ";
printSuit( hearts );
cout << endl << "SPADES: ";
printSuit( spades );
cout << endl << "TOTAL POINTS: " << points <<

endl;
cin.get();
}

void BridgeHand::printSuit( bool arrayOfCards [] )
{
for( int j = 0 ; j < MAX_LENGTH ; j++ )
{
if( arrayOfCards[j] )
{
if( j == 0 )
{
cout << "A" << " ";
}
if( j == 1 )
{
cout << "K" << " ";
}
if( j == 2 )
{
cout << "Q" << " ";
}
if( j == 3 )
{
cout << "J" << " ";
}
if( j == 4 )
{
cout << "10" << " ";
}
if( j == 5 )
{
cout << "9" << " ";
}
if( j == 6 )
{
cout << "8" << " ";
}
if( j == 7 )
{
cout << "7" << " ";
}
if( j == 8 )
{
cout << "6" << " ";
}
if( j == 9 )
{
cout << "5" << " ";
}
if( j == 10 )
{
cout << "4" << " ";
}
if( j == 11 )
{
cout << "3" << " ";
}
if( j == 12 )
{
cout << "2";
}
} // end if
} // end loop
cin.get();
}

***********
header .h
***********

#ifndef BRIDGEHAND
#define BRIDGEHAND

#include <iostream>
#include <string>

using namespace std;

const int MAX_LENGTH = 13;
const int ACE_VAL = 4;
const int KING_VAL = 3;
const int QUEEN_VAL = 2;
const int JACK_VAL = 1;
const int VOID_VAL = 3;
const int SINGLETON_VAL = 2;
const int DOUBLETON_VAL = 1;

const int ACE = 0;
const int KING = 1;
const int QUEEN = 2;
const int JACK = 3;
const int TEN = 4;
const int NINE = 5;
const int EIGHT = 6;
const int SEVEN = 7;
const int SIX = 8;
const int FIVE = 9;
const int FOUR = 10;
const int THREE = 11;
const int TWO = 12;

class BridgeHand
{
public:
BridgeHand();
void readCards();
void setCard(string);
void calcPoints();
int calcSuit(bool []);
bool validCard(int, char);
int getRank(string);
void print();
void printSuit(bool []);

private:
bool clubs[MAX_LENGTH];
bool diamonds[MAX_LENGTH];
bool hearts[MAX_LENGTH];
bool spades[MAX_LENGTH];
int points;
};

#endif

*****************************
The main is all I need. I don't know what to put in the main in order to test it.

Thank You

Explanation / Answer

please rate - thanks

don't know bridge, but this is what you need

int main ()
{BridgeHand b;
b.readCards();
b.print();
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote