Not logged in [
Login
-
Register
]
You Are Not Registered Or Not Logged In
Corsa Sport
»
Message Board
»
Off Day
»
Geek Day
»
Does anyone know Java????
» Post Reply
Post Reply
Who Can Post?
All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help
Andale Mono
Arial
Arial Black
Book Antiqua
Century Gothic
Comic Sans MS
Courier New
Georgia
Impact
Tahoma
Times New Roman
Trebuchet MS
Script MT Bold
Stencil
Verdana
Lucida Console
-2
-1
1
2
3
4
5
6
White
Black
Red
Yellow
Pink
Green
Orange
Purple
Blue
Beige
Brown
Teal
Navy
Maroon
LimeGreen
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
[quote][i]Originally posted by Mikorsa16v[/i] /* Program Saved As: cardObj.cpp Written By: Mike Date: 27/02/2003 Program Purpose: cards as objects */ #include
using namespace std; const int JACK = 11; const int QUEEN = 12; const int KING = 13; const int ACE = 14; enum Suit { clubs, diamonds, hearts, spades }; class Card{ private: int number; //cards have two attributes their suit and value Suit suit; public: Card() { } //empty constuctor which does nothing Card(int n, Suit s):number(n), suit(s) { } void display(); bool isEqual (Card); }; void Card::display() { if((number>=2) && (number<=10)) cout << number << " Of "; else switch(number) { case JACK: cout << "Jack Of "; break; case QUEEN: cout << "Queen Of "; break; case KING: cout << "King Of "; break; case ACE: cout << "Ace Of "; break; } switch(suit) { case clubs: cout << "Clubs \5"; break; case diamonds: cout << "Diamonds \4"; break; case hearts: cout << "Hearts \3"; break; case spades: cout << "Spades \6"; break; } } bool Card::isEqual(Card c2) { return ((number==c2.number)&&(suit==c2.suit)); } int main() { Card temp, chosen, prize; int position; Card card1(7, clubs); cout << "\nCard 1 Is The "; card1.display(); Card card2(JACK, hearts); cout << "\nCard 2 Is The "; card2.display(); Card card3(ACE, spades); cout << "\nCard 3 Is The "; card3.display(); prize=card3; cout << "\nI'm Swapping Card 1 and 3"; temp=card3; card3=card1; card1=temp; cout << "\nI'm Swapping Card 2 and 3"; temp=card3; card3=card2; card2=temp; cout << "\nI'm Swapping Card 1 and 2"; temp=card2; card2=card1; card1=temp; cout << "\nNow, Where (1,2 or 3) Is The "; prize.display(); cout << "? "; cin >> position; switch (position) { case 1: chosen=card1; break; case 2: chosen=card2; break; case 3: chosen=card3; break; } if(chosen.isEqual(prize)) cout << "**** You Win! ****"; else cout << "Sorry, You Lose!"; cout << "You Chose The: "; chosen.display(); cout << endl; return 0; } may be of some help, is quite simple you can see the class and how it works, hopefully [/quote]
Post Options:
Disable smileys?
Turn BBCode off?
Receive email notification of new replies?
This is a long topic, click
here
to review it.