-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank account.cpp
111 lines (108 loc) · 2.92 KB
/
bank account.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
#include <iostream>
#include <fstream>
using namespace std;
struct bank
{
string name;
double bal;
long acc;
};
int main()
{
int n;
cout << "Enter no. of entries: ";
cin >> n;
struct bank arr[n];
ofstream outfile("F:\\bank.txt");
if (!outfile)
{
cout << "Cannot open file\n";
return 1;
}
outfile << "Name | Account Number | Balance\n";
for (int i = 0; i < n; i++)
{
cout << "\nEnter name of customer " << i + 1 << ": ";
cin >> arr[i].name;
cout << "Enter a/c number of customer " << i + 1 << ": ";
cin >> arr[i].acc;
cout << "Enter balance of customer " << i + 1 << ": ";
cin >> arr[i].bal;
outfile << arr[i].name << " | " << arr[i].acc << " | " << arr[i].bal << "\n";
}
outfile.close();
ifstream infile("F:\\bank.txt");
if (!infile)
{
cout << "File doesn't exist\n";
return 1;
}
string header;
getline(infile, header); // Skip the header line
for (int i = 0; i < n; i++)
{
cout << "\nDetails of customer " << i + 1 << endl;
getline(infile, arr[i].name,'|');
infile >> arr[i].acc;
infile.ignore(); // Ignore the comma
infile >> arr[i].bal;
infile.ignore(); // Ignore the newline character
cout << "Name: " << arr[i].name << "\n";
cout << "A/c number: " << arr[i].acc << "\n";
cout << "Balance (in INR): " << arr[i].bal << "\n";
}
infile.close();
return 0;
}
// #include <iostream>
// #include <fstream>
// using namespace std;
// struct bank
// {
// char name[20];
// double bal;
// long acc;
// };
// int main()
// {
// int n, i;
// cout << "Enter no. of entries : ";
// cin >> n;
// struct bank arr[n];
// ofstream outfile("F:\\bank.txt");
// if (!outfile)
// {
// cout << "Cannot outfileen file \n";
// return 1;
// }
// for (i = 0; i < n; i++)
// {
// cout << "\nEnter name of customer " << i + 1 << ": ";
// cin >>arr[i].name;
// cout << "Enter a/c number of customer " << i + 1 << ": ";
// cin >> arr[i].acc ;
// cout << "Enter balamce of customer " << i + 1 << ": ";
// cin >>arr[i].bal;
// outfile.write((char *)&arr[i], sizeof(struct bank));
// }
// outfile.close();
// ifstream infile("F:\\bank.txt");
// if (!infile)
// {
// cout << "File doesn't exists \n";
// return 1;
// }
// for (i = 0; i < n; i++)
// {
// if (infile)
// {
// cout<<"\nDetails of customer "<<i+1;
// infile.read((char *)&arr[i], sizeof(struct bank));
// cout << "Name : " << arr[i].name << "\n";
// cout << "A/c number : " << arr[i].acc << "\n";
// cout << "Balance (in INR) : " << arr[i].bal << "\n";
// }
// }
// infile.close();
// return 0;
// }