-
Notifications
You must be signed in to change notification settings - Fork 0
/
abonent.h
119 lines (100 loc) · 2.79 KB
/
abonent.h
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
//(done)float -> целый
//(done)iterator end
//(done)сорт при выводе
#include "minilist.h"
#include "datetime.h"
#include <iostream>
#include <set>
struct TCall {
long long number;
DateTime date;
unsigned int duration;
TCall & operator = (const TCall & c)
{
number = c.number;
date = c.date;
duration = c.duration;
}
bool operator < (const TCall & c) const
{
return (date < c.date || (date == c.date && (number < c.number || (number == c.number && duration < c.duration))));
}
};
class Abonent {
unsigned int _traffic;
int _balance;
minilist<TCall> _history;
public:
Abonent(unsigned int); //traffic
Abonent(const Abonent &);
// ~Abonent();
Abonent & operator = (const Abonent &);
void balance_plus(unsigned int);
int balance();
void call(long long, DateTime, unsigned int); //number, date, duration
void history();
void history(DateTime);
void history(long long);
};
Abonent::Abonent(unsigned int traffic) : _traffic(traffic), _balance(0) {}
Abonent::Abonent(const Abonent & a) : _traffic(a._traffic), _balance(a._balance), _history(a._history) {}
Abonent & Abonent::operator = (const Abonent & a)
{
_traffic = a._traffic;
_balance = a._balance;
_history = a._history;
return *this;
}
void Abonent::balance_plus(unsigned int money)
{
_balance += money;
}
int Abonent::balance()
{
return _balance;
}
void Abonent::call(long long _number, DateTime _date, unsigned int _duration)
{
_balance -= _duration * _traffic;
TCall temp;
temp.number = _number;
temp.date = _date;
temp.duration = _duration;
_history.push_back(temp);
}
void Abonent::history()
{
std::multiset<TCall> hist;
for (_iterator<TCall> iter = _history.begin();; iter++) {
hist.insert(*iter);
if (iter == _history.end()) break;
}
std::cout << "History:" << std::endl;
for (std::multiset<TCall>::iterator iter = hist.begin(); iter != hist.end(); iter++) {
std::cout << iter->number << ' ' << iter->date << ' ' << iter->duration << std::endl;
}
}
void Abonent::history(DateTime dt)
{
std::multiset<TCall> hist;
for (_iterator<TCall> iter = _history.begin();; iter++) {
if (iter->date == dt) hist.insert(*iter);
if (iter == _history.end()) break;
}
std::cout << "Calls from " << dt << ':' << std::endl;
for (std::multiset<TCall>::iterator iter = hist.begin(); iter != hist.end(); iter++) {
std::cout << iter->number << ' ' << iter->duration << std::endl;
}
}
void Abonent::history(long long numb)
{
std::multiset<TCall> hist;
for (_iterator<TCall> iter = _history.begin();; iter++) {
if (iter->number == numb) hist.insert(*iter);
if (iter == _history.end()) break;
}
std::cout << "Calls to " << numb << ':' << std::endl;
for (std::multiset<TCall>::iterator iter = hist.begin(); iter != hist.end(); iter++) {
std::cout << iter->date << ' ' << iter->duration << std::endl;
}
}