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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <time.h>
#include "MainBankClass.h"
Banking::Banking()
{
acctNumber[13] = 0;
acctBalance = 0;
}
/********************************\
| The following code is to print the menu |
| and recieve the users choice on what |
| they want to do with the ATM |
\********************************/
char Banking::menu()
{
char choice;
cout << "\t\t -=[ Main Menu ]=- \n\n"
<< "\tA) Create New Account\n"
<< "\tB) View Account Balance\n"
<< "\tC) Transfer Funds From Checking To Savings\n"
<< "\tD) Transfer Funds From Savings To Checking\n"
<< "\tE) Exit\n"
<< "\n\n\tSelection: ";
cin >> choice;
cin.ignore();
choice = toupper(choice);
while(!isalpha(choice))
{
invalid("[!!] Invalid selection.\n[!!] Choose a valid option: ");
cin >> choice;
cin.ignore();
}
switch(choice)
{
case 'A':
createNewAccount();
break;
case 'B':
getAcctInfo();
break;
case 'C':
cout << "Choice C" << endl;
break;
case 'D':
cout << "choice D" << endl;
break;
case 'E':
cout << "Exiting" << endl;
exit(1);
break;
default:
system("cls");
invalid("\n\n\n\n\t\t [!!] Invalid Selection \n\t\t Good-bye \n\n\n\n\n\n\n");
exit(1);
break;
}
return choice;
}
/***************************\
| Incase an invalid decision to made |
| this throws the error message sent |
| to it by the calling area |
\***************************/
void Banking::invalid(char *msg)
{
cout << msg;
}
/*************************\
| Used if files can not be opened |
| and exits with code 251: |
| miscommunication with server |
\*************************/
void Banking::fatal(char *msg)
{
cout << msg;
exit(1);
}
/***************************\
| Create an account, either checking |
| or savings, or both. |
| Must should create a randomly |
| generated account number that will |
| correspond with each account. |
\***************************/
/************************\
NOTE:: WILL BE UPDATED
TO CONTAIN A PIN FOR
ACCOUNT VERIFICATION
*************************/
void Banking::createNewAccount()
{
srand(time(NULL)); // Seed random generator with time initialized to NULL
char acctChoice; // choice for the account type
float initCheckDeposit = 0; // The initial deposit for checking account
float initSaveDeposit = 0; // The initial deposit for saving account
ofstream checkFile("checking.dat", ios::out | ios::binary | ios::app); // For saving checking accounts
ofstream saveFile("saving.dat", ios::out | ios::binary | ios::app); // For saving savings accounts
system("cls");
cout << "\t\t-=[ New Account Creation ]=-\n\n" << endl;
cout << "A) Checking Account\n"
<< "B) Savings Account\n"
<< "C) Checking and Saving Account\n" << endl;
cout << "New account type: ";
cin >> acctChoice;
acctChoice = toupper(acctChoice);
cin.clear();
cin.sync();
switch(acctChoice)
{
case 'A':
system("cls");
cout << "\t\t -=[ New Checking Account ]=- \n" << endl;
cout << "Name of the main holder to be on the account: ";
getline(cin, acctName);
cout << "Initial deposit amount: $";
cin >> initCheckDeposit;
if(!checkFile)
fatal("[!!] Fatal Error 251: Miscommunication with server\n");
for(int i = 0; i < 12; i++)
{
acctNumber[i] = (rand() % 10); // Build a random checking account number
}
checkFile << acctName << endl;
checkFile << acctNumber << endl;
checkFile << initCheckDeposit << endl;
break;
case 'B':
system("cls");
cout << "\t\t -=[ New Savings Account ]=- \n" << endl;
cout << "Name of the main holder to be on account: ";
getline(cin, acctName);
cout << "Deposit Amount: $";
cin >> initSaveDeposit;
if(!saveFile)
fatal("[!!] Fatal Error 251: Miscommunication with server\n");
for(int i = 0; i < 12; i++)
{
acctNumber[i] = (rand() % 10);
}
saveFile << acctName << endl;
saveFile << acctNumber << endl;
saveFile << initSaveDeposit << endl;
break;
case 'C':
system("cls");
cout << "\t -=[ New Checking / Saving Account ]=- \n" << endl;
cout << "Name of the main holder to be on account: ";
getline(cin, acctName);
cout << "Checking Deposit Amount: $";
cin >> initCheckDeposit;
cout << "Saving Deposit Amount: $";
cin >> initSaveDeposit;
if(!saveFile || !checkFile)
fatal("[!!] Fatal Error 251: Miscommunication with server\n");
for(int i = 0; i < 12; i++)
{
acctNumber[i] = (rand() % 10);
}
saveFile << acctName << endl;
saveFile << acctNumber << endl;
saveFile << initSaveDeposit << endl;
checkFile << acctName << endl;
checkFile << acctNumber << endl;
checkFile << initCheckDeposit << endl;
break;
default:
system("cls");
fatal("[!!] Invalid option\n");
break;
}
}
/*********************\
| Will read in account info |
| and display it for the user |
\*********************/
void Banking::getAcctInfo()
{
int i = 0;
double balance = 0;
char choice;
string name;
fstream checkFile("checking.dat", ios::in | ios::binary | ios::beg);
fstream saveFile("saving.dat", ios::in | ios::binary | ios::beg);
system("cls");
cout << "\t\t -=[ View Account Balance ]=-\n\n";
cout << "A) View Checking Account\n"
<< "B) View Saving Account\n"
<< "C) View Checking \\ Saving Account\n" << endl;
cout << "Choice: " << endl;
cin >> choice;
choice = toupper(choice);
if(!isalpha(choice))
fatal(" [!!] Invalid Choice");
switch(choice)
{
case 'A':
cin.clear();
system("cls");
cout << "\t\t -=[ View Checking Account ]=-\n\n" << endl;
cout << "Account Name: ";
cin.sync();
getline(cin, name);
getline(checkFile, acctName);
while(name != acctName && !checkFile.eof())
{
i++;
getline(checkFile, acctName);
}
if(name == acctName)
{
checkFile.seekg((sizeof(acctName) * i), ios::beg);
getline(checkFile, acctName);
checkFile >> acctNumber[13];
checkFile >> acctBalance;
system("cls");
cout << "\t\t -=[ Account Overview ]=-\n\n" << endl;
cout << "Account Name: " << acctName << "\n"
<< "Account Number: " << acctNumber << "\n"
<< "Balance: $" << acctBalance << endl;
}
else
{
fatal("[!!] Invalid Entry\n");
}
break;
}
}
| |