PSP Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Welcome, Guest
You last visited:


You are not connected. Please login or register

My bank coursework

Go down  Message [Page 1 of 1]

1My bank coursework  Empty My bank coursework Sat Dec 11, 2010 11:40 am

Blacksun

Blacksun
GFX Team
GFX Team

thx scuzzy

At uni i had to complete a bank simulation for my coursework. Handed it in today, thank god.
It was not hard but it was just effort, like most things to do with my education. I leave everything to the last minute so this is not the best i can do if i actually sat and went to lectures and started when they handed out the assignment.

anyway, here is my code:

#include <iostream>
#include <ctime>
#include <fstream>

class CAccount
{
public:
void OpenAccount()
{
std::cout << "Enter Balance: ";
std::cin >> iBalance;
bMortgage = 0;
dCreditLimit = 300;
std::cout << "(C)urrent or (J)unior Account?";
std::cin >> cAccountType;
while (cAccountType != 'C' && cAccountType != 'J')
{
std::cout << "Invalid Option" << std::endl;
std::cout << "(C)urrent or (J)unior Account?";
std::cin >> cAccountType;
}
}

void PrintAccount()
{
std::cout << std::endl;
std::cout << "Account Number: " << iAccountNumber << std::endl;
std::cout << "Balance: " << iBalance << std::endl;
std::cout << "Credit Limit: " << dCreditLimit << std::endl;
std::cout << "Account Type: " << cAccountType << std::endl;
std::cout << "Mortgage payback ammount: " << bMortgage << std::endl;
}

void ShowBalance()
{
std::cout << "Balance: " << iBalance << std::endl;
}
int iAccountNumber;
int iCustomerID;
long int iBalance;
double dInterestRate;
double dCreditLimit;
long double bMortgage;

private:

char cAccountType;
};

class CurrentAccount : public CAccount
{
};

class CCustomer
{
public:
void AddNewCustomer()
{
std::cout << "Enter Name: ";
std::cin >> cName;
std::cout << "Enter Address: ";
std::cin >> cAddress;
std::cout << "Enter Telephone Number: ";
std::cin >> dTelNumber;
std::cout << "Enter Sex: ";
std::cin >> cSex;
std::cout << "Enter DOB: ";
std::cin >> cDOB;
}
void ShowPersonDetails()
{
std::cout << "ID: " << iCustomerID << std::endl;
std::cout << "Name: " << cName << std::endl;
std::cout << "Address: " << cAddress << std::endl;
std::cout << "Telephone Number: " << dTelNumber << std::endl;
std::cout << "Sex: " << cSex << std::endl;
std::cout << "DOB: " << cDOB << std::endl;
std::cout << "\n\n" << std::endl;
}

void UpdatePersonDetails()
{
int iChoice;
ShowPersonDetails();
std::cout << "Choose Details to edit: " << std::endl;
std::cout << "1. Name" << std::endl;
std::cout << "2. Address" << std::endl;
std::cout << "3. Telephone Number" << std::endl;
std::cout << "4. Sex" << std::endl;
std::cout << ": ";
std::cin >> iChoice;

switch (iChoice)
{
case 1 : std::cout << "Enter new Name: ";
std::cin >> cName;break;
case 2 : std::cout << "Enter new Address: ";
std::cin >> cAddress; break;
case 3 : std::cout << "Enter new Telephone Number: ";
std::cin >> dTelNumber; break;
case 4 : std::cout << "Enter new Sex: ";
std::cin >> cSex; break;
}


}


int iCustomerID;
char cName[30];

private:
char cAddress[100];
long int dTelNumber;
char cSex[6];
char cDOB[8];
};

struct AccountNode
{
CAccount New;
AccountNode *nxt;
};

struct CustomerNode
{
CCustomer New;
CustomerNode *nxt;
};


CustomerNode *Customerstart_ptr = NULL;
CustomerNode *Customercurrent;
AccountNode *Accountstart_ptr = NULL;
AccountNode *Accountcurrent;

std::ofstream myfile;


void CustomerSearch(int iSearch, bool& bExists)
{
using namespace std;

CustomerNode *temp;
temp = Customerstart_ptr;
cout << endl;
if (temp == NULL)
{
cout << "No Customers" << endl;
}
else
{
while (temp != NULL)
{
if (temp->New.iCustomerID == iSearch)
{
bExists = true;
}
temp = temp->nxt;
}
if (bExists == false)
{
cout << "Customer ID does not exist" << endl;
}
}

}

void ListAccountsAndBalances(int iID, int iAID)
{
using namespace std;

CustomerNode *temp;
temp = Customerstart_ptr;
AccountNode *temp2;
temp2 = Accountstart_ptr;

while (temp != NULL)
{
for (int i = 0; i < iID; i++)
{
cout << "Customer Name: " << temp->New.cName << endl;

while (temp2 != NULL)
{
if (temp2->New.iCustomerID == temp->New.iCustomerID)
{
temp2->New.ShowBalance();
temp2 = temp2->nxt;
}
else
{
temp2 = temp2->nxt;
}
}
temp2 = Accountstart_ptr;
temp = temp->nxt;
}
}
}

void AddAccount(int& iAID)
{
using namespace std;
int iCustomerID;
bool bExists = false;

AccountNode *temp, *temp2;

temp = new AccountNode;
cout << "Enter Customer ID: ";
cin >> iCustomerID;
CustomerSearch(iCustomerID, bExists);
if (bExists == true)
{

temp->New.iCustomerID = iCustomerID;
temp->New.OpenAccount();
temp->New.iAccountNumber = ++iAID;
temp->nxt = NULL;
cout << "\nAccount added to Customer ID " << iCustomerID << endl;

if (Accountstart_ptr == NULL)
{
Accountstart_ptr = temp;
Accountcurrent = Accountstart_ptr;
}
else
{
temp2 = Accountstart_ptr;
while (temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;
}
}
}

void DisplayCustomerAccounts()
{
using namespace std;

int iCustomerID;
bool bExists = false;

AccountNode *temp;
temp = Accountstart_ptr;
cout << endl;
if (temp == NULL)
{
cout << "No Customers" << endl;
}
else
{
cout << "Please Enter Customer ID: ";
cin >> iCustomerID;
CustomerSearch(iCustomerID, bExists);
if (bExists == true)
{
while (temp != NULL)
{
if(temp->New.iCustomerID == iCustomerID)
{
temp->New.PrintAccount();
}
temp = temp->nxt;
}
}
}
cout << "No more Accounts" << endl;

}

void DisplayAccounts()
{
using namespace std;

AccountNode *temp;
temp = Accountstart_ptr;
cout << endl;
if (temp == NULL)
{
cout << "No Customers" << endl;
}
else
{
while (temp != NULL)
{
temp->New.PrintAccount();
temp = temp->nxt;
}
}
cout << "No more Accounts" << endl;

}

void AddCustomer(int& iID)
{
using namespace std;


CustomerNode *temp, *temp2;

temp = new CustomerNode;
temp->New.AddNewCustomer();
temp->New.iCustomerID = ++iID;
temp->nxt = NULL;
cout << "\nCustomer Added!" << endl;

if (Customerstart_ptr == NULL)
{
Customerstart_ptr = temp;
Customercurrent = Customerstart_ptr;
}
else
{
temp2 = Customerstart_ptr;
while(temp2->nxt != NULL)
{
temp2 = temp2->nxt;
}
temp2->nxt = temp;
}
}

void DisplayCustomers()
{
using namespace std;

CustomerNode *temp;
temp = Customerstart_ptr;
cout << endl;
if (temp == NULL)
{
cout << "No Customers" << endl;
}
else
{
while (temp != NULL)
{
temp->New.ShowPersonDetails();
temp = temp->nxt;
}
cout << "No more customers" << endl;
}


}

void UpdateCustomer()
{
using namespace std;

int iCustomerID;

CustomerNode *temp;
temp = Customerstart_ptr;
cout << "Enter Customer ID for Editing: " << endl;
cin >> iCustomerID;

while (temp != NULL)
{
if (temp->New.iCustomerID == iCustomerID)
{
temp->New.UpdatePersonDetails();
}
temp = temp->nxt;
}
}

void TransferMoney()
{
using namespace std;

time_t now = time(0);
tm* localtm = localtime(&now);

AccountNode *temp, *temp2;
temp = Accountstart_ptr;
temp2 = Accountstart_ptr;

int iAccountFrom, iAccountTo, iAmmount;
cout << "Enter amount to be transfered: ";
cin >> iAmmount;
cout << "Enter Account ID to transfer money from: ";
cin >> iAccountFrom;

while (temp != NULL)
{
if (temp->New.iAccountNumber == iAccountFrom && temp->New.iBalance - iAmmount >= 0)
{
cout << "Enter Account ID to transfer money to: ";
cin >> iAccountTo;

while (temp2 != NULL)
{
if (temp2->New.iAccountNumber == iAccountTo)
{
temp->New.iBalance -= iAmmount;
temp2->New.iBalance += iAmmount;
cout << "MONEY TRANSFERED" << endl;
myfile << "\n~~~~~~Transferal~~~~~~" << endl;
myfile << "Time and Date: " << asctime(localtm);
myfile << "Account ID from:" << iAccountFrom << endl;
myfile << "Account ID to:" << iAccountTo << endl;
myfile << "Transfered: " << iAmmount << endl;
}
temp2 = temp2->nxt;
}
}
temp = temp->nxt;
}
}

void DepositMoney()
{
using namespace std;

time_t now = time(0);
tm* localtm = localtime(&now);

AccountNode *temp;
temp = Accountstart_ptr;

int iAmmount, iAccountID;

if (temp == NULL)
{
cout << "No Accounts" << endl;
}
else
{
cout << "Enter Account ID to deposit to: ";
cin >> iAccountID;
while (temp != NULL)
{
if (temp->New.iAccountNumber == iAccountID)
{
cout << "Enter Ammount to deposit: ";
cin >> iAmmount;
temp->New.iBalance += iAmmount;
cout << "DEPOSITED" << endl;
myfile << "\n~~~~~~DEPOSIT~~~~~~" << endl;
myfile << "Time and Date: " << asctime(localtm);
myfile << "Account ID:" << temp->New.iAccountNumber << endl;
myfile << "Deposited: " << iAmmount << endl;
}
temp = temp->nxt;
}
}
}

void WithdrawMoney()
{
using namespace std;

time_t now = time(0);
tm* localtm = localtime(&now);

AccountNode *temp;
temp = Accountstart_ptr;

int iAmmount, iAccountID;

if (temp == NULL)
{
cout << "No Accounts" << endl;
}
else
{
cout << "Enter Account ID to withdraw from: ";
cin >> iAccountID;
while (temp != NULL)
{
if (temp->New.iAccountNumber == iAccountID)
{
cout << "Enter Ammount to withdraw: ";
cin >> iAmmount;
if (temp->New.iBalance - iAmmount >= 0)
{
temp->New.iBalance -= iAmmount;
cout << "WITHDRAWN" << endl;
myfile << "\n~~~~~~Withdrawal~~~~~~" << endl;
myfile << "Time and Date: " << asctime(localtm);
myfile << "Account ID:" << temp->New.iAccountNumber << endl;
myfile << "Withdrawn: " << iAmmount << endl;
}
else
{
cout << "Not enough funds" << endl;
}
}
temp = temp->nxt;
}
}
}

void AddMortgage()
{
using namespace std;
int iAccountID;
long double iCostOfProperty;
long double iAmmountToPay, iAmmountToPay2;

AccountNode *temp;
temp = Accountstart_ptr;

if (temp == NULL)
{
cout << "No Accounts" << endl;
}
else
{
cout << "Enter Account ID to add mortgage to: ";
cin >> iAccountID;

if (temp->New.iAccountNumber == iAccountID)
{
temp->New.dInterestRate = 5;
cout << "Enter cost of property: ";
cin >> iCostOfProperty;
iAmmountToPay = iCostOfProperty *= 0.8;
cout << "Ammount to pay: " << iAmmountToPay << endl;
iAmmountToPay2 = iAmmountToPay;
iAmmountToPay2 *= 0.05;
iAmmountToPay += iAmmountToPay2;
cout << "Ammount to pay plus interest: " << iAmmountToPay;
temp->New.bMortgage = iAmmountToPay;
}
}
}

void DeleteAccount()
{
int iAccountID;

AccountNode *temp, *temp2;
temp = Accountstart_ptr;

if (temp == NULL)
{
std::cout << "No Accounts" << std::endl;
}
else
{
std::cout << "Enter Account ID for deletion: ";
std::cin >> iAccountID;
if(temp->nxt == NULL && temp->New.iAccountNumber == iAccountID)
{
Accountstart_ptr = NULL;
std::cout << "\nAccount Deleted!" << std::endl;
}
else if(temp->nxt != NULL && temp->New.iAccountNumber == iAccountID)
{
temp2 = temp->nxt;
*temp = *temp2;
std::cout << "\nAccount Deleted!" << std::endl;
}

else
{
int iCount = 0;
while (temp != NULL)
{
if (temp->New.iAccountNumber == iAccountID)
{
if (temp->nxt == NULL)
{
temp2 = Accountstart_ptr;
iCount--;
for (int i = 0; i < iCount; i++)
{
temp2 = temp2->nxt;
std::cout << temp2->New.iAccountNumber;
}
temp = temp2;
temp->nxt = NULL;
std::cout << "\nAccount Deleted!" << std::endl;
}
else
{
temp2 = temp->nxt;
*temp = *temp2;
std::cout << "\nAccount Deleted!" << std::endl;
}
}
iCount++;
temp = temp->nxt;
}
}
}
}

void DeleteCustomer()
{
int iCustomerID;

CustomerNode *temp, *temp2;
temp = Customerstart_ptr;

if (temp == NULL)
{
std::cout << "No Customers" << std::endl;
}
else
{
std::cout << "Enter Customer ID for deletion: ";
std::cin >> iCustomerID;
if(temp->nxt == NULL && temp->New.iCustomerID == iCustomerID)
{
Customerstart_ptr = NULL;
std::cout << "\nCustomer removed from system" << std::endl;
}
else if(temp->nxt != NULL && temp->New.iCustomerID == iCustomerID)
{
temp2 = temp->nxt;
*temp = *temp2;
std::cout << "\nCustomer removed from system" << std::endl;
}

else
{
int iCount = 0;
while (temp != NULL)
{
if (temp->New.iCustomerID == iCustomerID)
{
if (temp->nxt == NULL)
{
temp2 = Customerstart_ptr;
iCount--;
for (int i = 0; i < iCount; i++)
{
temp2 = temp2->nxt;
std::cout << temp2->New.iCustomerID;
}
temp = temp2;
temp->nxt = NULL;
std::cout << "\nCustomer removed from system" << std::endl;
}
else
{
temp2 = temp->nxt;
*temp = *temp2;
std::cout << "\nCustomer removed from system" << std::endl;
}
}
iCount++;
temp = temp->nxt;
}
}
}
}



int main()
{
using namespace std;
myfile.open ("TransactionLog.txt");
int iChoice, iChoice2, iChoice3, iChoice4;
int iID = 0;
int iAID = 0;

do
{
cout << endl;
cout << "Please selecet and option: " << endl;
cout << "0. Exit." << endl;
cout << "1. Customer Options." << endl;
cout << "2. Account Options." << endl;
cout << "3. Transaction Options." << endl;
cout << endl;
cin >> iChoice;

switch (iChoice)
{
case 1 : do
{
cout << endl;
cout << "0. Exit" << endl;
cout << "1. Add Customer" << endl;
cout << "2. Print Customers" << endl;
cout << "3. Update Customer" << endl;
cout << "4. Add Account" << endl;
cout << "5. Delete Customer" << endl;
cin >> iChoice2;

switch (iChoice2)
{
case 1 : AddCustomer(iID); break;
case 2 : DisplayCustomers(); break;
case 3 : UpdateCustomer(); break;
case 4 : AddAccount(iAID); break;
case 5 : DeleteCustomer(); break;
}
}while (iChoice2 != 0); break;

case 2 : do
{
cout << endl;
cout << "0. Exit" << endl;
cout << "1. Add Account" << endl;
cout << "2. Print All Accounts" << endl;
cout << "3. Print Accounts of Customer" << endl;
cout << "4. List Accounts and Balances" << endl;
cout << "5. Delete Account" << endl;
cout << "6. Add Mortgage" << endl;
cin >> iChoice3;

switch (iChoice3)
{
case 1 : AddAccount(iAID); break;
case 2 : DisplayAccounts(); break;
case 3 : DisplayCustomerAccounts(); break;
case 4 : ListAccountsAndBalances(iID, iAID); break;
case 5 : DeleteAccount(); break;
case 6 : AddMortgage(); break;
}
}while (iChoice3 != 0); break;

case 3 : do
{
cout << endl;
cout << "0. Exit" << endl;
cout << "1. Transfer Money" << endl;
cout << "2. Deposit Money" << endl;
cout << "3. Withdraw Money" << endl;
cin >> iChoice4;

switch (iChoice4)
{
case 1 : TransferMoney(); break;
case 2 : DepositMoney(); break;
case 3 : WithdrawMoney(); break;
}
}while (iChoice4 != 0); break;
}
}while (iChoice != 0);

myfile.close();
}

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum