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

I\'m writing a program that that allows the user to deal with bank account infor

ID: 3534449 • Letter: I

Question

I'm writing a program that that allows the user to deal with bank account information. My problem is that when i create an account, do some deposit, withdraw and other things. The program won't save the account information that i create or load it. The account information won't show in bank inquiry and customer list. I don't what my problem is. It might be that I didn't open/read/close the file correctly. If you are able to point out any other problems, I would be grateful.


Here is my program


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <string>

using namespace std;

const int MAX_CUSTOMERS = 1000;
const double OVERDRAFT_FEE = 35.00;


int linearSearch(string acno, const string acNums[], int numAccs)
{
    int i;
    for (i=0; i<numAccs; i++)
    {
       if (acno == acNums[i])
          return i;
    }
    return -1;
}


void openAccount(string acno, string fName, string lName, char midInit, double initBal, string acNums[], string fNames[], string lNames[], char midInitials[], double balances[], int& numAccs)
{
     acNums[numAccs] = acno;
     lNames[numAccs] = lName;
     fNames[numAccs] = fName;
     midInitials[numAccs] = midInit;
     balances[numAccs] = initBal;
     numAccs++;
     cout<<endl;
}


void closeAccount(string acno, string acNums[], string fNames[], string lNames[], char midInitials[], double balances[], int& numAccs)
{

     acNums[numAccs]= acNums[numAccs+1];
     fNames[numAccs]= fNames[numAccs+1];
     lNames[numAccs]= lNames[numAccs+1];
     midInitials[numAccs]=midInitials[numAccs+1];
     balances[numAccs]= balances[numAccs+1];
     numAccs--;
     cout<<endl;
}


void deposit(string acno, double amount, const string acNums[], double balances[], int numAccs)
{
   int row = linearSearch(acno,acNums,numAccs);
   balances[row] = balances[row] + amount;
}


void withdraw(string acno, double amount, const string acNums[], double balances[], int numAccs)
{
        int row = linearSearch(acno, acNums, numAccs);
        if (amount > balances[row])
        {
        balances[row]= balances[row]- amount - OVERDRAFT_FEE;
        }
        else
        balances[row]= balances[row] - amount;
        cout<<endl;
}


void inquiry(string acno, const string acNums[], const string fNames[],const string lNames[], const char midInitials[],const double balances[], int numAccs)
{
        int i = numAccs;
        cout << "------------------------------"<<endl;
        cout << "customer: " << fNames[numAccs] << " " << midInitials[numAccs] << ". " << lNames[numAccs]<< endl;
        cout << "A/C #: " << acNums[numAccs] << endl;
        cout << "Balance: $" << setprecision(2) << fixed << balances[numAccs] << endl;
        cout << "------------------------------" << endl;
}


void customersList(const string acNums[], const string fNames[],
const string lNames[], const double balances[], int numAccs)
{
   if(numAccs == 0)
    {
        cout << " *** THERE ARE NO ACTIVE ACCOUNTS ***" << endl;
    }
    else
    {
            cout << "              Geaux Tiger Bank, Louisiana LTD" << endl;
            cout << "                     Customers Listing" << endl;
            cout << "      100 Les Miles Dr., Baton Rouge, Louisiana 70802" << endl;
            cout << "===========================================================" << endl;
            cout << setw(14) << left << "a/c # " << setw(14) << left;
            cout << "First Name " << setw(14) << left<< "Last Name " << setw(14 )<< "Balance" << endl;
            cout << "-----------------------------------------------------------" << endl;
       
        for(int i=0; i<numAccs;i++)
        {
            cout << setw(14) << left << acNums[numAccs] << setw(14) << left;
            cout << fNames[numAccs] << setw(14) << left << lNames[numAccs] << setw(14);
            cout << setprecision(2) << fixed << "$" << balances[numAccs] << endl;
        }
            cout<<"==========================================================="<<endl;
    }
}


void menu()
{
    cout<<"      Geaux Tigers Bank ATM"<<endl;
    cout<<"     ========================"<<endl;
    cout<<"     OPEN AN ACCOUNT......[1]"<<endl;
    cout<<"     CLOSE AN ACCOUNT.....[2]"<<endl;
    cout<<"     DEPOSIT..............[3]"<<endl;
    cout<<"     WITHDRAW.............[4]"<<endl;
    cout<<"     BALANCE INQUIRY......[5]"<<endl;
    cout<<"     CUSTOMERS LISTING....[6]"<<endl;
    cout<<"     EXIT.................[0]"<<endl;
}  

int main()
{
   string acNums[MAX_CUSTOMERS], fNames[MAX_CUSTOMERS], lNames[MAX_CUSTOMERS];
   char midInitials[MAX_CUSTOMERS];
   double balances[MAX_CUSTOMERS];   
   
   string acno, lName, fName;
   double initBal, amount;
   char midInit;

   int numAccs=0, pos, option;
   fstream acInfoIn, acInfoOut, inStrInfo, inStrBal, outStrInfo, outStrBal;
   string fileNameInfo ="acinfo.dbf";
   string fileNameBal = "acbal.dbf";
   
   acInfoIn.open("acinfo.dbf",ios::in);
   numAccs = 0;
   while (acInfoIn>>acNums[numAccs])
   {
      acInfoIn>>lNames[numAccs]>>fNames[numAccs]>>midInitials[numAccs]>>balances[numAccs];
    numAccs++;
   }
   acInfoIn.close();  


   do
   {
      menu();
      cout<<endl;
      cout<<"Select an option->";
      cin>>option;
      cout<<endl;
      switch(option)
      {
         case 1:
                cout<<"Enter a 10-character long account number->";
                cin>>acno;
                cout<<endl;
               
                if (acno.length() != 10)
                {
                   cout<<acno<<" must be 10-character long."<<endl;
                   cout<<endl;
                }
                else if (linearSearch(acno,acNums,numAccs) > 0)
                {
                   cout<<acno<<" cannot be assigned to multiple customers."<<endl;
                   cout<<endl;
                }
                else
                {
                   cout<<"Customer's first name ->";;
                   cin>>fName;
                   cout<<"Customer's middle initial ->";
                   cin>>midInit;
                   cout<<"Customer's last name ->";
                   cin>>lName;
                   cout<<"Initial Deposit ->";
                   cin>>initBal;
                   if (initBal < 25.00)
                   {
                      cout<<"The initial balance required for a new account must be at least $25.00."<<endl;
                      cout<<endl;
                   }
                   else
                      openAccount(acno,fName,lName,midInit,initBal,acNums,fNames,lNames,midInitials,balances,numAccs);
                }                   
                break;
               
         case 2:
                cout<<"Enter a ten digit account number->"<<endl;
                cin>>acno;
                cout<<endl;
               
                if(acno.length()!=10)
                 {
                    cout<<"Account number must be ten digits."<<endl;
                    cout<<endl;
                 }  
                else if(linearSearch(acno,acNums,numAccs)<0)
                 {
                    cout<<"Account number does not exist."<<endl;
                    cout<<endl;
                 }  
                else
                 {
                    closeAccount(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
                 }                
                break;
               
         case 3:
                cout<<"Enter a 10-character long account number->";
                cin>>acno;
                cout<<endl;
               
                if (acno.length() != 10)
                {
                   cout<<acno<<" must be 10-character long."<<endl;
                   cout<<endl;
                }
                else if (linearSearch(acno,acNums,numAccs) < 0)
                {
                   cout<<acno<<" is not a valid account ."<<endl;
                   cout<<endl;
                }
                else
                {
                   cout<<"Enter the amount to be deposited-> ";
                   cin>>amount;
                   cout<<endl;
                   if (amount <= 0)
                   {
                      cout<<"The amount to be deposited must be at least $0.01."<<endl;
                      cout<<endl;
                  }
                   else
                      deposit(acno,amount,acNums,balances,numAccs);
                }                  
                break;
               
         case 4:
                cout<<"Enter a ten digit account number->"<<endl;
                cin>>acno;
                cout<<endl;
               
                if(acno.length()!=10)
                {
                    cout<<"Account number must be ten digits.";
                    cout<<endl;
                 }
                else if(linearSearch(acno,acNums,numAccs)<0)
                 {
                    cout<<"Account number does not exist."<<endl;
                    cout<<endl;
                 }  
                else
                {
                    cout<<"Enter the amount to be withdrawn->"<<endl;
                    cin>>amount;
                    cout<<endl;
                    if(amount<=0.00)
                    {
                       cout<<"The amount to be withdrawn must be at least $0.01."<<endl;
                       cout<<endl;
                    }
                    else
                        withdraw(acno, amount, acNums,balances,numAccs);
                 }
                break;
               
         case 5:
                cout<<"Enter a ten digit account number->"<<endl;
                cin>>acno;
                cout<<endl;
               
                if(acno.length()!=10)
                {
                    cout<<"Account number must be ten digits."<<endl;
                    cout<<endl;
                 }   
                else if(linearSearch(acno,acNums,numAccs)<0)
                {
                    cout<<"Account number does not exist."<<endl;
                    cout<<endl;
                 }   
                else
                {
                    inquiry(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
                 }                       
                break;
               
         case 6:
                customersList(acNums,fNames,lNames,balances,numAccs);
                break;
               
         case 0:
                break;
               
         default:
               cout<<"Invalid menu option"<<endl;
               cout<<endl;                 
      }                                                                 
    }while (option != 0);
    outStrInfo.open(fileNameInfo.c_str(), ios::out);
    outStrBal.open(fileNameBal.c_str(), ios::out);

    if(outStrBal.fail())
    {
        cout<<"File acbal.dbf failed to open."<<endl;
      }
    if(outStrInfo.fail())
    {
        cout<<"File acinfo.dbf failed to open."<<endl;
      }
    else
    {
        numAccs=0;
        for(int i=0;i>MAX_CUSTOMERS;i++)
        {
            outStrInfo>>acno[i];
            outStrInfo>>lNames[i];
            outStrInfo>>fNames[i];
            outStrInfo>>midInitials[i];
            outStrBal>>acno[i];
            outStrBal>>balances[i];
            numAccs++;
        }
    }

    outStrInfo.close();
    outStrBal.close();

   
   
    return (0);


}

Explanation / Answer

# include<iostream.h>

# include<conio.h>

# include<iomanip.h>


class bank

{

char name[20];

int acno;

char actype[4];

float balance;

public:

void init();

void deposit();

void withdraw();

void disp_det();

};

//member functions of bank class

void bank :: init()

{

cout<<"


New Account

";

cout<<"


Enter the Name of the depositor : ";

cin.get(name,19,'

');

cout<<"

Enter the Account Number : ";

cin>>acno;

cout<<"

Enter the Account Type : (CURR/SAVG/FD/RD/DMAT) ";

cin>>actype;

cout<<"

Enter the Amount to Deposit : ";

cin >>balance;

}

void bank :: deposit()

{

float more;

cout <<"

Depositing

";

cout<<"


Enter the amount to deposit : ";

cin>>more;

balance+=more;

}

void bank :: withdraw()

{

float amt;

cout<<"

Withdrwal

";

cout<<"


Enter the amount to withdraw : ";

cin>>amt;

balance-=amt;

}

void bank :: disp_det()

{

cout<<"


Account Details


";

cout<<"Name of the depositor : "<<name<<endl;

cout<<"Account Number : "<<acno<<endl;

cout<<"Account Type : "<<actype<<endl;

cout<<"Balance : $"<<balance<<endl;

}

// main function , exectution starts here

void main(void)

{

clrscr();

bank obj;

int choice =1;

while (choice != 0 )

{

cout<<"


Enter 0 to exit

1. Initialize a new acc.

2. Deposit

3.Withdraw

4.See A/c Status";

cin>>choice;

switch(choice)

{

case 0 :obj.disp_det();

cout<<"


EXITING PROGRAM.";

break;

case 1 : obj.init();

break;

case 2: obj.deposit();

break;

case 3 : obj.withdraw();

break;

case 4: obj.disp_det();

break;

default: cout<<"


Illegal Option"<<endl;

}

}

getch();

}