SOS . a problem in a program I wrote [spades] [amp]

admin / May 24th, 2011/ Posted in Software / No Comments »

Q: Hi, I have to write a program for a player to have bridge.

I:
1. receives 13 cards, and she comes in a linked list
2. print them in the order Ive them
3. organize them in a sort order: 977,503-u003e reorder the seried: clubs, diamonds-u003e u003e u003e heart-
u003e each series should b sorted also
4. out

The print the main components of the program are: Main hand.

from u0026 main I call: 977 503 * read – get the details cards
letter of the player * – * Print the lists out
hand – who are interested to organize the cards into a sort order

from hand I call: 977 503 * copy – which copies each card to the appropriate series
* type – all sorts every series
* merge – all series combined into one list

I did it, but have a problem with The .

enclosed the program.

plsssss, help me! :-(


Re:guys, plsss.

someone? :(


Re:Originally posted by: guy
you don't need to split it into four lists or do four sorts. You can just use one list and one sort.
How can I do that?

Re:Originally posted by: guy
'read' gets the all 13 cards, in the order the user enters it – it keeps it in the 'list'.
Than I split it to maximum 4 groups: c, d, h and s (it can be also 1 group, if all the cards the player got belong to one series), I sort each of the groups, and than merge the series to 1 list, according to the order: c-> d-> h-> s.
That's what I meant to do, any way…

Then you just select the cards, drop them in the list, print out the list, sort the list like an array of integers, and print out the list again
amm.. that're the requirements in my HW..

You completely missed my point. I'm saying you don't need to split it into four lists or do four sorts. You can just use one list and one sort.


Re:Originally posted by: guy
by the way, your parameter to read has a datatype of card*&;. that's kind of weird. if you're passing in a pointer into your function, you don't need to pass that pointer as a reference. just pass the pointer in by value as card*.
Ary u sure? Because I learnt that when I move a pointer of a list, for ex., and I want to change the parameter it points to – I have to get it as *&;…

I think I understood what u wrote afterwards.. I'm not sure.
I tried to correct my program according to it, and initialized the list in 'main'.
Now the ptoblem is in another place…
Now I get something printed (in that step:cout<<"The cards, befor organizing:\n";, in main), but it doesn't do it well (I entered 'c' from 1 to 13, and got: "c 13");
The program stucked just after that step..
In another check, the problem is where it was before…

:o :(


Re:by the way, your parameter to read has a datatype of card*&;. that's kind of weird. if you're passing in a pointer into your function, you don't need to pass that pointer as a reference. just pass the pointer in by value as card*.

the general protection fault refers to the fact that you declared card* list in main(), never created a new card through something like "list = new card()", and ultimately try to access a member of this card* variable that points to invalid memory. allocate a new card and assign it to list first.


Re:'read' gets the all 13 cards, in the order the user enters it – it keeps it in the 'list'.
Than I split it to maximum 4 groups: c, d, h and s (it can be also 1 group, if all the cards the player got belong to one series), I sort each of the groups, and than merge the series to 1 list, according to the order: c-> d-> h-> s.
That's what I meant to do, any way…

Then you just select the cards, drop them in the list, print out the list, sort the list like an array of integers, and print out the list again
amm.. that're the requirements in my HW..


Re:You don't need so many lists to do this.

number your cards 1-52. card 1-13 are 2-A of clubs, 14-26 are 2-A of diamonds, 27-39 are 2-A of hearts, 40-52 are 2-A of .

Then you just select the cards, drop them in the list, print out the list, sort the list like an array of integers, and print out the list again.


Re:So read() simply tacks a new card on the end? I'm not down with all the c++ but you're algorithm looks just a little bit odd. First you create a new card and enter it's suit and number. Then you abandon that card by assigning list to c. Then you assign c to list (which will have no effect). Then you tack on a new card. When you repeat you go to work on the same card again (I don't see any c = c->next). Then at the end you cut the list off. So you've effectively lost a reference to NUM_CARD-1 cards.

I could be reading this all wrong, like I said, I've never done c++.

I'd suggest an algorithm for you but I don't understand the semantics of read(). Are you passing in a pointer to a card pointer and after the call that pointer should point to an entire list?


Re:someone?

:(


Re:I can compile it, but when I run I get the message:
Unhandled Exception General Protection Exception…

The bold line the program point to, as a guilty one, is that:

void read (card *&;list)
{
card *c=new card;

for(int i=1; i<=NUM_CARD; i++)
{
cin>>c->suit>>c->num;
c=list;
list=c;
list->next=new card;
}
c->next=NULL;
}


Re:And what, praytell, is the mysterious problem?

Related posts


Tags: ,

Leave a Reply

Name required

Mail (will not be published) required

Website