0

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.

Edited by deadelgabar: n/a

2
Contributors
2
Replies
7
Views
7 Years
Discussion Span
Last Post by caut_baia
0

plz guys any help,, this is a project for me and i have the due date on thursday, i need any help plzz

-2
#include <iostream>

using namespace std;

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&);

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

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

Hope this will get you started..

Votes + Comments
Don't hand out code willy-nilly. You just gave away half the assignment. What does that teach? Nothing.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.