-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStation.cpp
More file actions
69 lines (59 loc) · 2 KB
/
Station.cpp
File metadata and controls
69 lines (59 loc) · 2 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
// Name: Phu Thong Pham
// Seneca Student ID: 106455199
// Seneca email: ptpham4@myseneca.ca
// Date of completion: Nov 14, 2020
//
// I confirm that I am the only author of this file
// and the content was created entirely by me.
#include <iostream>
#include <iomanip>
#include <string>
#include <exception>
#include "Utilities.h"
#include "Station.h"
using namespace std;
size_t Station::m_widthField = 0u;
unsigned int Station::id_generator = 0u;
Station::Station(const string& stationInit) {
Utilities stationUtil;
size_t next_pos = 0;
bool more = true;
try {
m_itemName = stationUtil.extractToken(stationInit, next_pos, more);
m_serialNumber = stoi(stationUtil.extractToken(stationInit, next_pos, more));
m_quantity = stoi(stationUtil.extractToken(stationInit, next_pos, more));
if (m_widthField < stationUtil.getFieldWidth())
m_widthField = stationUtil.getFieldWidth();
m_desc = stationUtil.extractToken(stationInit, next_pos, more);
m_id = ++id_generator;
}
catch (invalid_argument& tokenError) {
cout << "Exception: " << tokenError.what() << endl;
}
catch (...) {
cout << "Unhandled Exception!" << endl;
}
}
const string& Station::getItemName() const {
return m_itemName;
}
unsigned int Station::getNextSerialNumber() {
return m_serialNumber++;
}
unsigned int Station::getQuantity() const {
return m_quantity;
}
void Station::updateQuantity() {
if (m_quantity > 0)
m_quantity--;
}
void Station::display(ostream& os, bool full) const {
os << "[" << setw(3) << setfill('0') << right << m_id << "] " << setfill(' ');
os << "Item: " << setw(m_widthField) << left << (m_itemName.empty() ? "" : m_itemName) << " ";
os << "[" << setw(6) << setfill('0') << right << m_serialNumber << "]" << setfill(' ');
if (full) {
os << " Quantity: " << setw(m_widthField) << left << m_quantity;
os << " Description: " << left << (m_desc.empty() ? "" : m_desc);
}
os << endl;
}