I'm creating a program to Deal, Sort, Display and determine cards for a poker game.
A word for word of my program is here...
Write a program that will operate on a deck of 52 cards. Your program will:
1. Deal them into four random hands of 5 cards each
a. The four hands need to be kept in an array for later use.
2. Sort each hand so that it shows the cards in sequence from two as the lowest to ace as the highest.
3. Display the cards in each hand using the card face (2, 10, King, etc.) and the suit (Spades, Hearts, etc.)
4. Display what you determined the hand to be.
5. Each time the program is run, a different sets of hands is to be dealt.
I think I understand number four, but I don't understand how to deal/shuffle the deck. Nor do I understand structs.
Here's a skeleton of what I have so far.
#include <iostream>
#include <stdlib.h>
#include <cctype>
#include <memory.h>
#include "logic.h"
using namespace std;
// & means location
// * value of location
struct Cards {
enum Value {Two = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace};
Value V;
int Suite;
enum Suite {Hearts, Diamonds, Clubs, Spades};
};
struct Hand {
Cards [5];
};
struct Deck {
Cards [52];
};
char * personsName [20]; //this means location with *
int numNames = 0;
char * Name;
char * search;
bool Continue;
int main ()
{
do {
for(int x = 0; x < 20; x++){
cout << "Enter a name, type END to stop: ";
Name = readString ();
if(strcmp (Name, "END") != 0){
personsName [x] = Name;
numNames++;
}
else{
Continue = (strcmp (Name, "END") != 0);
break;
}
}
cout << "Pre-sorted Names" << endl;
printNames(personsName,numNames);
bubbleSort(personsName,numNames);
cout << "Post-sorted Names" << endl;
printNames(personsName,numNames);
cout << "What would you like to find?" << endl;
search = readString();
cout << "The name is at index " << binarySearch(personsName,search,numNames) << endl;
} while (Continue);
delete [] * personsName;
return 0;
}
Now as you can see, this is an old program that I'm recycling for use.
On a side note, how can I throw all my methods into another file and call them from there. Should I make a new .cpp file, put my search function in that and how would I declare that? As in, where would I declare the .h file, in main or in the .cpp - and where do I declare the .cpp?
Thank you for any advice or just tips on how to do this.
My problem is that I don't know how to even begin to start this/use with structs.
I have a sorting method, and a search method already set up.