/*
Name: Program for Alibaba bank account, aiming to build a simple bank system using class and objects, but with multiple users input.
Author: muguangde
Date:09/22/2014-09:21AM
Description: This is a small program to simulate bank
account management. User create an account first, then
perform other operations.
*/
#include "Bank.h"
//New added functions to read initial info of users
void Bank::readInitial()
{
int account_num,type;
double amount;
string fname,lname,ssn;
fstream infile;
int initial_acc_num=0;
infile.open("InitialAccount.txt");
if(!infile.is_open()) {
cout<<"Error: fail to open file."<<endl;
// system("PAUSE");
// exit(1);
}
//To read in the data
while(!infile.eof())
{
infile>>account_num>>type>>amount>>fname>>lname>>ssn;
initial_acc_num++;
/* Dynamically Allocate new Accounts */
acct [numaccts++] = new Account (account_num,type,amount,fname,lname,ssn);
}
cout<<"*************************************************************"<<endl;
cout<<"********AliBABA banking system copyleft @2014***************"<<endl;
cout<<"*************************************************************"<<endl;
cout<<"There are "<<initial_acc_num<<" accounts initially in the bank system."<<endl;
infile.close();
}
//Function to read info from console
void Bank::readAccts()
{
int response;
cout << "Welcome to AliBABA Banking. Enter the Initial Accounts. " << endl;
cout << "Enter 1 for a new account, 0 to finish: " << endl;
cin >> response;
while(response) {
newAcct();
cout<< "Enter 1 for a new account, 0 to quit: " << endl;
cin >> response;
}
}
int Bank::find(int an)
{
for (int i = 0; i < numaccts; i++)
if (acct[i]->getAcctnum() == an)
return i;
return -1;
}
void Bank::newAcct()
{
int an, at;
double b;
string fn, ln;
string ssn;
cout << "Enter Account Number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos >= 0) {
cout << "Error! Account already exists." << endl;
return ;
}
else {
/* Call Typemenu() Function */
cout << "Enter Your First Name." << endl;
cin >> fn;
cout << "Enter Your Last Name." << endl;
cin >> ln;
cout << "Enter Your SSN." << endl;
cin >> ssn;
typemenu();
cout << "Enter the Account type you want to open." << endl;
cin >> at;
cout << "Enter the initial deposit." << endl;
cout << "$";
cin >> b;
/* Dynamically Allocate new Accounts */
acct [numaccts++] = new Account (an,at,b,fn,ln,ssn);
}
}
/* Bank: Deposit Function */
void Bank::deposit()
{
int an;
cout << "Enter your Account number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout << "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 0) {
cout << "Account was closed." << endl;
return;
}
acct[pos]->deposit();
}
//Function to do withdraw affair
void Bank::withdrawal()
{
int an;
cout << "Enter your Account number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout << "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 0) {
cout << "Account was closed." << endl;
return;
}
acct[pos]->withdrawal();
}
//Function to do inquiry
void Bank::inquiry()
{
int an;
cout << "Enter your Account Number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout << "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 0) {
cout << "Account was closed." << endl;
return;
}
acct[pos]->inquiry();
}
//Processing function here
void Bank::processTransactions()
{
char choice;
menu();
cin >> choice;
while (choice != 'Q' && choice != 'q') {
/*switch statement goes here */
switch(choice) {
case 'W':
case 'w':
withdrawal();
break;
case 'D':
case 'd':
deposit();
break;
case 'B':
case 'b':
inquiry();
break;
case 'N':
case 'n':
newAcct();
break;
case 'C':
case 'c':
closeAcct();
break;
case 'R':
case 'r':
reopenAcct();
break;
case 'X':
case 'x':
deleteAcct();
break;
case 'Q':
case 'q':
printAllAccts(); //PRINT ACCOUNT ARRAY
cout << "Thank You for using AliBABA Banking. Please come again!" << endl;
break;
default:
cout << "That is not a valid selection. Please select another choice." << endl;
}
menu();
cin >> choice;
}
}
//Function for the menu
void Bank::menu()
{
/* menu print goes here */
cout << "\t***************" << endl;
cout << "\t Bank Menu" << endl;
cout << "\t W - Withdraw" << endl;
cout << "\t D - Deposit" << endl;
cout << "\t N - New Account" << endl;
cout << "\t C - Close Account" << endl;
cout << "\t R - Reopen Account" << endl;
cout << "\t X - Delete Account" << endl;
cout << "\t B - Balance" << endl;
cout << "\t Q - Quit" << endl;
cout << "\t**************" << endl;
cout << endl;
cout<<"Enter choice now: " <<endl;
}
/* Bank: Type Menu Function */
void Bank::typemenu()
{
cout << "\t***************" << endl;
cout << "\t Type Menu" << endl;
cout << "\t 1 - Checking" << endl;
cout << "\t 2 - Savings" << endl;
cout << "\t 3 - Money Market" << endl;
cout << "\t**************" << endl;
cout << endl;
}
//Function to print
void Bank::printAllAccts()
{
string kind[3] = {"Checking ", "Savings ", "Money Market "};
cout << "\n******************************************" << endl;
cout << "********AliBABA banking system************" << endl;
cout << "******************************************" << endl;
cout << "Here is the information on all accounts:" << endl;
for(int i = 0; i < numaccts; i++) {
cout<< "Account Number " << acct[i]->getAcctnum() << endl;
cout<< "SSN " << acct[i]->getSsn() << endl;
cout << "Type of account: " << kind[acct[i]->getType()]<<endl;
if (acct[i]->getStatus()== 0)
cout << "Account was closed." << endl;
else
acct[i]->inquiry();
}
}
/* Close Account function */
void Bank::closeAcct()
{
int an;
cout << "Enter your Account number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout<< "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 0) {
cout << "Account is already closed!" << endl;
return;
}
acct[pos]->closeAcct();
}
/* Reopen Account function */
void Bank::reopenAcct() {
int an;
cout << "Enter your Account number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout<< "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 1) {
cout << "Account is already open!" << endl;
return;
}
acct[pos]->reopen();
}
void Bank::deleteAcct() {
int an;
cout << "Enter your Account number." << endl;
cin >> an;
/* Search For Account */
int pos = find(an);
if (pos < 0) {
cout<< "Account not found." << endl;
return;
}
if (acct[pos]->getStatus()== 1) {
cout << "Account must be closed before deletion." << endl;
return;
}
cout << "You have successfully deleted account." << acct[pos]->getAcctnum() << endl;
delete acct[pos];
numaccts--;
for (int i = pos; i < numaccts; i++)
acct[i] = acct[i+1];
}
回到主页
回到目录