-
Notifications
You must be signed in to change notification settings - Fork 0
/
Till.hpp
110 lines (96 loc) · 3.47 KB
/
Till.hpp
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
/**
* @file This file is part of CashRegister.
*
* @section LICENSE
* MIT License
*
* Copyright (c) 2018 Rajdeep Konwar
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @section DESCRIPTION
* Till class definitions and inline methods.
**/
#ifndef TILL_HPP
#define TILL_HPP
#include <iostream>
#include <sstream>
#include <unordered_map>
/** The cash register holds zero or more of these bills and coins in the Till.
* The value of the enum is its worth in cents.
*/
enum Denomination {
Penny = 1,
Nickel = 5,
Dime = 10,
Quarter = 25,
Half = 50,
Dollar = 100,
Five = 500,
Ten = 1000,
Twenty = 2000,
Fifty = 5000,
Hundred = 10000
};
class Till {
private:
//! This is the LCD display on the cash register
std::ostream m_display;
//! This is the Till. All bills and coins are stored here
std::unordered_map< Denomination, int > m_till;
//! Overloaded operator << for LCD displays
inline std::ostream & operator << ( const char *i_message ) {
m_display << i_message;
return m_display;
}
//! How much money is in the cash register?
double totalInRegister() const;
// -------------------------------------------------------
// Function: CashRegister::Dispense
// Purpose: Remove coins/bills from the Till and give them to the customer
// -------------------------------------------------------
inline void dispense( const Denomination &i_d,
const int &i_count ) {
m_till[i_d] -= i_count;
}
// -------------------------------------------------------
// Function: Till::reportError
// Purpose: There is a problem!
// -------------------------------------------------------
inline void reportError( const char *i_text ) {
m_display << i_text << std::endl;
}
//! Display readable denomination info
std::string displayDenomination( const Denomination &i_d ) const;
public:
Till( std::ostream &out );
// -------------------------------------------------------
// Function: Till::~Till
// Purpose: Destructor - display final amount left in Till
// -------------------------------------------------------
inline ~Till() {
std::cout << "\nFinal amount in register = $" << totalInRegister() << std::endl;
}
/** The customer has paid money, that money is already in the Till
* Now, dispense change.
**/
int makeChange( const double &i_amountPaid,
const double &i_amountOwed );
};
#endif