Question

In: Computer Science

Bank Linked List Project: Create a bank linked list project program to mimic a simple bank...

Bank Linked List Project:
Create a bank linked list project program to mimic a simple bank account system (open account, deposit, withdraw, loans etc.).
Requirements:
1. Use linked list (queues and/or stacks)
2. Classes
3. Arrays
4. Add, delete, remove, search methods

(use Dev. C++ to create the program)

Solutions

Expert Solution

#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

// Class Bank definition
class Bank
{
public:
// Data member to store data
string name;
string accountNumber;
double balance;
// Pointer to point to next node
Bank *next;

};// End of class

// Declares a start pointer and assigns null to it
Bank *start = NULL;

// Function to accept data
void accept(Bank *ptr)
{
cout<<"\n Enter the name: ";
cin>>ptr->name;
cout<<"\n Enter the account number: ";
cin>>ptr->accountNumber;
cout<<"\n Enter initial balance: ";
cin>>ptr->balance;
}// End of function

// Function to display information
void displayAccounts()
{
// Creates a temporary pointer
Bank *ptr;
// Checks if start is null then list is empty
if(start == NULL)
{
cout<<"\nList is empty:\n";
return;
}// End of if condition
else
{
// Points to starting account
ptr = start;
cout<<"\n Accounts Information \n";
// Loops till end of the list
while(ptr != NULL)
{
cout<<"\n Name: "<<ptr->name<<"\t Account Number: "<<ptr->accountNumber
<<"\t Balance: "<<ptr->balance;
// Move to next account
ptr=ptr->next ;
}// End of while loop
}// End of else
}// End of function

// Function to display parameter node information
void displayAccount(Bank *ptr)
{
cout<<"\n Name: "<<ptr->name<<"\t Account Number: "<<ptr->accountNumber<<"\t Balance: "<<ptr->balance;
}// End of function

// Function to search an account
int Search(string accNo)
{
int position = -1, counter = 0;
// Creates a temporary pointers
Bank *ptr;
// Checks if start is null then list is empty
if(start==NULL)
{
cout<<"\nThe List is Empty:\n";
exit(0);
}// End of if condition

// Otherwise
else
{
// Points to starting account
ptr = start;
// Loops till end of the list
while(ptr != NULL)
{
// Checks if current account number is equals to parameter account number
if(ptr->accountNumber.compare(accNo) == 0)
{
cout<<"\n Account details \n";
// Calls the function to display found account information
displayAccount(ptr);
// Assigns the found position
position = counter;
// Returns the position
return counter;
}// End of if condition
// Move to next account
ptr=ptr->next ;
// Increase the record counter
counter++;
}// End of while loop
}// End of else

// Checks if found position is -1 account not found
if(position == -1)
cout<<"\n Account not available.";
// returns the position
return position;
}// End of function

// Function to add an account number
void addAccount()
{
// Creates a temporary pointer
Bank *temp = new Bank();

// Checks if temp is null then list is full
if(temp==NULL)
{
cout<<"\nOut of Memory Space:\n";
return;
}// End of if condition
// Calls the function accept data for node temp
accept(temp);
// Assigns null to temp next
temp->next = NULL;
// Checks if the start is NULL then it is the first node to insert
if(start == NULL)
{
// temp address is assigned to start
start = temp;
}// End of if condition
// Otherwise
else
{
// start address is assigned to temp next
temp->next = start;
// temp address is assigned to start
start = temp;
}// End of else
}// End of function

// Function to delete a node at specified position
void deleteAccount()
{
int position;
string accNo;
// Creates a temporary pointer
Bank *temp,*ptr;
// Checks if start is null then list is empty
if(start==NULL)
{
cout<<"\nThe List is Empty:\n";
exit(0);
}// End of if condition
// Otherwise
else
{
// Accepts the account number
cout<<"\nEnter the account number: \t";
cin>>accNo;
// Calls the function to search the account number
// Stores the returned found position
position = Search(accNo);

// Checks if found position is -1 account not found
if(position == -1)
{
cout<<"\n No such account number: "<<accNo;
return;
}// End of if condition

// Checks if the position is zero
if(position == 0)
{
// Temporary pointer points start
ptr = start;
// Start pointing to next node
start = start->next;
cout<<"\nThe deleted account is: ";
// Calls the function to display the deleted account information
displayAccount(ptr);
// Deletes the pointer
free(ptr);
}// End of if condition

// Otherwise
else
{
// Temporary pointer points start
ptr = start;

// Loops till record found position
for(int c = 0; c < position; c++)
{
// temporary pointer pointing to previous node ptr
temp = ptr;
// Move to next account
ptr = ptr->next;

// Checks if ptr is null node not found
if(ptr == NULL)
{
cout<<"\nAccount not Found:\n";
return;
}// End of if condition
}// End of for loop
temp->next = ptr->next ;
cout<<"\n The deleted account:";
// Calls the function to display deleted account information
displayAccount(ptr);
// Deletes the account
free(ptr);
}// End of inner else
}// End of outer else
}// End of function

// Function to perform deposit operation
void deposit(string accNo)
{
int c, position = -1;
double amount;
// Creates a temporary pointers
Bank *temp,*ptr;
// Checks if start is null then list is empty
if(start==NULL)
{
cout<<"\nThe List is Empty:\n";
exit(0);
}// End of if condition
// Otherwise
else
{
// Temporary pointer points start
ptr = start;
c = 0;
// Loops till end of the list
while(ptr != NULL)
{
// Temporary pointer pointing to previous node ptr
temp = ptr;
// Compare the current node account number with the parameter accNo for equal
if(ptr->accountNumber.compare(accNo) == 0)
{
// Stores the found index position
position = c;
break;
}// End of if condition
// Move to next account
ptr = ptr->next;
// Increase the index counter by one
c++;
}// End of while loop
// Checks if the position is -1 not found
if(position == -1)
cout<<"\n Account not found:";
// Otherwise checks if the position is zero then starting node
else if(position == 0)
{
ptr = start;
// Accepts the deposit amount
cout<<"\n Enter the deposit amount: ";
cin>>amount;

// Checks if deposit amount is negative display error message
if(amount < 0)
{
cout<<"\n Invalid amount.";
return;
}// End of if condition

// Otherwise valid amount
else
// Increases the balance by amount
ptr->balance += amount;
}// End of else if condition

// Otherwise
else
{
// Temporary pointer points start
ptr = start;
// Loops up to entered position
for(c = 0; c < position; c++)
{
// Temporary pointer pointing to previous node ptr
temp = ptr;
// Move to next account
ptr = ptr->next;
// Checks if ptr is null node not found
if(ptr == NULL)
{
cout<<"\nAccount not found:\n";
return;
}// End of if condition
}// End of for loop
// Accept the deposit amount
cout<<"\n Enter the deposit amount: ";
cin>>amount;

// Checks if deposit amount is negative display error message
if(amount < 0)
{
cout<<"\n Invalid amount.";
return;
}// End of if condition

// Otherwise valid amount
else
// Adds the amount to balance
ptr->balance += amount;
}// End of else
}// End of outer else
}// End of function

// Function to perform withdrawal operation
void withdraw(string accNo)
{
int c, position = -1;
double amount;
// Creates a temporary pointers
Bank *temp,*ptr;
// Checks if start is null then list is empty
if(start==NULL)
{
cout<<"\nThe List is Empty:\n";
exit(0);
}// End of if condition
// Otherwise
else
{
// Temporary pointer points start
ptr = start;
c = 0;
// Loops till end of the list
while(ptr != NULL)
{
// Temporary pointer pointing to previous node ptr
temp = ptr;
// Compare the current node account number with the parameter accNo for equal
if(ptr->accountNumber.compare(accNo) == 0)
{
// Stores the found index position
position = c;
break;
}// End of if condition
// Move to next account
ptr = ptr->next;
// Increase the index counter by one
c++;
}// End of while loop
// Checks if the position is -1 not found
if(position == -1)
cout<<"\n Account not found:";
// Otherwise checks if the position is zero then starting node
else if(position == 0)
{
// Points to the starting account
ptr = start;
// Accepts the withdrawal amount
cout<<"\n Enter the withdrawal amount: ";
cin>>amount;

// Checks if withdrawal amount is negative display the error message
if(amount < 0)
{
cout<<"\n Invalid amount.";
return;
}// End of if condition

// Otherwise checks withdrawal amount is greater than the current balance
// display error message
else if(amount > ptr->balance)
{
cout<<"\n Insufficient balance.";
return;
}// End of else if condition

// Otherwise valid withdrawal amount
else
// Subtracts the amount from current balance
ptr->balance -= amount;
}// End of else if condition
// Otherwise
else
{
// Temporary pointer points start
ptr = start;
// Loops up to entered position
for(c = 0; c < position; c++)
{
// temporary pointer pointing to previous node ptr
temp = ptr;
// Move to next node
ptr = ptr->next;
// Checks if ptr is null node not found
if(ptr == NULL)
{
cout<<"\nAccount not found:\n";
return;
}// End of if condition
}// End of for loop

// Accepts the withdrawal amount
cout<<"\n Enter the withdrawal amount: ";
cin>>amount;

// Checks if withdrawal amount is negative display the error message
if(amount < 0)
{
cout<<"\n Invalid amount.";
return;
}// End of if condition

// Otherwise checks withdrawal amount is greater than the current balance
// display error message
else if(amount > ptr->balance)
{
cout<<"\n Insufficient balance.";
return;
}// End of else if condition

// Otherwise valid withdrawal amount
else
// Subtracts the amount from current balance
ptr->balance -= amount;
}// End of else
}// End of outer else
}// End of function

// Function to display user choice and return user choice
int menu()
{
// To store user choice
int choice;
// Displays menu
cout<<"\n ************ Bank Account ************ \n";
cout<<"\n MENU \n";
cout<<"---------------------------------------\n";
cout<<"\n 1. Add account.";
cout<<"\n 2. Delete account.";
cout<<"\n 3. Search account.";
cout<<"\n 4. Display all accounts.";
cout<<"\n 5. Deposit.";
cout<<"\n 6. Withdrawal.";
cout<<"\n 7. Quit";
cout<<"\n--------------------------------------\n";
// Accepts user choice
cout<<"Enter your choice:\t";
cin>>choice;
// returns user choice
return choice;
}// End of function

// main function definition
int main()
{
string accNo;
// Loops till user choice is not 7
while(1)
{
// Calls the function to display menu.
// Calls the function as per user choice returned by the function
switch(menu())
{
case 1:
addAccount();
break;
case 2:
deleteAccount();
break;
case 3:
cout<<"\n Enter an account number to search: ";
cin>>accNo;
Search(accNo);
break;
case 4:
displayAccounts();
break;
case 5:
cout<<"\n Enter an account number to deposit: ";
cin>>accNo;
deposit(accNo);
break;
case 6:
cout<<"\n Enter an account number to withdrawal: ";
cin>>accNo;
withdraw(accNo);
break;
case 7:
exit(0);
default:
cout<<"\n Wrong Choice:\n";
}//end of switch - case
}// End of while loop
return 0;
}//end of main function

Sample Output:


************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

List is empty:

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 1

Enter the name: Mohan

Enter the account number: 111

Enter initial balance: 2000

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Mohan Account Number: 111 Balance: 2000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 1

Enter the name: Pyari

Enter the account number: 222

Enter initial balance: 78000

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Pyari Account Number: 222 Balance: 78000
Name: Mohan Account Number: 111 Balance: 2000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 1

Enter the name: Ram

Enter the account number: 12000

Enter initial balance: 3000

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 3

Enter an account number to search: 555

Account not available.
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 3

Enter an account number to search: 111

Account details

Name: Mohan Account Number: 111 Balance: 2000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 5

Enter an account number to deposit: 444

Account not found:
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 5

Enter an account number to deposit: 222

Enter the deposit amount: 4000

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Ram Account Number: 12000 Balance: 3000
Name: Pyari Account Number: 222 Balance: 82000
Name: Mohan Account Number: 111 Balance: 2000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 5

Enter an account number to deposit: 111

Enter the deposit amount: -10000

Invalid amount.
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 5

Enter an account number to deposit: 111

Enter the deposit amount: 10000

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Ram Account Number: 12000 Balance: 3000
Name: Pyari Account Number: 222 Balance: 82000
Name: Mohan Account Number: 111 Balance: 12000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 6

Enter an account number to withdrawal: 12000

Enter the withdrawal amount: -10

Invalid amount.
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 6

Enter an account number to withdrawal: 12000

Enter the withdrawal amount: 6000

Insufficient balance.
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 6

Enter an account number to withdrawal: 12000

Enter the withdrawal amount: 500

************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Ram Account Number: 12000 Balance: 2500
Name: Pyari Account Number: 222 Balance: 82000
Name: Mohan Account Number: 111 Balance: 12000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 2

Enter the account number: 999

Account not available.
No such account number: 999
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 2

Enter the account number: 12000

Account details

Name: Ram Account Number: 12000 Balance: 2500
Position: 0
The deleted account is:
Name: Ram Account Number: 12000 Balance: 2500
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 4

Accounts Information

Name: Pyari Account Number: 222 Balance: 82000
Name: Mohan Account Number: 111 Balance: 12000
************ Bank Account ************

MENU
---------------------------------------

1. Add account.
2. Delete account.
3. Search account.
4. Display all accounts.
5. Deposit.
6. Withdrawal.
7. Quit
--------------------------------------
Enter your choice: 7


Related Solutions

1) a. Write down a C++ program which will create a list (simple linear linked list)...
1) a. Write down a C++ program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a gradepoint average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function...
Create a Linked List and conduct the following operations. Portion of the program is given. The...
Create a Linked List and conduct the following operations. Portion of the program is given. The operations are: Add an “H” to the list Add an “I” to the list Add 100 to the list Print the content of the list and its size Add a “H” to the first place of the list Add a “R” to the last place of the list Get the element of position 3 and print it Get the last element and print it...
Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given....
**JAVA** Create a Linked List and conduct the following operations. Portion of the program is given. The operations are: Add an “H” to the list Add an “I” to the list Add “100” to the list Print the content of the list and its size Add a “H” to the first place of the list Add a “R” to the last place of the list Get the element of position 3 and print it Get the last element and print...
Introduction: In this project you will create a generic linked list using Java Generics. Description: Create...
Introduction: In this project you will create a generic linked list using Java Generics. Description: Create a generic class called GenLinkedList. GenLinkedList will use nodes that store a value of the generic type to store its contents. It should have the following methods. The methods should all operate on the object making the call (none are static). Perform checking of the parameters and throw exceptions where appropriate. The linked list should be singly-linked. It should not use sentinel nodes (empty...
Write a program where you- 1. Create a class to implement "Double Linked List" of integers....
Write a program where you- 1. Create a class to implement "Double Linked List" of integers. (10) 2. Create the list and print the list in forward and reverse directions. (10)
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
C++ Write a program to create a linked list which stores the details of employees(Employee number,...
C++ Write a program to create a linked list which stores the details of employees(Employee number, employee name, rate, hours worked). Create a menu to manage the emoployee data. MENU 1. ADD EMPLOYEE DETAILS 2. DELETE EMPLOYEE 3. SEARCH EMPLOYEE 4. PRINT EMPLOYEE PAYROLL 5. EXIT When the user selected option #4 the program should print the following pay report for each employee: EmpNo.     Name      Rate    Hours    Regular Pay      Overtime Pay     Gross Pay Any hours worked above 40 hours are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT