I have a start to my program but I am struggling with several things. I need to write the setcard() logic to reveal cards in my output rather than error messages. I tried to cout << rankNames[rnk] but it did not work. I also need to think about logic for sorting and shuffling. As always, thanks a lot.
CODE
//
#include <iostream>
#include <string>
using namespace std;
string rankNames[] = { "Error", "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
string suitNames[] = { "Error", "Diamonds", "Clubs", "Hearts", "Spades"};
class Card
{
private:
int rank;
int suit;
public:
// Constructor for a Card
Card(int rk, int st)
{
rank = rk;
suit = st;
}
// A default Constructor is needed to declare an array of Cards
Card()
{
rank = 0;
suit = 0;
}
// A string that represents the card
string toString()
{
return rankNames[rank] + " of " + suitNames[suit];
}
// Compare two cards. Write this.
bool greater(Card other) { }
// Write this
void setCard(int st, int rnk)
{
}
};
// Routine to write a set of cards
void printCards(Card deck[], int size)
{
for (int i = 0; i < size; i++)
cout << deck[i].toString() << endl;
}
// Write a routine to jumble an array of cards
void shuffle(Card deck[], int size) { }
// Write a routine to sort an array of cards
void sort(Card deck[], int size) { }
int main()
{
Card deck[52]; // Creates 52 cards using default constructor
// Create a regulation deck of cards
int pos = 0;
for (int suit = 1; suit <= 4; suit++)
for (int rank = 1; rank <= 13; rank++, pos++)
deck[pos].setCard(suit, rank);
// Has the deck been created?
cout << "\nInitial deck\n";
printCards(deck, 52);
shuffle(deck, 52);
cout << "\nShuffled deck\n";
printCards(deck, 52);
// Deal a hand
// This is not regulation dealing. Rather than getting the
// first 13 cards, I should get every fourth card.
Card hand[13];
for (pos = 0; pos < 13; pos++)
hand[pos] = deck[pos];
// Display my hand
cout << "\nMy hand as dealt\n";
printCards(hand, 13);
// Organize my hand
sort(hand, 13);
cout << "\nMy Hand after sorting\n";
printCards(hand, 13);
return 0;
}
*Mod Edit: added code tags: