-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.cpp
More file actions
52 lines (43 loc) · 1.21 KB
/
Copy pathCard.cpp
File metadata and controls
52 lines (43 loc) · 1.21 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
47
48
49
50
51
52
// Name: (Aryan LAkhani)
// Class (CECS 325-01)
// Project Name (Prog 1 – One Card War)
// Due Date (09/18/2025)
//
// I certify that this program is my own original work. I did not copy any part of this program from
// any other source. I further certify that I typed each and every line of code in this program.
#include "Card.h"
// default constructor (just making a "blank" card basically)
Card::Card()
{
rank = '0'; // nothing real, just filler
suit = 'X'; // same thing, fake suit
}
// constructor when we actually know the rank + suit
Card::Card(char r, char s)
{
rank = r; // ex: 'A'
suit = s; // ex: 'H'
}
// show the card (prints like "AS" or "10D")
void Card::display()
{
cout << rank << suit;
}
// compare this card vs another card
// return 1 if this card is bigger
// return -1 if it’s smaller
// return 0 if they’re equal
int Card::compare(Card other)
{
// order of ranks low → high
// (T is being used for 10)
string ranks = "23456789TJQKA";
int thisVal = ranks.find(rank);
int otherVal = ranks.find(other.rank);
if (thisVal > otherVal)
return 1;
if (thisVal < otherVal)
return -1;
// only way left is they’re equal
return 0;
}