classes

okay, this is the header file i've been given that i can't change
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Card
{
  public:
    friend class Hand;     
    void set(int newSuit, int newFace); // set card suit and face
    void display();                     // display the card value in plain english, see examples for details
  private:
    int suit; // 0 is Clubs, 1 is Spades, 2 is Hearts, 3 is Diamonds
    int face; // 2 is 2, ... 10 is 10, 11 is Jack, 12 is Queen, 13 is King, 14 is Ace
};

class Hand
{
  public:  
  void set(Card newCard1, Card newCard2, Card newCard3, Card newCard4, Card newCard5); // set cards in hand
  void displayHand();     // display the cards in the hand, see examples for details 
  void quickAnalysis();   // analyse the hand and determine if it contains 
                          // a four of a kind, flush, or full house  
                          // update the string member combination accordingly
  void displayCombination(); // use member combination to display the name of the combination in case it is 
                             // a four of a kind, flush, or full house 
                             // otherwise output a message that hand is not recognised
                             // see examples for details
  private:
    Card card1;  // first card in hand   
    Card card2;   
    Card card3;           
    Card card4;   
    Card card5;  // last card in hand   
    string combination; // hold information regarding the combination of the hand
                        // the value of this variable is set by quickAnalysis() 
};




and this is what i have done, it is going to be run on an automarker so it will only be testing relevant numbers so that isn't the problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
int main()
{
  int suit1, suit2, suit3, suit4, suit5;
  int face1, face2, face3, face4, face5;  

  cout << "Enter a hand (10 integers): " << flush;
  cin >> suit1 >> face1 >> suit2 >> face2 >> suit3 >> face3 >> suit4 >> face4 >> suit5 >> face5;
 Card card1, card2, card3, card4, card5;
  
  card1.set(suit1,face1);
  card2.set(suit2,face2);
  card3.set(suit3,face3);
  card4.set(suit4,face4);
  card5.set(suit5,face5);
    
  card1.display();
  card2.display();
  card3.display();
  card4.display();
  card5.display();
  
  Hand hand;
  hand.set(card1, card2, card3, card4, card5);

  hand.displayHand();
  
system("pause");
  return 0;
}

void Card::set(int newSuit, int newFace)
{
  suit = newSuit;
  face = newFace;
}


void Card::display()
{
  string faceStr;
  switch (face)
  {
    case  2: faceStr = "2";
             break;
    case  3: faceStr = "3";
             break;
    case  4: faceStr = "4";
             break;
    case  5: faceStr = "5";
             break;
    case  6: faceStr = "6";
             break;
    case  7: faceStr = "7";
             break;                                                                           
    case  8: faceStr = "8";
             break;
    case  9: faceStr = "9";
             break;
    case 10: faceStr = "10";
             break;
    case 11: faceStr = "Jack";
             break;  
    case 12: faceStr = "Queen";
             break;                
    case 13: faceStr = "King";
             break;  
    case 14: faceStr = "Ace";
             break;                  
  }
  string suitStr = "";
  switch (suit)
  {
    case 0: suitStr = "Clubs";            
            break;
    case 1: suitStr = "Spades";            
            break;
    case 2: suitStr = "Hearts";            
            break;                
    case 3: suitStr = "Diamonds";            
            break;
  }                   
  cout << faceStr << " of " << suitStr << endl;   
}

void Hand::set(Card newCard1, Card newCard2, Card newCard3, Card newCard4, Card newCard5)
{
 card1 = newCard1;
 card2 = newCard2;
 card3 = newCard3;
 card4 = newCard4;
 card5 = newCard5;
}

void Hand::displayHand()     
{
  cout << "*********************" << endl;      
  card1.display();
  card2.display();
  card3.display();
  card4.display();
  card5.display();
  cout << "*********************" << endl;
  
}



i just can't seem to get
1
2
3
4
5
6
7
cout << "*********************" << endl;
card1.display();
card2.display();
card3.display();
card4.display();
card5.display();
cout << "*********************" << endl;

to come up after the person inputs the numbers, i need to be able to do this then after i think i can do the rest of the assignment, thanks in advance
I can't see anything wrong with the display() function itself.

Add some print statements through out your code, so you can see what is happening from beginning to end.

EDIT: instead of getting user to enter the cards, I'd create an array which would be your 'deck'. This could be an array of card structs or classes, struct is better option. Then I'd use a shuffle method, (shuffle the array). Then I'd grab cards from the top.
Last edited on
its for an assignment and it goes through an automarker so the numbers being entered don't matter, there are things i have to do after this i just can't get the displayHeading() function to work and if i cant get that then i cant move on

i want this to happen in my program

Enter a hand (10 integers): 0 5 1 5 3 8 2 5 3 5
*********************
5 of Clubs
5 of Spades
8 of Diamonds
5 of Hearts
5 of Diamonds
*********************
Press any key to continue . . .

Topic archived. No new replies allowed.