The program imitates a gambling card game. The program shows you three cards, then the program interchange them, and if you can guess correctly where a particular card is, you win.

Here is some sample interaction with the program:
Card 1 is the 7 of clubs
Card 2 is the jack of hearts
Card 3 is the ace of spades
I’m swapping card 1 and card 3
I’m swapping card 2 and card 3
I’m swapping card 1 and card 2
Now, where (1, 2, or 3) is the ace of spades?
If the user insert 3
The program will print” sorry, you lose.”


Solution hints:
Implement the previous program using structure, this structure represent the data of Card (number and suit), so the structure uses separate members to hold of the number of the card and suit. The number runs from 2 to 14, where 11, 12, 13 and 14 represent the jack, queen, king, and ace, respectively. The suit runs from 0 to 3, where these four numbers represent clubs, diamonds, hearts, and spades.

Recommended Answers

All 6 Replies

I take it this is your homework? Well perhaps if you show some effort, then we will consider helping...If we were to just give you the answer, what good would you achieve from that?

i already started it but cant do it all alone,, and it is a project worth 10%.. and it is so important.. plz if u can help me i will be very thankful

i already started it

Prove it. Just saying you started it does not mean we're going to write it for you.

plz if u can help me i will be very thankful

We will help. But you have to explain what you need help with. Details, specific questions, those we can answer. And code.

Read the Member Rules...

#include <iostream>
class Card
  {
    int number;
    string suit;

      public:
        Card () {};
        ~Card () {};
        Card(int n,string s) , number(n), suit(s) {};
        Card& operator= (const Card d) 
		{          
            number=d.number;
            suit=d.suit;
          }
        friend bool operator== (const Card c,const Card d) 
		{
            return (c.number==d.number) && (c.suit==d.suit);
          }
        friend ostream& operator << (ostream& o,Card d) {return o<<d.number << endl << d.suit;}            
  };

void SwapCards(Card&,Card&);

void main ()
  {
    Card one(4,"spades");
    Card two(6,"clubs");    
    SwapCards(one,two);
  }

void SwapCards(Card& a,Card& b)
  {
    Card chair;
    chair=a;
    a=b;
    b=chair;
  }

this was a start but lots of errors, and cant complete it.. plzzzzz any help

friend bool operator== (const Card c,const Card d) 
{
return (c.number==d.number) && (c.suit==d.suit);
}
friend ostream& operator << (ostream& o,Card d) {return o<<d.number << endl << d.suit;}

What's going on right here?

could you please post the errors you are getting?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.