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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
const int SIZE = 100;
// This enumeration is from the assignment document.
enum AccountType {
unknown = -1, Checking, Savings
};
// This record (struct) is from the assignment document.
struct bankAccount
{
char name[SIZE];
float amount;
AccountType type;
};
void customer(int accountnumber, double balance);
void bankteller(int accountnumber, double balance);
void supervisor(int accountnumber, double balance);
void deposit(bankAccount accounts[], char accountName[], float amount);
void withdraw(bankAccount accounts[], char accountName[], float amount);
void transfer(int x);
void addaccount();
void deleteaccount();
void search();
void listcustomers();
void listmoney();
void listdeposits();
void listwithdrawals();
void balanceInquiry(bankAccount accounts[], char accountName[]);
int main()
{
bankAccount accounts[SIZE]; // This is the array of structs.
for (int i = 0; i < SIZE; i++) // initialize the array.
{
strncpy(accounts[i].name, "none", SIZE);
accounts[i].amount = 0.0;
accounts[i].type = unknown;
}
int index = 0;
char choice;
cout << "Welcome to the Bank Customer Record. \n";
cout << "Which interface would you like to access: (c)ustomer, (b)ank Teller, or (s)upervisor or would you like to (q)uit: ";
cin >> choice;
while (choice != 'q')
{
switch (choice)
{
case 'c':
customer(accounts);
break;
case 'b':
bankteller(accounts);
break;
case 's':
supervisor(accounts);
break;
default:
cout << "Sorry, didn't understand your choice. Try again." << endl;
}
}
cout << "\n\n\tThanks For Visiting Our Bank!";
system("pause");
return 0;
}
void customer(bankAccount accounts[])
{
char choice;
char accountName[100];
float amount;
cout << "Welcome, customer. /n";
cout << "What would you like to do: (l)ook at balance inquiry, (d)eposit funds, (w)ithdraw funds, (t)ransfer funds, or (q)uit?";
cin >> choice;
cout << "What is the account name? ";
cin >> accountName;
while (choice != 'q')
{
switch (choice)
{
case 'l':
balanceInquiry(accounts, accountName);
break;
case 'd':
cout << "How much are you depositing? ";
cin >> amount;
deposit(accounts, accountName, amount);
break;
case 'w':
cout << "How mucha are you withdrawing? ";
withdraw(accounts, accountName, amount);
break;
case 't':
//transfer(x);
break;
default:
cout << "Sorry, didn't understand your choice. Try again." << endl;
}
}
cout << endl;
}
void bankteller(bankAccount accounts[])
{
char choice;
char accountName[100];
float amount;
cout << "Welcome, bank teller. /n";
cout << "What would you like to do: (l)ook at balance inquiry, (d)eposit funds, (w)ithdraw funds, (t)ransfer funds, (a)dd a new account, delet(e) an account, (s)earch for an account, or (q)uit?";
cin >> choice;
cout << "What is the account name? ";
cin >> accountName;
while (choice != 'q')
{
switch (choice)
{
case 'l':
balanceInquiry(accounts, accountName);
break;
case 'd':
cout << "How much are you depositing? ";
cin >> amount;
deposit(accounts, accountName, amount);
break;
case 'w':
cout << "How much are you withdrawing? ";
withdraw(accounts, accountName, amount);
break;
case 't':
//transfer(x);
break;
case 'a':
addaccount();
break;
case 'e':
deleteaccount();
break;
case 's':
search();
break;
default:
cout << "Sorry, didn't understand your choice. Try again." << endl;
}
}
cout << endl;
}
void supervisor(bankAccount accounts[])
{
cout << "Welcome, supervisor. /n";
cout << "What would you like to do: (l)ook at balance inquiry, (d)eposit funds, (w)ithdraw funds, (t)ransfer funds, (a)dd a new account, delet(e) an account, (s)earch for an account, list amount of customers in Bank (1), list amount of money in Bank (2), list total deposits in Bank (3), list total withdrawals in Bank (4), or (q)uit?";
char choice;
char accountName[100];
float amount;
cout << "What is the account name? ";
cin >> accountName;
while (choice != 'q')
{
switch (choice)
{
case 'l':
balanceInquiry(accounts, accountName);
break;
case 'd':
cout << "How much are you depositing? ";
cin >> amount;
deposit(accounts, accountName, amount);
break;
case 'w':
cout << "How much are you withdrawing? ";
withdraw(accounts, accountName, amount);
break;
case 't':
//transfer(x);
break;
case 'a':
addaccount();
break;
case 'e':
deleteaccount();
break;
case 's':
search();
break;
case '1':
listcustomers();
break;
case '2':
listmoney();
break;
case '3':
listdeposits();
break;
case '4':
listwithdrawals();
break;
default:
cout << "Sorry, didn't understand your choice. Try again." << endl;
}
}
cout << endl;
}
void balanceInquiry(bankAccount accounts[], char accountName[])
{
bool found = false;
for (int i = 0; i < SIZE; i++)
{
if (strcmp(accounts[i].name, accountName) == 0)
{
cout << "The balance is $" << accounts[i].amount << endl;
found = true;
}
}
if (found == false)
cout << "Sorry, that account was not found.";
}
void deposit(bankAccount accounts[], char accountName[], float amount)
{
bool found = false;
for (int i = 0; i < SIZE; i++)
{
if (strcmp(accounts[i].name, accountName) == 0)
{
accounts[i].amount += amount;
cout << "$" << amount << " successfully deposited." << endl;
found = true;
}
}
if (found == false)
cout << "Sorry, that account was not found.";
}
void withdraw(bankAccount accounts[], char accountName[], float amount)
{
bool found = false;
for (int i = 0; i < SIZE; i++)
{
if (strcmp(accounts[i].name, accountName) == 0)
{
accounts[i].amount -= amount;
cout << "$" << amount << " successfully withdrawn." << endl;
found = true;
}
}
if (found == false)
cout << "Sorry, that account was not found.";
}
void transfer(bankAccount accounts[], char accountName[], float amount)
{
bool found = false;
for (int i = 0; i < SIZE; i++)
{
if (strcmp(accounts[i].name, accountName) == 0)
{
}
}
if (found == false)
cout << "Sorry, that account was not found.";
}
void addaccount()
{
ifstream inData;
ofstream outData;
string fileName;
string str;
cout << "Insert the name of the data file: ";
cin >> fileName;
inData.open(fileName); // Access the file of the name you had inputted
string lastName, firstName, type;
double balance;
inData >> lastName >> firstName >> balance >> type;
cout << "What file would you like to save the data in?: ";
cin >> fileName;
outData.open(fileName);
outData << str;
cout << "\nEnter the customer's last name:";
cin >> lastName;
cout << "\n\nEnter the customer's first name : ";
cin >> firstName;
cin.ignore();
cin.getline(50, firstName);
cout << "\nEnter Type of The account (C/S) : ";
cin >> type;
type = toupper(type);
cout << "\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin >> deposit;
cout << "\n\n\nAccount Created.";
}
void deleteaccount();
{
account ac;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat", ios::binary);
if (!inFile)
{
cout << "File could not be open !! Press any Key...";
return;
}
outFile.open("Temp.dat", ios::binary);
inFile.seekg(0, ios::beg);
while (inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if (ac.retacno() != n)
{
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
}
}
inFile.close();
outFile.close();
remove("account.txt");
rename("Temp.txt", "account.txt");
cout << "\n\n\tRecord Deleted ..";
}
void search();
{
int seqSearch(const int list[], int listLength, int searchItem)
{
int loc;
bool found = false;
for (loc = 0; loc < listLength; loc++)
if (list[loc] == searchItem)
{
found = true;
break;
}
if (found)
return loc;
else
return -1;
}
}
|