472,958 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Help with sorting hand of playing cards

Hi Guys,

I have all my code working except sort function .

I need to sort the cards in hand......and I am having hard time with that....

Any help would be really helpful ;)
Expand|Select|Wrap|Line Numbers
  1. class hand{
  2. private:
  3. string theSuits; // contains suits in order
  4. string theValues; // contains values in order
  5. int numcards;
  6. public:
  7. unsigned size;
  8. acard* handcards; // an array of cards
  12. hand();
  13. ~hand();
  14. void sortit( unsigned size);
  15. void show();
  16. void shuffle();
  17. };
  19. void hand::sortit(unsigned size) {
  20.    sort(handcards, handcards + size);
  21.    for ( int i=0; i < size; ++i){
  22.    cout << h.handcards[i].str<< " " ; }
  23.    cout << endl;
  25. }
  28. int main()
  29. {
  30. int cardnum(0);
  31. string h[5];
  32. srand(time(0));
  34. deck mydeck;
  35. mydeck.show();
  36. mydeck.shuffle();
  37. mydeck.show();
  38. hand myhand1;
  39. hand myhand2;
  40. hand myhand3;
  41. hand myhand4;
  42. mydeck.hands(myhand1, 6);
  43. //myhand1.sortit(6);
  44. mydeck.hands(myhand2, 6);
  45. mydeck.hands(myhand3, 6);
  46. mydeck.hands(myhand4, 6);
  49. system("pause");
  50. return 0;
  51. }
Jan 30 '08 #1
2 4823
464 Expert 256MB
Your trying to use a sort function from the algorithm header on an array of objects. If I'm guessing the sort algorithm doesn't know how to handle the objects that are in the array. Look up c++ sorting techniques (Bubble Sort, Selection Sort, Insertion Sort, ect.) on google and try using one of them on your array in a sort function (your own function).
Jan 30 '08 #2
9,208 Expert Mod 8TB
Where is your card???

Isn't a hand a container of cards??

Doesn't a card contain a suit and a value ??

So why isn't your hand a vector<Card> ???

There is a sort with the vector that you can use. You will need a) to write an operator< for your Card class or b) write a function that takes two Card arguments by reference and returns true if the first argument is less than the second argument.
Jan 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Johnny Snead | last post by:
Hey guys, Need help with this random sort algorithm private void cmdQuestion_Click(object sender, System.EventArgs e) { Random rnd = new Random(); //initialize rnd to new random object...
by: dembla | last post by:
Hey Frnds can anyone help me in this i need a program in 'c' PROGRAM to print NxN Matrix 9 1 8 1 2 3 2 7 3 as 4 5 6 6 4 5 7 8 9 in sorted form
by: Sam | last post by:
Hi, I have one table like : MyTable {field1, field2, startdate, enddate} I want to have the count of field1 between startdate and enddate, and the count of field2 where field2 = 1 between...
by: Umesh | last post by:
I don't understand it. Help me by writing a program while i try myself to sort an array of numbers. Thanks.
by: cherriecheng88 | last post by:
hi...did anyone know how to do this assignment? cuz, i have run out of time really need ppls help me out thank you if you know it... Blackjack For the third assignment you will write a program...
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
by: l1nuxxx | last post by:
I have a file well call file.pl. It's a card sorting program. I need to create a lib fuction with part of the original file that shuffles the deck of cards. After it shuffles the first deck and deals...
by: mProgramz | last post by:
//Specification: This program plays a version of //the card game of 21. //A human player is pitted against the computer. //The player who is the closest to 21 without //going over wins the hand. ...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.