-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockitem.cpp
116 lines (98 loc) · 1.87 KB
/
stockitem.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
// Description: Implementation of a StockItem class
#include "stockitem.h"
StockItem::StockItem()
{
sku = 0;
description = "";
price = 0;
stock = 0;
}
StockItem::StockItem(int skuid, std::string desc, double p)
{
sku = skuid;
if (sku > 99999) sku = sku % 100000;
if (sku < 10000) sku += 10000; // force sku to 5 digits
if (desc.length() > 30)
description = desc.substr(0, 29);
else
description = desc;
price = p;
stock = 0;
}
int StockItem::GetSKU() const
{
return sku;
}
std::string StockItem::GetDescription() const
{
return description;
}
double StockItem::GetPrice() const
{
return price;
}
int StockItem::GetStock() const
{
return stock;
}
bool StockItem::SetDescription(std::string newdesc)
{
if (newdesc.length() > 30)
description = newdesc.substr(0, 29);
else
description = newdesc;
return true;
}
bool StockItem::SetPrice(double newprice)
{
if (newprice >= 0)
{
price = newprice;
return true;
}
else return false;
}
bool StockItem::SetStock(int amount)
{
if (amount >= 0)
{
stock = amount;
return true;
}
else return false;
}
bool StockItem::operator==(const StockItem& item) const
{
return (sku == item.GetSKU());
}
bool StockItem::operator!=(const StockItem& item) const
{
return !(*this == item);
}
bool StockItem::operator>(const StockItem& item) const
{
return (sku > item.GetSKU());
}
bool StockItem::operator<(const StockItem& item) const
{
return (sku < item.GetSKU());
}
bool StockItem::operator>=(const StockItem& item) const
{
return !(*this < item);
}
bool StockItem::operator<=(const StockItem& item) const
{
return !(*this > item);
}
StockItem& StockItem::operator=(const StockItem& item)
{
if (this != &item)
{
this->sku = item.sku;
this->description = item.description;
this->price = item.price;
this->stock = item.stock;
}
return *this;
}