Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Banking Program Help: See the program requirements below. The parts in bold

ID: 3885865 • Letter: C

Question

C++ Banking Program Help: See the program requirements below. The parts in bold are the ones that I have no clue on how to do. Please see the code that I have written thus far below.

Title: Simple Banking Record

Learning objectives:

1. Use of functions

2. Use of loops and if statement

3. Use of arrays and pointers

Lab Objective: Part 1

Write a program that will be used by a bank clerk to create a client's account and will then allow the clerk to enter withdraws and deposits on that account. The program should offer the ability for the clerk to view the current balance on the account.

Sample run of the program:

At startup the clerk will get a menu:

MAIN MENU

==========

1. Add a client account

2. Apply transactions on the client account

3. View the balance

4. Exit

Enter your choice:_

If the clerk chooses option 1:

The program will ask to enter an account number and full name;

The program will then return to the main menu.

If the clerk chooses option 2:

The program must first check if the client exists. An appropriate error should display and the program goes back to the main menu.

If a client exists, the program will offer the choice of withdraw or deposit. The program must inspect the balance for overdraft.

If the clerk chooses option 3:

The program will display the account number, the full name and the balance.

Option: exit the program completely!

Part 2: A client can have more than one account. Typically a client would have a checking and a savings account. Rewrite another version of the previous program to accommodate for this feature.

Part 3: This new version of the program will have all of the above features in addition to the ability of applying them to several clients.

Part 4: Make the data persistent. In other words, save all client information for later retrieval.

#include<fstream>

#include<iostream>

#include<iomanip>

using namespace std;

struct client{string fname;

string lname;

double checking; //balance

double savings; //balance

};

void writeNewClients(client cl[], int size)

{ofstream outData;

outData.open("clients.dat", ios::app);

int i;

for (i   = 0;   i < size; i++)outData <<cl[i].fname<<" "<<cl[i].lname<<" "<<0.00<<" "<<0.00<<endl;

outData.close();}

int viewAllClients() //show all clients and return the number of records

{ifstream inData;

inData.open("clients.dat");

string data;

//find the number of   records in the file

int numRec = 0;

while (!   inData.eof())

{     inData >>data;

numRec++;}

numRec = (numRec -1)/4;

cout <<"Number of   records: "<<numRec<<endl; //TEST

inData.close();

inData.clear();

//read from file and display to screen

int i,   counter = 0;

inData.open("clients.dat");

cout <<"ACC Name CH SV ";

while (!   inData.eof()){cout <<counter<<" ";

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

{inData >>   data;cout <<data<<" ";}

counter++;cout <<" ";

if   (counter ==   numRec)

break;}

inData.close();

return numRec;}

void enterNewClients(client cl[], int size)

{int i;

for (i   = 0;   i < size; i++){cout <<"Full Name: ";cin >>cl[i].fname>>cl[i].lname;}}

void transactions(client &cl)

{int choice;

double amount;

system("CLS");

cout <<" Client Information: "<<" ================== "<<" Name: "<<cl.fname<<" "<<cl.lname<<" "<<" Checking Balance: $"<<fixed<<setprecision(2)<<cl.checking<<" "<<" Savings Balance: $"<<cl.savings<<" ";

do

{cout <<"Transaction Type "<<"================ "<<"1. Deposit to Checking "<<"2. Deposit to Savings "<<"3. Withdraw from Checking "<<"4. Withdraw from Savings "<<"5. Cancel Transaction "<<"Enter your choice: ";

cin >>   choice;}

while (choice < 1 ||   choice > 5);

switch(choice)

{case 1:cout <<"Enter a checking deposit amount: $";

cin >>amount;

cl.checking +=   amount;

break;

case 2:cout <<"Enter a savings deposit amount: $";

cin >>amount;

cl.savings += amount;

break;

case 3:cout <<"Enter a checking withdraw amount: $";

cin >>amount;

cl.checking -=   amount;

break;

case 4:cout <<"Enter a savings withdraw amount: $";

cin >>amount;

cl.savings -= amount;

break;}}

void loadBuffer(client cl[], int size)

{ifstream inData;

inData.open("clients.dat");

int i;

for (i   = 0;   i < size; i++)

{inData >>cl[i].fname;inData >>cl[i].lname;inData >>cl[i].checking;inData >>cl[i].savings;}

}

int menu()

{int choice;

cout <<" MAIN BANKING MENU "<<" ================= "<<" 1. Add NEW clients "<<" 2. Transactions on clients accounts "<<" 3. Show Report "<<" 4. EXIT "<<" Enter your choice: ";

cin >>choice;

return choice;}

int main()

{int option;

int nClients; //number of   new clients

int dbClients; //number of   clients in the file

int clientIndex; //client to be picked for editing

client cl[100];

int i,   j;

do

{system("CLS");

option = menu();

switch (option)

{case 1:   //data entry then save to   file in   append mode

cout <<"How many clients do   you want to   add?: ";

cin >>nClients;

enterNewClients(cl, nClients);

writeNewClients(cl, nClients);

break;

case 2:   //view all clients then choose a client to edit the sized

//buffer then rewrite the file completely

dbClients = viewAllClients();

cout <<"Pick an   ACC acount number for transactions: ";

cin >>   clientIndex;

//reload cl[] from file

loadBuffer(cl, dbClients);

//send the account to   be   edited

transactions(cl[clientIndex]);

//write to file

{ofstream outData;

outData.open("clients.dat");

for (i   = 0;   i < dbClients; i++)

outData <<cl[i].fname<<" "<<cl[i].lname<<" "<<cl[i].checking<<" "<<cl[i].savings<<endl;

outData.close();}

break;

case 3://View all clients

dbClients = viewAllClients();

break;

case 4:   cout <<"Goodbye! ";

break;

default: cout <<option<<" is an invalid option! ";}

system("PAUSE");}

while (option !=   4);

return 0;}

Explanation / Answer

HI,

The first option of taking input is already taken care of, kudos to that, to validate the client entered, i have added the condition below,

#include<fstream>

#include<iostream>

#include<iomanip>

using namespace std;

struct client{string fname;

string lname;

double checking; //balance

double savings; //balance

};

void writeNewClients(client cl[], int size)

{ofstream outData;

outData.open("clients.dat", ios::app);

int i;

for (i = 0; i < size; i++)outData <<cl[i].fname<<" "<<cl[i].lname<<" "<<0.00<<" "<<0.00<<endl;

outData.close();}

int viewAllClients() //show all clients and return the number of records

{ifstream inData;

inData.open("clients.dat");

string data;

//find the number of records in the file

int numRec = 0;

while (! inData.eof())

{ inData >>data;

numRec++;}

numRec = (numRec -1)/4;

cout <<"Number of records: "<<numRec<<endl; //TEST

inData.close();

inData.clear();

//read from file and display to screen

int i, counter = 0;

inData.open("clients.dat");

cout <<"ACC Name CH SV ";

while (! inData.eof()){cout <<counter<<" ";

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

{inData >> data;cout <<data<<" ";}

counter++;cout <<" ";

if (counter == numRec)

break;}

inData.close();

return numRec;}

void enterNewClients(client cl[], int size)

{

int i;

for (i = 0; i < size; i++)

{

cout <<"Full Name: ";cin >>cl[i].fname>>cl[i].lname;

}

}

void transactions(client &cl)

{int choice;

double amount;

system("CLS");

cout <<" Client Information: "<<" ================== "<<" Name: "<<cl.fname<<" "<<cl.lname<<" "<<" Checking Balance: $"<<fixed<<setprecision(2)<<cl.checking<<" "<<" Savings Balance: $"<<cl.savings<<" ";

do

{cout <<"Transaction Type "<<"================ "<<"1. Deposit to Checking "<<"2. Deposit to Savings "<<"3. Withdraw from Checking "<<"4. Withdraw from Savings "<<"5. Cancel Transaction "<<"Enter your choice: ";

cin >> choice;}

while (choice < 1 || choice > 5);

switch(choice)

{case 1:cout <<"Enter a checking deposit amount: $";

cin >>amount;

cl.checking += amount;

break;

case 2:cout <<"Enter a savings deposit amount: $";

cin >>amount;

cl.savings += amount;

break;

case 3:cout <<"Enter a checking withdraw amount: $";

cin >>amount;

cl.checking -= amount;

break;

case 4:cout <<"Enter a savings withdraw amount: $";

cin >>amount;

cl.savings -= amount;

break;}}

void loadBuffer(client cl[], int size)

{ifstream inData;

inData.open("clients.dat");

int i;

for (i = 0; i < size; i++)

{inData >>cl[i].fname;inData >>cl[i].lname;inData >>cl[i].checking;inData >>cl[i].savings;}

}

int menu()

{int choice;

cout <<" MAIN BANKING MENU "<<" ================= "<<" 1. Add NEW clients "<<" 2. Transactions on clients accounts "<<" 3. Show Report "<<" 4. EXIT "<<" Enter your choice: ";

cin >>choice;

return choice;}

int main()

{

int option;

int nClients; //number of new clients

int dbClients; //number of clients in the file

int clientIndex; //client to be picked for editing

client cl[100];

int i, j;

do

{system("CLS");

option = menu();

switch (option)

{case 1: //data entry then save to file in append mode

cout <<"How many clients do you want to add?: ";

cin >>nClients;

enterNewClients(cl, nClients);

writeNewClients(cl, nClients);

break;

case 2: //view all clients then choose a client to edit the sized

//buffer then rewrite the file completely

dbClients = viewAllClients();

cout <<"Pick an ACC acount number for transactions: ";

cin >> clientIndex;

if(clientIndex>dbClients) //checking if the index entered is valid client account

{

cout<<"invalid client entered";

break;

}

//reload cl[] from file

loadBuffer(cl, dbClients);

//send the account to be edited

transactions(cl[clientIndex]);

//write to file

{ofstream outData;

outData.open("clients.dat");

for (i = 0; i < dbClients; i++)

outData <<cl[i].fname<<" "<<cl[i].lname<<" "<<cl[i].checking<<" "<<cl[i].savings<<endl;

outData.close();}

break;

case 3://View all clients

dbClients = viewAllClients();

break;

case 4: cout <<"Goodbye! ";

break;

default: cout <<option<<" is an invalid option! ";}

system("PAUSE");}

while (option != 4);

return 0;

}

Thumbs up if this was helpful, otherwise let me know in comments.