You have been hired as a programmer by a major bank. Your first project is a sma
ID: 3694219 • Letter: Y
Question
You have been hired as a programmer by a major bank. Your first project is a small banking transaction system. Each account consists of a number and a balance. The user of the program (the teller) can create a new account, as well as perform deposits, withdrawals, and balance inquiries.
Initially, the account information of existing customers is to be read into a pair of parallel arrays--one for account numbers, the other for balances.
The bank can handle up to MAX_NUM accounts. Use the following function to read in the data values:
int read_accts(int acctnum_array[], double balance_array[], int max_accts);
This function fills up the account number and balance arrays (up to max_accts) and returns the actual number of accounts read in (later referred to as num_accts).
After initialization, print the initial database of accounts and balances. Use function print_accts() described below.
The program then allows the user to select from the following menu of transactions:
Select one of the following:
W - Withdrawal
D - Deposit
N - New account
B - Balance
Q – Quit
X – Delete Account – Extra Credit
Use the following function to produce the menu:
void menu();
This function only displays the menu. The main program then prompts the user for a selection.
You should verify that the user has typed in a valid selection (otherwise print out an error message and repeat the prompt). Once the user has entered a selection, one of the following functions should be called to perform the specific transaction.
At the end, before the user quits, the program prints the contents of the account arrays.
int findacct(int acctnum_array[], int num_accts, int account);
This function returns the index of account in account_array if the account exists, and -1 if it doesn't. It is called by all the remaining functions.
void withdrawal(int acctnum_array[], double balance_array[], int num_accts);
This function prompts the user for the account number. If the account does not exist, it prints an error message. Otherwise, it asks the user for the amount of the withdrawal. If the account does not contain sufficient funds, an it prints an error message and does not perform the transaction.
void deposit(int acctnum_array[], double balance_array[], int num_accts);
This function prompts the user for the account number. If the account does not exist, it prints an error message. Otherwise, it asks the user for the amount of the deposit.
int new_acct(int acctnum_array[], double balance_array[], int num_accts);
This function prompts the user for a new account number. If the account already exists, it prints an error message. Otherwise, it adds the account to the account array with an initial balance of 0. It returns the new number of accounts.
void balance(int acctnum_array[], double balance_array[], int num_accts);
This function prompts the user for an account number. If the account does not exist, it prints an error message. Otherwise, it prints the account balance.
void print_accts(int acctnum_array[], double balance_array[], int num_accts);
This function prints all customer information--account number and balance.
Explanation / Answer
//Please find below the required program for the Bank Transactions
#include <stdio.h>
#include<stdlib.h>
int read_accts(int *acctnum_array, double *balance_array, int max_accts)
{
int ch=1,i=0;
while(ch==1)
{
printf("Enter the account number and balance ");
scanf("%d %lf ",&acctnum_array[i],&balance_array[i]);
i++;
printf("Do you want to enter more data? 0 or 1? ");
scanf("%d ",&ch);
}
printf("After initialization, the initial database of accounts and balances are as follows: ");
print_accts(acctnum_array,balance_array,i-1);
return i-1;
}
void print_accts(int *acctnum_array, double *balance_array, int num_accts)
{
int i;
for(i=0;i<=num_accts;i++)
{
printf("%d %lf ",acctnum_array[i],balance_array[i]);
}
}
void menu() {
printf("W - Withdrawal D - Deposit N - New account B - Balance Q – Quit ");
}
int findacct(int *acctnum_array, int num_accts, int account)
{
int i,flag=0;
for(i=0;i<=num_accts;i++)
{
if(acctnum_array[i]==account)
{
flag=1;
break;
}
}
if(flag==1)
return i;
else
return -1;
}
void withdrawal(int *acctnum_array, double *balance_array, int num_accts)
{
int account,retval;
double wd_amt;
printf("Enter the account number for withdrawal ");
scanf("%d ",&account);
retval=findacct( acctnum_array, num_accts, account);
if(retval==-1)
{
printf("Error: The account doesnt exist ");
}
else
{
printf("Enter the amount for withdrawal ");
scanf("%lf ",&wd_amt);
if(balance_array[retval]<wd_amt)
{
printf("Insufficient funds ");
}
else
{
balance_array[retval]=balance_array[retval]-wd_amt;
}
}
}
void deposit(int *acctnum_array, double *balance_array, int num_accts)
{
int account,retval;
double deposit;
printf("Enter the account number for deposit ");
scanf("%d ",&account);
retval=findacct( acctnum_array, num_accts, account);
if(retval==-1)
{
printf("Error: The account doesnt exist ");
}
else
{
printf("Enter the amount for deposit ");
scanf("%lf ",&deposit);
balance_array[retval]=balance_array[retval]+deposit;
}
}
int new_acct(int *acctnum_array, double *balance_array, int num_accts)
{
int new_account,retval;
printf("Enter the new account number ");
scanf("%d ",&new_account);
retval=findacct( acctnum_array, num_accts, new_account);
if(retval==-1)
{
num_accts++;
acctnum_array[num_accts]=new_account;
balance_array[num_accts]=0;
}
else
{
printf("Error: The account already exists ");
}
return num_accts;
}
void balance(int *acctnum_array, double *balance_array, int num_accts)
{
int account,retval;
printf("Enter the account number to view balance ");
scanf("%d ",&account);
retval=findacct( acctnum_array, num_accts, account);
if(retval==-1)
{
printf("Error: The account doesnt exist ");
}
else
{
printf("The acount balance is %lf ",balance_array[account]);
}
}
int main() {
int MAX_NUM,num_accts;
int *acctnum_array;
double *balance_array;
char option;
printf("Enter the maximum number of accounts the bank can hold ");
scanf("%d ",&MAX_NUM);
acctnum_array=(int *)malloc(MAX_NUM*sizeof(int));
balance_array=(double *)malloc(MAX_NUM*sizeof(double));
num_accts=read_accts(acctnum_array,balance_array,MAX_NUM);
menu();
printf("Choose one option from the above menu ");
scanf("%c ",&option);
printf("The option choosen is %c ",option);
prompt: switch(option)
{
case 'W' : withdrawal(acctnum_array,balance_array, num_accts);
break;
case 'D':deposit( acctnum_array, balance_array, num_accts);
break;
case 'N':num_accts=new_acct( acctnum_array, balance_array, num_accts);
break;
case 'B' : balance( acctnum_array, balance_array, num_accts);
break;
case 'Q':
break;
default:printf("Choose a correct option from the above menu ");
scanf("%c ",&option);
goto prompt;
}
printf("At the end the database of accounts and balances are as follows: ");
print_accts(acctnum_array,balance_array,num_accts);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.