-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.cpp
60 lines (46 loc) · 1.55 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
//Name: Chaoyi Wu
// Seneca Student ID: 154330179
// Seneca email: [email protected]
// Date of completion: Nov. 14th
//
// I confirm that the content of this file is created by me,
// with the exception of the parts provided to me by my professor.
#include <sstream>
#include <algorithm>
#include <iomanip>
#include "Item.h"
#include "Utilities.h"
size_t Item::m_widthField = 0;
Item::Item(const std::string& record) {
Utilities utility;
size_t next_pos = 0;
bool more = true;
m_name = utility.extractToken(record, next_pos, more);
std::stringstream ss(utility.extractToken(record, next_pos, more));
ss >> m_serialNumber;
ss = std::stringstream(utility.extractToken(record, next_pos, more));
ss >> m_quantity;
m_widthField = std::max(m_widthField, utility.getFieldWidth());
m_description = utility.extractToken(record, next_pos, more);
}
const std::string& Item::getName() const {
return m_name;
}
const unsigned int Item::getSerialNumber() {
return m_serialNumber++;
}
const unsigned int Item::getQuantity() {
return m_quantity;
}
void Item::updateQuantity(){
m_quantity = m_quantity - 1 < 0 ? 0 : m_quantity - 1;
}
void Item::display(std::ostream& os, bool full) const {
os << std::left << std::setw(m_widthField) << m_name;
os << " [" << std::right << std::setw(6) << std::setfill('0') << m_serialNumber << "]";
os << std::setfill(' ');
if (full) {
os << std::left << " Quantity: " << std::setw(m_widthField) << m_quantity << " Description: " << m_description;
}
os << std::endl;
}