-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashier.cpp
More file actions
59 lines (51 loc) · 1.17 KB
/
Cashier.cpp
File metadata and controls
59 lines (51 loc) · 1.17 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
#include <iostream>
#include <iomanip>
class money {
int kn;
int lp;
public:
money(int kn = 0, int lp = 0) : kn(kn), lp(lp) {}
money& operator+=(const money& novac);
money& operator-=(const money& novac);
friend std::ostream& operator<<(std::ostream& os, const money& novac);
friend std::istream& operator>>(std::istream& is, money& novac);
};
money& money::operator+=(const money& novac) {
this->lp += novac.lp;
this->kn += novac.kn;
if (this->lp >= 100) {
this->lp -= 100;
++(this->kn);
}
return *this;
}
money& money::operator-=(const money& novac) {
this->lp -= novac.lp;
this->kn -= novac.kn;
if (this->lp < 0) {
--this->kn;
this->lp += 100;
}
return *this;
}
std::ostream& operator<<(std::ostream& os, const money& novac) {
os << novac.kn << " kn";
if (novac.lp)
os << ", " << std::setw(2) << std::setfill('0') << novac.lp << " lp";
return os;
}
std::istream& operator>>(std::istream& is, money& novac) {
is >> novac.kn >> novac.lp;
return is;
}
int main() {
money racun, uk;
char c;
while (std::cin >> c >> racun) {
if (c == '-')
uk -= racun;
else
uk += racun;
}
std::cout << uk;
}