473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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
  9.  
  10.  
  11.  
  12. hand();
  13. ~hand();
  14. void sortit( unsigned size);
  15. void show();
  16. void shuffle();
  17. };
  18.  
  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;
  24.  
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. int cardnum(0);
  31. string h[5];
  32. srand(time(0));
  33.  
  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);
  47.  
  48.  
  49. system("pause");
  50. return 0;
  51. }
Jan 30 '08 #1
2 4866
Studlyami
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
weaknessforcats
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

10
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...
33
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
5
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...
17
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.
5
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...
8
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...
8
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...
3
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. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.