-
Notifications
You must be signed in to change notification settings - Fork 3
/
Card.cpp
159 lines (143 loc) · 4.47 KB
/
Card.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//******************************************************************************
//
// File Name: Card.cpp
//
// File Overview: Represents a Card containing a number and a suit
#include <iostream>
#include "Card.h"
#include "ConsoleUI.h"
using namespace std;
//******************************************************************************
// File scope (static) variable definitions
//******************************************************************************
// None
//******************************************************************************
// Function : constructor
// Process : Initialize data members to invalid values
// Notes : Not the recommended constructor
// Need to set the number and suit afterwards
//******************************************************************************
Card::Card()
{
number=0;
suit=0;
} // end Card::Card
//******************************************************************************
// Function : constructor
// Process : Initializes data members to input suit and number
// Notes : Recommended constructor
//******************************************************************************
Card::Card(int number, int suit)
{
this->number=number;
this->suit=suit;
} // end Card::Card
void Card::setNumber(int number)
{
this->number = number;
} // end Card::setNumber
//***************************************************************************
// Function : setSuit
// Process : Mutator for suit
// Notes : None
//***************************************************************************
void Card::setSuit(int suit)
{
this->suit = suit;
} // end Card::setSuit
//***************************************************************************
// Function : getNumber
// Process : Accessor for number
// Notes : None
//***************************************************************************
int Card::getNumber()
{
return this->number;
} // end Card::getNumber
//***************************************************************************
// Function : getSuit
// Process : Accessor for suit
// Notes : None
//***************************************************************************
int Card::getSuit()
{
return this->suit;
} // end Card::getSuit
//***************************************************************************
// Function : printCard
// Process : Print the card number and suit
// Call printNumber
// Call printSuit
// Notes : None
//***************************************************************************
void Card::printCard()
{
ConsoleUI* ui=new ConsoleUI();
ui->output(this->printNumber()+printSuit());
} // end Card::printCard
//***************************************************************************
// Function : printNumber
// Process : print the card number
// 11 - J for Jack
// 12 - Q for Queen
// 13 - K for King
// 14 - A for Ace
// Notes : None
//***************************************************************************
string Card::printNumber()
{
int number = this->getNumber(); // Obtain the card's number
if (number > 1 && number < 11)
{
return to_string(number);
}
else if (number == 11)
{
return "J";
}
else if (number == 12)
{
return "Q";
}
else if (number == 13)
{
return "K";
}
else if (number == 14)
{
return "A";
}
else
{
return " Invalid number ";
}
} // end Card::printNumber
//***************************************************************************
// Function : printSuit
// Process : Print the card suit
// Notes : None
//***************************************************************************
string Card::printSuit()
{
int suit = this->getSuit(); // Obtain the card's suit
if(suit == 0)
{
return "\u2660";
}
else if(suit == 1)
{
return "\u2665";
}
else if(suit == 2)
{
return "\u2666";
}
else if(suit == 3)
{
return "\u2663";
}
else
{
return "Invalid suit";
}
} // end Card::printSuit