Thursday, December 12, 2019

Bank System Operations Use Dynamic Arrays

Question: Describe about the Bank System Operations for Use Dynamic Arrays. Answer: Introduction: The project is regarding bank system operations. Normally any bank maintains the accounts of all persons and do operations on them like creating account and deleting account, depositing money into account, withdraw money from account. Like this many operations can be provided. Needs to main the accounts as lists and each account is unique with last name and account type. One person can have many accounts with different account types. Each account given one unique account number and do operations based on the account number. Every operation requires the account number. Software Development Process: Initially build the menu options so that user can choose the respective operations. For repeating the operations used while loop like this below. Used below snippet of code for building this. while(1){ cout "n"; displayMenu(); cout "Enter Choice: "; cin choice; if(choice == 8) break; switch(choice){ case 1: cout "create accountn"; break; case 2: cout "update account addressn"; break; case 3: cout "update account typen"; break; case 4: cout "display all accounts of customern"; break; case 5: cout "deposit money into accountn"; break; case 6: cout "withdraw money into accountn"; break; case 7: cout "display accounts into ascending ordern"; break; default: break; } } Below is the testing screen shot of this. Used Arrays for holding the details of accounts, each account is like on object. Developed the create account option, in this asking the details of account and generate the account number using one increament counter. After filling the details of account add this into list of accounts. Below is code snippet for this. void createAccount(){ string firstName; string lastName; string address; int accountType; cout "n"; cout "Enter First Name: "; cin firstName; cout "Enter Last Name: "; cin lastName; cout "Enter Address: "; cin address; cout "Enter Account Type(CURRENT/SAVINGS/BUSINESS, 1/2/3): "; cin accountType; if(searchByLastName(lastName, accountType) != -1){ cout "Last Name: " lastName " With Account Type: " convertAccountTypeToString(accountType) " Already Existedn"; cout "n"; return; } A_List[num_accounts] = new BankAccount(firstName, lastName, inc_account_number, address, accountType); inc_account_number++; num_accounts++; cout "n"; } Developed the code for displaying the details of accounts of one person. First ask the account holder lastname and find the accounts with lastname and display all of them. Code snippet is below for this. void displayAllAccountsOfCustomer(){ int i; string lastName; cout "n"; cout "Enter Customer Last Name: "; cin lastName; cout "n"; printf("t%-20st%-20st%-15st%-20st%-10st%-15sn", "FirstName", "LastName", "AccountNumber", "Address" ,"Balance","AccountType"); printf("t===================================================================================n"); for(i=0; inum_accounts; i++){ if(A_List[i]-getLastName().compare(lastName) == 0){ printf("t%-20s", A_List[i]-getFirstName().data()); printf("t%-20s", A_List[i]-getLastName().data()); printf("t%-15d", A_List[i]-getAccountNumber()); printf("t%-20s", A_List[i]-getAddress().data()); printf("t%-8.2f", A_List[i]-getAccountBalance()); printf("t%-15sn", convertAccountTypeToString(A_List[i]-getAccountType())); } } cout "n"; } Testing of these two pahse is below screen shot. Update the Account address and account type. Here first asked the account number and changes the respective one based on the given input. If the account is not found show error otherwise do the respective operation. The code snippet is below for this. void updateAccountAddress(){ string address; int accountNumber; int index; cout "n"; cout "Enter Account Number: "; cin accountNumber; index = searchByAccountNumber(accountNumber); if(index == -1){ cout "Account Number: " accountNumber " Does Not Existn"; cout "n"; return; } cout "Enter Address: "; cin address; A_List[index]-setAddress(address); cout "n"; } void updateAccountType(){ int accountNumber; int index; int accountType; cout "n"; cout "Enter Account Number: "; cin accountNumber; index = searchByAccountNumber(accountNumber); if(index == -1){ cout "Account Number: " accountNumber " Does Not Existn"; cout "n"; } cout "Enter Account Type(CURRENT/SAVINGS/BUSINESS, 1/2/3): "; cin accountType; A_List[index]-setAccountType(accountType); cout "n"; } The testing of these two operations is below. The screen shot showing the operations of these. Now deposit and withdraw of money from account. Request for the account number and do the respective operations. If account number not found print error otherwise do the operation. Below is the code snippet. void depositMoneyIntoAccount(){ int accountNumber; int index; double balance; cout "n"; cout "Enter Account Number: "; cin accountNumber; index = searchByAccountNumber(accountNumber); if(index == -1){ cout "Account Number: " accountNumber " Does Not Existn"; cout "n"; return; } cout "Enter The Amount: "; cin balance; balance += A_List[index]-getAccountBalance(); A_List[index]-setAccountBalance(balance); cout "n"; } void withdrawMoneyIntoAccount(){ int accountNumber; int index; double balance; cout "n"; cout "Enter Account Number: "; cin accountNumber; index = searchByAccountNumber(accountNumber); if(index == -1){ cout "Account Number: " accountNumber " Does Not Existn"; cout "n"; return; } cout "Enter The Amount: "; cin balance; balance = A_List[index]-getAccountBalance()-balance; if(balance 0){ printf("You Can't Withdraw Amount More than: %5.2fn", A_List[index]-getAccountBalance()); return; } A_List[index]-setAccountBalance(balance); cout "n"; } Testing Screen shots of this. Self Reflection: Initally for the storing the values of each account choosed class structure instead of structure for that i read about classes and it's get and setter methods and constructor forming. After created this class studied about arrays to store these list of account objects. Now i am comfortable in maintain the arrays of accounts and account object. Now i am easily do the account creation and and changing the address and type of accounts. Now it becomes easy to deposit money and withdraw money from and to account. It is all just operations in the account. Conclusion: Instead of arrays it is better to use dynamic arrays list and dynamic linkedlist for stoeinf the accounts as number of accounts can grow to any extent to it is better to use the unlimted data structures for this. Referrences: https://www.cplusplus.com/doc/tutorial/classes/ https://www.cplusplus.com/doc/tutorial/arrays/

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.