96.8k views
4 votes
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

User Frevd
by
5.0k points

1 Answer

0 votes

Answer:

See explaination

Step-by-step explanation:

#include <iostream>

#include <fstream>

#include <cstdlib>

#include <string>

using namespace std;

int read_accts(int an[], double bal[], int max_accts)

{

int num=0;

ifstream myfile;

myfile.open("bankdata.txt");

if (!myfile)

{

cout << "Can't open input file bankdata.txt " << endl;

exit(1);

}

myfile >> an[num] >> bal[num];

//While I haven't tried to read past the end of file

while(!myfile.eof())

{

num++;

if (num == max_accts)

break;

myfile >> an[num] >> bal[num];

}

return num;

}

int findacct(int an[], int num, int acct)

{

for (int i=0; i<num; i++)

if (an[i]==acct)

return i;

return -1;

}

void withdrawal(int an[], double bal[], int num)

{

int index, account;

double amt;

cout << endl;

cout << "Enter the account number" << endl;

cin >> account;

index = findacct(an,num,account);

if (index < 0)

cout << "Error : account not found : " << account << endl;

else

{

cout << "Enter the withdrawal amount" << endl;

cin >> amt;

if (bal[index] < amt)

cout << "Insufficient funds" << endl;

else

{

bal[index] = bal[index] - amt;

cout << "Withdrawl successful and your new balance is " <<

bal[index] <<endl;

}

}

}

void print_accts(int an[], double bal[], int num)

{

cout << endl;

cout<<"Here are the accounts " << endl;

for (int i =0; i<num; i++)

cout << "Acct: " << an[i] << " Balance "

<< bal[i] << endl;

}

void deposit(int an[], double bal[], int num)

{

cout << endl;

cout<<"called Deposit " << endl;

}

void balance(int an[], double bal[], int num)

{

cout << endl;

cout<<"called Balance " << endl;

}

void new_acct(int an[], double bal[], int &num)

{

cout << endl;

cout<<"called New Account " << endl;

}

void menu()

{

cout << "W - Withdrawal" << endl;

cout << "D - Deposit" << endl;

cout << "N - New account" << endl;

cout <<"B - Balance" << endl;

cout <<"Q - Quit" << endl;

cout <<"X - Delete Account" << endl;

cout <<"Please make your selection: " << endl;

}

/***************************************************/

/* program to maintain a set of bank accounts */

/***************************************************/

int main()

{

const int MAX_NUM=100;

int acctnum_array[MAX_NUM];

double balance_array[MAX_NUM];

int num_accts = 0;

char selection='Z';

num_accts = read_accts(acctnum_array,balance_array,MAX_NUM);

print_accts(acctnum_array, balance_array, num_accts);

cout << endl;

while (selection!='Q' && selection!='q')

{

menu();

cin >> selection;

switch(selection)

{

case 'W' :

case 'w':

withdrawal(acctnum_array, balance_array, num_accts);

break;

case 'D' :

case 'd':

deposit(acctnum_array, balance_array, num_accts);

break;

case 'N' :

case 'n':

new_acct(acctnum_array, balance_array, num_accts);

break;

case 'B' :

case 'b':

balance(acctnum_array, balance_array, num_accts);

break;

case 'Q' :

case 'q':

print_accts(acctnum_array, balance_array, num_accts);

break;

default :

cout << "Invalid selection" << endl;

}

cout << endl;

}

cout << "Done" << endl;

return 0;

}

User Bookcasey
by
5.1k points