-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStation.cpp
More file actions
70 lines (56 loc) · 1.91 KB
/
Station.cpp
File metadata and controls
70 lines (56 loc) · 1.91 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
/* I have done all the coding by myself and only copied the code that my professor provided to complete my workshops and assignments.
Name: Hayaturehman Ahmadzai
Email: hahmadzai3@myseneca.ca
Student ID: 122539166
Created on 2021-07-09.*/
#include <iostream>
#include <iomanip>
#include "Utilities.h"
#include "Station.h"
namespace sdds {
size_t Station::m_widthField = 0;
size_t Station::id_generator = 1;
Station::Station(const std::string& record)
{
m_id = id_generator++;
Utilities utils;
size_t npos = 0;
bool more;
try {
m_name = utils.extractToken(record, npos, more);
m_nextSerial = std::stoi(utils.extractToken(record, npos, more));
m_stockQty = std::stoi(utils.extractToken(record, npos, more));
m_widthField = std::max(utils.getFieldWidth(), m_widthField);
m_desc = utils.extractToken(record, npos, more);
} catch (std::string& err) {
std::cout << err;
}
}
const std::string& Station::getItemName() const
{
return m_name;
}
size_t Station::getNextSerialNumber()
{
return m_nextSerial++;
}
size_t Station::getQuantity() const
{
return m_stockQty;
}
void Station::updateQuantity()
{
if (0 > --m_stockQty) m_stockQty = 0;
}
void Station::display(std::ostream& os, bool full) const
{
os << "[" << std::setfill('0') << std::setw(3) << std::right << m_id;
os << "] Item: " << std::setw(m_widthField) << std::setfill(' ') << std::left << m_name;
os << " [" << std::setfill('0') << std::setw(6) << std::right << m_nextSerial << "]" ;
if (full) {
os << " Quantity: " << std::setw(m_widthField) << std::setfill(' ') << std::left << m_stockQty
<< " Description: " << m_desc << std::endl;
}
else os << std::endl;
}
}