-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientData.cpp
More file actions
executable file
·188 lines (149 loc) · 4.77 KB
/
ClientData.cpp
File metadata and controls
executable file
·188 lines (149 loc) · 4.77 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
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
// Class ClientData stores customer's account details.
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include "ClientData.h"
using namespace std;
// default ClientData constructor
ClientData::ClientData( int accountNumberValue, int pinCodeValue,
string UserNameString, double balanceValue )
{
setAccountNumber( accountNumberValue );
setPinCode( pinCodeValue );
setUserName( UserNameString );
setBalance( balanceValue );
} // end ClientData constructor
// get account-number value
int ClientData::getAccountNumber() const
{
return accountNumber;
} // end function getAccountNumber
// set account-number value
void ClientData::setAccountNumber( int accountNumberValue )
{
accountNumber = accountNumberValue; // should valdate
} // end function setAccountNumber
// set pin-code value
void ClientData::setPinCode(int pinCodeValue)
{
pinCode = pinCodeValue;
}// end function setPinCode
// get pin code value
int ClientData::getPinCode() const
{
return pinCode;
}// end function getpincode value
// get last-name value
string ClientData::getUserName() const
{
return UserName;
} // end function getLastName
// set last-name value
void ClientData::setUserName( string UserNameString )
{
// copy at most 15 characters from string to lastName
int length = UserNameString.size();
length = ( length < 15 ? length : 14 );
UserNameString.copy(UserName, length);
UserName[ length ] = '\0' ; // append null character to lastName
} // end function setName
// get balance value
double ClientData::getBalance() const
{
return balance;
} // end function getBalance
// set balance value
void ClientData:: setBalance( double balanceValue )
{
balance = balanceValue;
}
void ClientData::fileCreator()
{
ofstream outdatabase( "ATMData.txt", ios::out | ios::binary );
// exit program if ofstream could not open file
if (!outdatabase)
{
cerr<< "File could not be opened." << endl;
exit( 1 );
} // end if
ClientData blankClient; // constructor zeros out each data member
// output 100 blank records to file
for ( int i = 0; i < 10000; ++i )
outdatabase.write(reinterpret_cast< const char *>(&blankClient),
sizeof(ClientData));
} // end file creator
// create account
void ClientData::createAccount ()
{
int accountNumber;
int pinCode;
string UserName;
double balance;
fstream outdatabase( "ATMData.txt", ios::in | ios::out | ios::binary );
// exit program if fstream cannot open file
if (!outdatabase)
{
cerr << "File could not be opened." << endl;
exit( 1 );
} // end if
cout << "Enter account number (1 to 10000, 0 to end input)\n? ";
// require user to specify account number
ClientData database;
cin >> accountNumber;
// user enters information, which i copied into file
while ( accountNumber > 0 && accountNumber <= 10000 )
{
// user enters pin code, user name, and balance
cout << "Enter Pin code, User name, balance\n? ";
cin >> pinCode;
cin >>UserName;
cin >> balance;
// set record accountNumber, pincode, UserName, balance values
database.setAccountNumber( accountNumber ) ;
database.setPinCode(pinCode);
database.setUserName( UserName );
//database.setFirstName( firstName ) ;
database.setBalance( balance );
// seek position in file of user-specified record
outdatabase.seekp( ( database.getAccountNumber() - 1 ) *
sizeof( ClientData ) ) ;
// enable user to enter another account
cout << "Enter account number\n? ";
cin >> accountNumber;
} // end while
} // end save data to file
void ClientData::outputLine(ostream &output, const ClientData &record )
{
output << left << setw(10) << record.getAccountNumber()
<< record.getPinCode()
<< setw( 16 ) << record. getUserName()
<< setw( 10 ) << setprecision( 2 ) << right << fixed
<< showpoint << record.getBalance() << endl;
} // end function outputLine
void ClientData::searchAccount()
{
ifstream indatabase("ATM.txt", ios::in | ios::binary);
// exit program if ifstream cannot open file
if (!indatabase )
{
cerr << "File could not be opened." << endl;
exit( 1 );
} // end if
cout << left << setw( 10 ) << "Account" << setw( 16 )
<< setw( 11 ) << "User Name" << left
<< setw( 10 ) << right << "Balance" << endl;
ClientData database; // create record
indatabase.read(reinterpret_cast< char *>(&database),
sizeof(ClientData));
// read all records from fil e
while (indatabase && !indatabase.eof() )
{
// display record
if ( database.getAccountNumber() != 0 )
//outputLine(cout, client);
indatabase.read(reinterpret_cast < char *>(&database),
sizeof(ClientData));
} // end while
} // end search record