question regarding classes

Hey everyone, I am having trouble with a program dealing with Poker hands. I used 2 separate Classes, Card and friend class Hand(containing 5 cards), with the aim of setting 5 card hand using the input from the user. I wrote the set() functions for Card no problem. However I cannot get the coding for set() for class Hand right no matter what I tried.

Anyway this is the relevant code I have done so far,

.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Card
{
  public:
    friend class Hand; 
    void set(int newSuit, int newFace);
  private:
    int suit; 
    int face;  
};

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


.cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Card::set(int newSuit, int newFace)
{
  suit = newSuit;
  face = newFace;
}

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

.main
1
2
3
4
5
6
7
8
9
10
11
12
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 newCard1, newCard2, newCard3, newCard4, newCard5;
  Hand newHand;
  
  newHand.set(newCard1, newCard2, newCard3, newCard4, newCard5);


Does the error come from the implementation of the void Hand::set function? Or is there something wrong with the way I am calling it in the main? Any hints or help would be greatly appreiciated!!
Last edited on
You don't initialize newCard1..5 before you use them in newHand.set().

a couple of unrelated suggestions:
1.you don't really have to move data around so much. for example your set function could look like this:
1
2
3
4
void Card::set()
{
  cin >> suit >> face;
}

2. protip: use arrays
Last edited on
can u please answer this?
print a list of integers from 1 to N that are both divisible by 2 and 3. after producing a list count the number of integers found.
thank you !
To start a new topic, you scroll down to the bottom of the page and click the button that says "New Topic".
i dont know already this kind of topic beacause my instructor is always absent

print a pyramid read a number and print a pyramid that has that size
example if number=5
output:



*
* *
* * *
* * * *
* * * * *

5 stars

i need it before octber 8 come it will help me a lot if you answer this thank you!
Topic archived. No new replies allowed.