-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.cpp
More file actions
46 lines (28 loc) · 1.03 KB
/
Card.cpp
File metadata and controls
46 lines (28 loc) · 1.03 KB
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
#include "Card.h"
#include <iostream>
#include <string>
using namespace std;
Card::Card() {
value = -1;
rank = -1;
}
Card::Card(int rank, int suit) { this->rank = rank; this->suit = suit; }
int Card::getSuit() { return suit; }
int Card::getRank() { return rank; }
void Card::setSuit(int suit) { this->suit = suit; }
void Card::setRank(int rank) { this->rank = rank; }
//negative means the current greater than the card passed in
int compareByRank(const Card& card) { return rank - card.rank; }
int Card::compareBySuit(const Card& card) { return suit - card.suit; }
string Card::getRankAsString() const {
string rankArray[] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine",
"Ten","Jack","Queen","King"};
return rankArray[rank];
}
string Card::getSuitAsString() const {
string suitArray[] = {"Hearts","Spades","Diamonds","Clubs"};
return suitArray[suit];
}
ostream& operator <<(ostream& obj, const Card& card) {
return obj << card.getRankAsString() << " of " << card.getSuitAsString() << endl;
}