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.
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
#include
#include
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 < 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: "< inData.close(); inData.clear(); //read from file and display to screen int i, counter = 0; inData.open("clients.dat"); cout <<"ACC\tName\tCH\tSV "; while (! inData.eof()){cout < for (int i = 0; i < 4; i++) {inData >> data;cout < 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 <<"\tClient Information: "<<"\t================== "<<"\tName: "< 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 <<"\t\tMAIN BANKING MENU "<<"\t\t================= "<<"\t\t1. Add NEW clients "<<"\t\t2. Transactions on clients accounts "<<"\t\t3. Show Report "<<"\t\t4. EXIT "<<"\tEnter 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 < outData.close();} break; case 3://View all clients dbClients = viewAllClients(); break; case 4: cout <<"Goodbye! "; break; default: cout <
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
