-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.cpp
More file actions
88 lines (73 loc) · 1.56 KB
/
Item.cpp
File metadata and controls
88 lines (73 loc) · 1.56 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
//Implementation file for Item Class
// Brian Terry
// 12/5/2019
//Includes
#include <iomanip>
#include "Item.h"
using namespace std;
//Implementation
Item::Item() : Item("UNDEFINED") {}
Item::Item(string val, int qty) {
name = val;
quantity = qty;
}
Item::Item(const Item &obj) {
id = obj.id;
name = obj.name;
quantity = obj.quantity;
}
Item::~Item() {}
void Item::saveItem(DataManager *dm) {
dm->writeInt(id);
dm->writeString(name);
dm->writeInt(quantity);
}
void Item::loadItem(DataManager *dm) {
id = dm->readInt();
name = dm->readString();
quantity = dm->readInt();
}
const Item Item::operator =(const Item &rhs) {
if (this != &rhs) {
id = rhs.id;
name = rhs.id;
quantity = rhs.quantity;
}
return *this;
}
Item Item::operator++() {
++quantity;
return *this;
}
Item Item::operator ++(int) {
Item temp(name, quantity);
temp.id = id;
quantity++;
return temp;
}
Item Item::operator--() {
if (quantity > 0) { --quantity; }
return *this;
}
Item Item::operator--(int) {
Item temp(name, quantity);
temp.id = id;
if (quatity > 0) { quatity--; }
return temp;
}
ostream& operator <<(ostream& strm, const Item& obj) {
strm << "[" << obj.id << "] ";
if (obj.id < 10 ) {
strm << " ";
}
strm << obj.quantity <<"x " << obj.name;
return strm;
}
istream& operator >>(istream& strm, Item& obj) {
cout << "Name: ";
getline(strm, obj.name);
cout << "Quantity: ";
strm >> obj.quantity;
strm.ignore();
return strm;
}