-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSportsCard.cpp
More file actions
194 lines (163 loc) · 6.07 KB
/
Copy pathSportsCard.cpp
File metadata and controls
194 lines (163 loc) · 6.07 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Blake Berry
// 03/08/2022
// Homework 4
// This file is an implimentation for the SportsCard class. The SportsCard
// class Inherited from the collectible interface. The Comic class represents
// an item that can exist at a collectible store
//-----------------------------------------------------------------------------
#include "SportsCard.h"
//-------------------------- Constructor -----------------------------------
// Creates a completely empty SportsCard with empty fields
// Postconditions: an empty SportsCard is created
SportsCard::SportsCard(std::string key) :
Collectible(key),
player_(""),
manufacturer_(""),
year_(0),
grade_("")
{
}
//-------------------------- destructor -----------------------------------
// Frees any dynamic memory associated with the SportsCard
// Postconditions: The SportsCard is freed of any dynamic memory
SportsCard::~SportsCard()
{
}
//-------------------------- Create --------------------------------------
// Parses a given string and created a SportsCard from a given string
// returning itself
// PreConditions : The SportsCard data must be formatted correctly in the
// string
// Postconditions: returns a constant pointer to the created SportsCard
// throws an exception if any of the information is invalid
const SportsCard* SportsCard::create(std::string toMakeFrom) const
{
SportsCard* dummy = new SportsCard();
// assumes that year comes first
dummy->year_ = std::stoi(Collectible::processConstruction(toMakeFrom));
if (dummy->year_ < 1000 || dummy->year_ > 2022) {
//throw error
}
// assumes grade comes second
dummy->grade_ = Collectible::processConstruction(toMakeFrom);
/*
if (dummy->grade_ < 0) {
//throw error
}
*/
dummy->player_ = Collectible::processConstruction(toMakeFrom);
dummy->manufacturer_ = Collectible::processConstruction(toMakeFrom);
return dummy;
}
//-------------------------- operator== ------------------------------------
// Checks if two SportsCards are equivilent. Equivilance is defined as each
// Comic having the same player, manufacturer, year, and grade
// Postconditions: Returns true if both SportsCards are equivilent
// Returns false if the SportsCards are not equivilent.
bool SportsCard::operator==(const Comparable& right) const
{
const SportsCard& toCheck = static_cast<const SportsCard&>(right);
bool equiv = true;
if (player_ != toCheck.player_) {
return false;
}
if (year_ != toCheck.year_) {
return false;
}
if (manufacturer_ != toCheck.manufacturer_) {
return false;
}
if (grade_ != toCheck.grade_) {
return false;
}
return equiv;
}
//-------------------------- operator!= --------------------------------------
// Checks if two SportsCards are not equivilent. Equivilance is defined as each
// Comic having the same player, manufacturer, year, and grade
// Postconditions: Returns true if both SportsCards are not equivilent
// Returns false if the SportsCards are equivilent.
bool SportsCard::operator!=(const Comparable& right) const
{
return !((*this) == right);
}
//-------------------------- operator> -------------------------------------
// Checks if two SportsCards have a greater than relationship. SportsCards
// are weighted such that we first consider them by player, then by
// manufacturer, then by year, then by grade.
// The fields are compared using defined >
// Postconditions: Returns true if the right hand side SportsCard is smaller
// than the left hand side. Otherwise, false is returned
bool SportsCard::operator>(const Comparable& right) const
{
const SportsCard& toCheck = static_cast<const SportsCard&>(right);
if (player_ > toCheck.player_) {
return true;
}
else if (player_ == toCheck.player_) {
if (year_ > toCheck.year_) {
return true;
}
else if (year_ == toCheck.year_) {
if (manufacturer_ > toCheck.manufacturer_) {
return true;
}
else if(manufacturer_ == toCheck.manufacturer_){
if (grade_ >toCheck.grade_) {
return true;
}
}
}
}
return false;
}
//-------------------------- operator< --------------------------------------
// Checks if two SportsCards have a less than relationship. SportsCards
// are weighted such that we first consider them by player, then by
// manufacturer, then by year, then by grade.
// The fields are compared using defined <
// Postconditions: Returns true if the right hand side SportsCard is larger
// than the left hand side. Otherwise, false is returned
bool SportsCard::operator<(const Comparable& right) const
{
const SportsCard& toCheck = static_cast<const SportsCard&>(right);
if (player_ < toCheck.player_) {
return true;
}
else if (player_ == toCheck.player_) {
if (year_ < toCheck.year_) {
return true;
}
else if (year_ == toCheck.year_) {
if (manufacturer_ < toCheck.manufacturer_) {
return true;
}
else if(manufacturer_ == toCheck.manufacturer_){
if (grade_ < toCheck.grade_) {
return true;
}
}
}
}
return false;
}
//-------------------------- print ----------------------------------------
// Prints the SportsCard player, manufacturer, year, and grade on one line
// Postconditions: prints to the console a representation of the SportsCard
void SportsCard::print() const
{
std::cout << "Sports Card : " << year_ << ", " << grade_
<< ", " + manufacturer_ << ", " + player_;
}
//-------------------------- copy ------------------------------------------
// creates a deep copy of the current coin and returns a non-modifyable
// pointer to it
// preconditions : The caller must means to deallocate the memory
// associated
// Postconditions: returns a constant pointer deep copy of the current
// coin
const SportsCard* SportsCard::copy() const
{
const SportsCard* copied = new SportsCard(*this);
return copied;
}