-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStation.cpp
138 lines (120 loc) · 2.53 KB
/
Station.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Author: Kathleen Monks
// Purpose: Final Project for Seneca's OOP345
// Date of completion: 2021-11-27
// ==========================================
#include <iostream>
#include <string>
#include <algorithm>
#include "Station.h"
using namespace std;
namespace sdds
{
// Initialize Class Variables
// ==========================
size_t Station::m_wField{ 0u };
int Station::id_generator{ 0u };
// Class Constraints
// =================
const size_t id_widthField{ 3 };
const size_t serialNo__widthField{ 6 };
Station::Station(const std::string& record)
{
Utilities util;
size_t next_pos{ 0u };
bool more{ true };
id_generator++;
m_id = id_generator;
m_item = util.extractToken(record, next_pos, more);
m_serialNumber = std::stoi(util.extractToken(record, next_pos, more));
m_noOfItems = std::stoi(util.extractToken(record, next_pos, more));
m_wField = std::max(util.getFieldWidth(), m_wField);
m_desc = util.extractToken(record, next_pos, more);
}
const std::string& Station::getItemName() const
{
return m_item;
}
size_t Station::getNextSerialNumber()
{
return m_serialNumber++;
}
size_t Station::getQuantity() const
{
return m_noOfItems;
}
void Station::updateQuantity()
{
if (m_noOfItems > 0)
{
m_noOfItems--;
}
}
void Station::display(std::ostream& os, bool full) const
{
if (!full)
{
// id
os << '[';
os.fill('0');
os.width(id_widthField);
os.setf(ios::right);
os << m_id;
os.unsetf(ios::right);
os << ']';
// item
os << " Item: ";
os.fill(' ');
os.width(m_wField);
os.setf(ios::left);
os << m_item;
os.unsetf(ios::left);
// serialNumber
os << " [";
os.fill('0');
os.width(serialNo__widthField);
os.setf(ios::right);
os << m_serialNumber;
os.unsetf(ios::right);
os << ']';
}
else
{
// id
os << '[';
os.fill('0');
os.width(id_widthField);
os.setf(ios::right);
os << m_id;
os.unsetf(ios::right);
os << ']';
// item
os << " Item: ";
os.fill(' ');
os.width(m_wField);
os.setf(ios::left);
os << m_item;
os.unsetf(ios::left);
// serialNumber
os << " [";
os.fill('0');
os.width(serialNo__widthField);
os.setf(ios::right);
os << m_serialNumber;
os.unsetf(ios::right);
os << ']';
// noOfItems
os << " Quantity: ";
os.fill(' ');
os.width(m_wField);
os.setf(ios::left);
os << m_noOfItems;
os.unsetf(ios::left);
// desc
os << " Description: ";
os.setf(ios::left);
os << m_desc;
os.unsetf(ios::left);
}
os << endl;
}
}