-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cpp
91 lines (75 loc) · 1.87 KB
/
Item.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
#include "Item.h"
#include <iostream>
// Definition of toLowerCase function
string toLowerCase(const string& str) {
string result = str;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
// Constructor
Item::Item(const string& itemName,
const string& itemDescription,
int itemAmount,
const string& itemImagePath)
: name(toLowerCase(itemName)),
description(itemDescription),
amount(itemAmount),
imagePath(itemImagePath),
category("[None]") {
}
// Setter for the name (stored in lowercase)
void Item::setName(const string& itemName) {
name = toLowerCase(itemName);
}
// Getter for the name
string Item::getName() const {
return name;
}
// Setter for the description
void Item::setDescription(const string& itemDescription) {
description = itemDescription;
}
// Getter for the description
string Item::getDescription() const {
return description;
}
// Setter for the image path
void Item::setImage(const string& itemImagePath) {
imagePath = itemImagePath;
}
// Getter for the image path
string Item::getImage() const {
return imagePath;
}
// Setter for the category
void Item::setCategory(const string& itemCategory) {
category = itemCategory;
}
// Getter for the category
string Item::getCategory() const {
return category;
}
// Setter for the amount
void Item::setAmount(int itemAmount) {
amount = itemAmount;
}
// Getter for the amount
int Item::getAmount() const {
return amount;
}
// Increase item quantity
void Item::increment() {
++amount;
}
// Decrease item quantity
void Item::decrement() {
--amount;
}
// Equality operator
bool Item::operator==(const Item& other) const {
return name == other.name &&
description == other.description &&
amount == other.amount &&
imagePath == other.imagePath &&
category == other.category;
}