Question

Description For this assignment, you will maintain an array of bank accounts. You will declare a...

Description For this assignment, you will maintain an array of bank accounts. You will declare a struct type called bankAcct and have an array of bankAcct with maximum size of 20, the members of the struct are shown below struct

bankAcct { string first , last ; double amount ; long acctNo ; short pin ; };

Each member is described below

• string first stores the user’s first name • string last stores the user’s last name

• double amount stores the user’s current balance

• long acctNo stores the user’s 7 digit bank account number

• short pin stores the user’s 4 digit PIN A text file will be given, and your program will read the text file and populate the array of bankAcct objects.

The number of lines will be no greater than 20. Each line will contain the following data in the following order: FirstName LastName BankAccount PIN Balance. Each line will be terminated by an end of line character. You will need to write the following functions

• int storeInfo(bankAcct[], ifstream&) - this function takes in the array of bank accounts and an input file stream variable, this will read through the file and populate the array and returns an integer denoting the amount of bank accounts read from the file

• void sort(bankAcct[], int) - this function will sort the array of bank accounts with respect to their account numbers, the integer passed in is the amount of accounts (the value returned from the storeInfo function) 1

• int search(bankAcct[], int, long) - this function takes in the array of bank accounts, the amount of bank accounts, and the bank account number to search for (in the array of bank accounts), an integer is returned which is the index of the bankAcct array whose account number matches the long parameter, if no such account exists, then a -1 is returned, this function will perform a binary search.

• void outputAndHandleRequest(bankAcct&) - this function takes in an account object (found using the search function), and it will output the bank account info (last name, first name, account number and current balance), you may need to use output manipulators for this, and then it will ask the user whether they want to deposit or withdraw, then will ask for an amount and will update the account accordingly

You cannot modify the function return types or the parameters, you need to design your main with these functions in mind, so for example, you need to sort the array before you can perform binary search. Another tip to get you started, user is prompted for the bank account number in main, then call the search function to get an index and based on the index returned you call the output function by passing in the object located the index retrieved from search (if it is not -1)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>

#include<fstream>

#include<string>

#include<sstream>

using namespace std;

struct bankAcct

{

string first ,last ;

double amount ;

long acctNo ;

short pin ;

};

int storeInfo(bankAcct[], ifstream&);

void sort(bankAcct[], int);

int search(bankAcct[], int, long);

void outputAndHandleRequest(bankAcct&);

int main()

{

bankAcct accounts[20];

ifstream infile;

int totalAccount;

infile.open("accounts.txt");

if(!infile)

{

cout<<"Error in opening file..Exiting.."<<endl<<endl;

return 0;

}

totalAccount=storeInfo(accounts,infile);

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

{

cout<<"Account Number: "<<accounts[i].acctNo<<endl;

cout<<"Account Holder Name: "<<accounts[i].first<<" "<<accounts[i].last<<endl;

cout<<"Account Current balance: $"<<accounts[i].amount<<endl<<endl;

}

sort(accounts,totalAccount);

cout<<" After sorting "<<endl;

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

{

cout<<"Account Number: "<<accounts[i].acctNo<<endl;

cout<<"Account Holder Name: "<<accounts[i].first<<" "<<accounts[i].last<<endl;

cout<<"Account Current balance: $"<<accounts[i].amount<<endl<<endl;

}

long searchNumber;

cout<<"Enter the account number you want to search for: ";

cin>>searchNumber;

int loc=search(accounts,totalAccount,searchNumber);

if(loc>0)

{

outputAndHandleRequest(accounts[loc]);

}

else

{

cout<<"Record not found ";

}

return 0;

}

int storeInfo(bankAcct accounts[], ifstream& file)

{

string line;

int count=0;

string fname,lname;

double amount;

long number;

short pin;

while(getline(file,line))

{

stringstream ss(line);

ss>>fname;

ss>>lname;

ss>>amount;

ss>>number;

ss>>pin;

accounts[count].first=fname;

accounts[count].last=fname;

accounts[count].acctNo=number;

accounts[count].pin=pin;

accounts[count].amount=amount;

count++;

}

return count;

}

void sort(bankAcct accounts[], int count)

{

int i,j,min;

bankAcct temp;

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

{  

for (j = i + 1; j < count; j++)

{

if (accounts[i].acctNo > accounts[j].acctNo)

{

temp = accounts[i];

accounts[i] = accounts[j];

accounts[j] = temp;

}

}

}

}

int search(bankAcct accounts[], int count, long number)

{

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

{

if(accounts[i].acctNo==number)

{

return i;

}

}

return -1;

}

void outputAndHandleRequest(bankAcct& account)

{

int choice;

cout<<" Account Number: "<<account.acctNo<<endl;

cout<<"Account Holder Name: "<<account.first<<" "<<account.last<<endl;

cout<<"Account Current balance: $"<<account.amount<<endl;

cout<<"Press 1. For withdraw 2. For Deposit"<<endl;

cin>>choice;

if(choice==1)

{

double amnt;

cout<<"Enter amount to withdraw: ";

cin>>amnt;

if(amnt<account.amount)

account.amount-=amnt;

else

cout<<"Nu sufficient balance"<<endl<<endl;

}

else if(choice==2)

{

double amnt;

cout<<"Enter amount to withdraw: ";

cin>>amnt;

account.amount+=amnt;

}

else

cout<<" Invalid choie ";

}

output

accounts.txt file

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Description For this assignment, you will maintain an array of bank accounts. You will declare a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This lab is to give you more experience with C++ Searching and Sorting Arrays Given a...

    This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....

  • Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations...

    Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...

  • Stuck on this computer science assignment Write a program that demonstrates binary searching through an array...

    Stuck on this computer science assignment Write a program that demonstrates binary searching through an array of strings and finding specific values in an corresponding parallel double array. In all cases your output should exactly match the provided solution.o. Provided files: Assignment.cpp - starter assignment with function prototypes companies.txt - file for program to read. earnings.txt - file for program to read. Input1.txt Input2.txt - Test these inputs out manually, or use stream redirection Input3.txt - These inputs are based...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...

  • C programming The program will require the following structure: struct _data { char *name; long number;...

    C programming The program will require the following structure: struct _data { char *name; long number; }; The program will require command line arguments: int main(int argv, char **argc) { Where argv is the number of arguments and argc is an array holding the arguments (each is a string). Your program must catch any case where no command line arguement was provided and print a warning message (see below). You MUST include/use the following functions, defined as follows: int SCAN(FILE...

  •       C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...

          C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp)    Print out the customer’s name, address, account number and balance using whatever formatting you would like    Sort on account balance (hint: you can overload the < operator and use sort from the...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player,...

    Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT