-
Notifications
You must be signed in to change notification settings - Fork 0
/
banking record system.cpp
192 lines (192 loc) · 4.76 KB
/
banking record system.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include<iostream>
#include<fstream>
#include<cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::fstream;
using std::ofstream;
using std::ifstream;
using std::ios;
class account_query
{
private:
char account_number[20];
char firstName[10];
char lastName[10];
float total_Balance;
public:
void read_data();
void show_data();
void write_rec();
void read_rec();
void search_rec();
void edit_rec();
void delete_rec();
};
void account_query::read_data()
{
cout<<"\nEnter Account Number: ";
cin>>account_number;
cout<<"Enter First Name: ";
cin>>firstName;
cout<<"Enter Last Name: ";
cin>>lastName;
cout<<"Enter Balance: ";
cin>>total_Balance;
cout<<endl;
}
void account_query::show_data()
{
cout<<"Account Number: "<<account_number<<endl;
cout<<"First Name: "<<firstName<<endl;
cout<<"Last Name: "<<lastName<<endl;
cout<<"Current Balance: Rs. "<<total_Balance<<endl;
cout<<"-------------------------------"<<endl;
}
void account_query::write_rec()
{
ofstream outfile;
outfile.open("record.bank", ios::binary|ios::app);
read_data();
outfile.write(reinterpret_cast<char *>(this), sizeof(*this));
outfile.close();
}
void account_query::read_rec()
{
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"Error in Opening! File Not Found!!"<<endl;
return;
}
cout<<"\n****Data from file****"<<endl;
while(!infile.eof())
{
if(infile.read(reinterpret_cast<char*>(this), sizeof(*this))>0)
{
show_data();
}
}
infile.close();
}
void account_query::search_rec()
{
int n;
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to Search: ";
cin>>n;
infile.seekg((n-1)*sizeof(*this));
infile.read(reinterpret_cast<char*>(this), sizeof(*this));
show_data();
}
void account_query::edit_rec()
{
int n;
fstream iofile;
iofile.open("record.bank", ios::in|ios::binary);
if(!iofile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
iofile.seekg(0, ios::end);
int count = iofile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to edit: ";
cin>>n;
iofile.seekg((n-1)*sizeof(*this));
iofile.read(reinterpret_cast<char*>(this), sizeof(*this));
cout<<"Record "<<n<<" has following data"<<endl;
show_data();
iofile.close();
iofile.open("record.bank", ios::out|ios::in|ios::binary);
iofile.seekp((n-1)*sizeof(*this));
cout<<"\nEnter data to Modify "<<endl;
read_data();
iofile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
void account_query::delete_rec()
{
int n;
ifstream infile;
infile.open("record.bank", ios::binary);
if(!infile)
{
cout<<"\nError in opening! File Not Found!!"<<endl;
return;
}
infile.seekg(0,ios::end);
int count = infile.tellg()/sizeof(*this);
cout<<"\n There are "<<count<<" record in the file";
cout<<"\n Enter Record Number to Delete: ";
cin>>n;
fstream tmpfile;
tmpfile.open("tmpfile.bank", ios::out|ios::binary);
infile.seekg(0);
for(int i=0; i<count; i++)
{
infile.read(reinterpret_cast<char*>(this),sizeof(*this));
if(i==(n-1))
continue;
tmpfile.write(reinterpret_cast<char*>(this), sizeof(*this));
}
infile.close();
tmpfile.close();
remove("record.bank");
rename("tmpfile.bank", "record.bank");
}
int main()
{
account_query A;
int choice;
cout<<"***Acount Information System***"<<endl;
while(true)
{
cout<<"Select one option below ";
cout<<"\n\t1-->Add record to file";
cout<<"\n\t2-->Show record from file";
cout<<"\n\t3-->Search Record from file";
cout<<"\n\t4-->Update Record";
cout<<"\n\t5-->Delete Record";
cout<<"\n\t6-->Quit";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
A.write_rec();
break;
case 2:
A.read_rec();
break;
case 3:
A.search_rec();
break;
case 4:
A.edit_rec();
break;
case 5:
A.delete_rec();
break;
case 6:
exit(0);
break;
default:
cout<<"\nEnter corret choice";
exit(0);
}
}
system("pause");
return 0;
}