hey guys ! i have a problem relating to linked lists ..
Make a class called Card. Each card is represented by a suit and a rank. You can keep both as strings. Implement getters and setters for the Card class as well as a print function. A 7 of spades should be printed as 7S or 7♠.
Create a class Deck which contains 52 cards. Implement a print function which prints outs all cards in the deck. Also implement a shuffle function. You can use any algorithm to shuffle a deck. The simplest one is dividing the deck into two parts of random size and then placing the lower part on top of the upper part. However, you must implement the deck as a linked list of cards. Each node in this list should have a pointer to a unique Card object and a pointer to the next node. This means that there should never be more (or less) than 52 Card objects in the whole program at any time.

I have printed all the cards and now i want to shuffle them :

My Code is :
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197`` ``````#include #include #include #include #include "Card.h" using namespace std; class Deck { private: Card c[52]; public : Deck () { int index = 0 ; for (int i = 2 ; i<=9 ; i++ ) { c[index].Setsuit("H"); string rank; ostringstream convert; convert << i; rank = convert.str(); c[index].SetRank(rank); index++; } c[index].Setsuit("H"); c[index].SetRank("A"); index++ ; c[index].Setsuit("H"); c[index].SetRank("k"); index++ ; c[index].Setsuit("H"); c[index].SetRank("Q"); index++ ; c[index].Setsuit("H"); c[index].SetRank("J"); index++ ; c[index].Setsuit("H"); c[index].SetRank("10"); for (int i = 2 ; i<=9 ; i++ ) { c[index].Setsuit("C"); string rank; ostringstream convert; convert << i; rank = convert.str(); c[index].SetRank(rank); index++; } c[index].Setsuit("C"); c[index].SetRank("A"); index++ ; c[index].Setsuit("C"); c[index].SetRank("k"); index++ ; c[index].Setsuit("C"); c[index].SetRank("Q"); index++ ; c[index].Setsuit("C"); c[index].SetRank("J"); index++ ; c[index].Setsuit("C"); c[index].SetRank("10"); index++ ; for (int i = 2 ; i<=9 ; i++ ) { c[index].Setsuit("S"); string rank; ostringstream convert; convert << i; rank = convert.str(); c[index].SetRank(rank); index++; } c[index].Setsuit("S"); c[index].SetRank("A"); index++ ; c[index].Setsuit("S"); c[index].SetRank("k"); index++ ; c[index].Setsuit("S"); c[index].SetRank("Q"); index++ ; c[index].Setsuit("S"); c[index].SetRank("J"); index++ ; c[index].Setsuit("S"); c[index].SetRank("10"); index++ ; for (int i = 2 ; i<=9 ; i++ ) { c[index].Setsuit("D"); string rank; ostringstream convert; convert << i; rank = convert.str(); c[index].SetRank(rank); index++; } c[index].Setsuit("D"); c[index].SetRank("A"); index++ ; c[index].Setsuit("D"); c[index].SetRank("k"); index++ ; c[index].Setsuit("D"); c[index].SetRank("Q"); index++ ; c[index].Setsuit("D"); c[index].SetRank("J"); index++ ; c[index].Setsuit("D"); c[index].SetRank("10"); index++ ; } void Print_cards_in_a_Deck() { for (int i = 0 ; i<52 ; i++ ) { c[i].Print_Cards(); } } }; #ifndef CARD_H #define CARD_H #include #include using namespace std; class Card { private : string suit ; string rank ; public : void Setsuit(string Suit) { suit = Suit ; } string GetSuit () { return suit ; } void SetRank( string Rank) { rank = Rank ; } string GetRank () { return rank ; } void Print_Cards() { cout << rank << setw(1) < #include "Card.h" #include "Deck.h" using namespace std; void main () { Card c; Deck d ; c.SetRank("A"); c.Setsuit("Hearts"); d.Print_cards_in_a_Deck(); system("pause"); } #include #include "Card.h" #include"Deck.h" using namespace std; class Node { public : Card c ; Node *next ; }``````

Now the problem is that i can not access the functions of the class card as i have made an object of the class card in the class Node . please help me with this ..
Topic archived. No new replies allowed.