-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.h
69 lines (48 loc) · 1.59 KB
/
card.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by Naris on 11/1/2018.
//
//File Name: card.h
//
//Written by Owen Astrachan and Roger Priebe
// This class represents a playing card, i.e., "ace of spades"
// a Card is constructed from a rank (int in range 1..13)
// and a suit (Card::spades, Card::hearts, Card::diamonds,
// Card::clubs)
//
// Cards should be created by a Deck (see deck.h), a Deck returns
// good cards
// The function toString() converts a card to a string, e.g., to print
//
// Accessor functions include
//
// int GetRank() -- returns 1, 2, ..., 13 for ace, two, ..., king
//
// bool SameSuitAs(c) -- returns true if same suit as Card c
//
// string suitString() -- returns "s", "h", "d" or "c"
//
// Note that the Ace is represented by 1 and the King by 13
#ifndef _CARD_H
#define _CARD_H
#include <iostream>
#include <string>
using namespace std;
class card
{
public:
enum Suit {spades, hearts, diamonds, clubs};
card(); // default, ace of spades
card(int rank, Suit s);
string toString() const; // return string version e.g. Ac 4h Js
bool sameSuitAs(const card& c) const; // true if suit same as c
int getRank() const; // return rank, 1..13
string suitString(Suit s) const; // return "s", "h",...
string rankString(int r) const; // return "A", "2", ..."Q"
bool operator == (const card& rhs) const;
bool operator != (const card& rhs) const;
private:
int myRank;
Suit mySuit;
};
ostream& operator << (ostream& out, const card& c);
#endif