-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.cpp
157 lines (140 loc) · 4.18 KB
/
logger.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "logger.h"
Logger::Logger()
{
initTimeDate(a);
}
void Logger::initTimeDate(string &a)
{
time_t rawtime;
struct tm *info;
time( &rawtime );
info = localtime( &rawtime );
a= asctime(info);
}
void Logger::printTransaction(int x, string s)
{
initTimeDate(a);
ofstream g;
g.open("logger.txt",ios::ate | ios::app);
if( s == "InquireBalance" )
g<< s <<": "<< a;
else
if( s == "Withdraw" )
g<< s <<": "<< x <<" "<< a;
else
if(s == "Deposit" )
g<< s <<": "<< x <<" "<< a;
g.close();
}
void Logger::prepareForTransactions(string acc)
{
ofstream g("logger.txt",ios::ate | ios::app);
g<<"---------------------------------------------------------------\n";
g<<"Account Number:"<<acc<<'\n';
g.close();
}
void Logger::itotalCashAmount(int x)
{
ofstream g("logger.txt",ios::ate | ios::app);
g<<"Suma initiala din automat: "<< x <<'\n';
g.close();
}
void Logger::ftotalCashAmount(int x)
{
ofstream g("logger.txt",ios::ate | ios::app);
g<<"Suma finala din automat: "<< x <<'\n';
g.close();
}
void Logger::printBanknotesStatus(const int vb[],int b[])
{
ofstream g("logger.txt",ios::ate | ios::app);
g<<"Statusul bancnotelor din bancomat:\n";
for(int i=0;i<5;i++)
g<< b[i] <<" bancnote de "<< vb[i] <<" lei \n";
g.close();
}
void Logger::printLackOfFunds(const int vb[], int b[])
{
ofstream g("logger.txt",ios::ate | ios::app);
g<<"Fonduri insuficiente in automat!\n";
g<<"Statusul bancnotelor din bancomat:\n";
for(int i=0;i<5;i++)
g<< b[i] <<" bancnote de "<< vb[i] <<" lei \n";
g.close();
}
///ACEASTA SECTIUNE A FOST MODIFICATA, FOLOSESTE LA CHITANTA
const char* Logger::showTransInfo(string accNr)
{
///ATENTIE LA DEPASIREA LIMITELOR TABLOULUI DE CARACTERE _text;
strcpy(_text,"");
ifstream f("logger.txt");
string s1;
string s2;
string s3;
while(!f.eof())
{
getline(f,a);
if( a.find("Account Number:")!=string::npos && a.find(accNr)!=string::npos )
{
while(getline(f,a))
{
if(a.find("Account Number:")== string::npos)
{
if(a.find("InquireBalance") != string::npos)
{
s1 = s2;
s2 = s3;
s3 = a;
}
if(a.find("Withdraw") != string::npos)
{
s1 = s2;
s2 = s3;
s3 = a;
}
if(a.find("Deposit") != string::npos)
{
s1 = s2;
s2 = s3;
s3 = a;
}
}}
}
}
initTimeDate(a);
strcat(_text, ("Statement of account\n\n" + a + "\n").c_str());
strcat(_text, ("Account Number: " + accNr + "\n\n" + s1 + "\n" + s2 + "\n" + s3 + "\n\n" + "Thank you, Z Bank").c_str());
f.close();
return (const char*) _text;
}
void Logger::loadTransInfoATM()
{
ifstream f("logger.txt");
counter=0;
while(!f.eof())
{
getline(f,b[counter]);
if(b[counter].find("InquireBalance") != string::npos)
counter++;
else
if(b[counter].find("Withdraw") != string::npos)
counter++;
else
if(b[counter].find("Deposit") != string::npos)
counter++;
}
f.close();
}
string Logger::getTransATM(int i)
{
if( i < counter)
{
return b[i];
}
else
return "";
}
int Logger::getLimitTransATM()
{
return counter;
}