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

IN NEED OF SOME HELP WHERE DO I GO FROM HERE? It reads commands from a bank.txt

ID: 3772273 • Letter: I

Question

IN NEED OF SOME HELP WHERE DO I GO FROM HERE?

It reads commands from a bank.txt file. Your program must process the following four commands.

Create account amount Deposit account amount Withdraw account amount Balance account

In all of the above commands, account is an integer and amount is a double. The following program behavior is required –

Valid account numbers are 1-9. This requires the program to have an array of references to Account objects.

If the first word on any line contains a command other than the four listed above, an error message should be displayed and that line ignored.

The create command creates a new account object with the given account number and initial balance. If an account already exists with that number an error message should be displayed and the command ignored.

The Deposit and Withdraw commands perform the indicated operation on an existing account. If no account with that number has been created, an error message is displayed and the command ignored.

The Balance command displays the balance of the requested account. No change to the account occurs. If no account with that number has been created, an error message is displayed and the command ignored.

Helpful Hints

I have included a working example and sample bank.txt file along with the assignment.

The .exe file and .txt files can be copied into any Windows directory to be run. You can

explore other behaviors of the program by modifying the .txt file.

Your Account class can be used exactly as it is although you will need to copy it to your

new project for Lab 5

One way to skip the rest of a line if there is a bad command or account number is – string junk;

if (inFile.peek() != ' ') getline(inFile, junk);

Test your program extensively to make sure it behaves as it should. I will use a different bank.txt file to test your programs.

This is not an assignment that can be completed in a single day. Don’t put it off. Upload: Your .h and .cpp files.

THIS IS WHAT I HAVE SO FAR,

HEADER.H

#ifndef Header_H

#define Header_H

#include <iostream>

#include <string>

class Name{

  

private:

   int nextName;

   string CommonName[];

   void findRecursive(string name, int low, int high);

public:

   Name();

   void addName(pair CommonName);

   void sorthName();

   int findLinear(string name);

   int findBinary(string name);

};

class CommonName{

private:

   int newField;

   string name;

public:

       int gerOrdinal();

   string getName();

   CommonName(int ord, string aName);

};

#endif

HEADER.CPP

#include "Account.h"

using namespace std;

Account::Account()

{

   balance = 0;

}

Account::Account(int newId, double initialBalance)

{

   id = newId;

   balance = initialBalance;

}

void Account::setId(int newId)

{

   id = newId;

}

void Account::setBalance(double newBalance)

{

   balance = newBalance;

}

void Account::withdraw(double amount)

{

   balance = balance - amount;

}

void Account::deposit(double amount)

{

   balance = balance + amount;

}

MAIN.CPP

#include<iostream>

#include<iomanip>

#include<cmath>

using namespace std;

#include "Account.h"

int main() {

  

double checkBal = 0.0, savBal = 0.0;

double checkDeposit = 0.0, savDeposit = 0.0;

double checkWdraw = 0.0, savWdraw;

Account checkAccount;

Account savingsAccount;

checkAccount.setId(11777);

savingsAccount.setId(22999);

  

  

cout << setprecision(2) << fixed << endl;

cout << "Please enter the initial balance for Account #" << checkAccount.getId() << ": $";

cin >> checkBal;

checkAccount.setBalance(checkBal);

  

cout << "Please enter the initial balance for Account #" << savingsAccount.getId() << ": $";

cin >> savBal;

savingsAccount.setBalance(savBal);

  

cout << "How much will you deposit into Account #" << checkAccount.getId() << ": $";

cin >> checkDeposit;

checkAccount.deposit(checkDeposit);

  

cout << "How much will you withdraw from Account #" << checkAccount.getId() << ": $";

cin >> checkWdraw;

checkAccount.withdraw(checkWdraw);

  

cout << "The current Balance in Account #" << checkAccount.getId()

<< " is: $" << checkAccount.getBalance()

;

cout << " How much will you deposit into Account #" << savingsAccount.getId() << ": $";

cin >> savDeposit;

savingsAccount.deposit(savDeposit);

  

cout << "How much will you withdraw from Account #" << savingsAccount.getId() << ": $";

cin >> savWdraw;

savingsAccount.withdraw(savWdraw);

  

cout << "The current Balance in Account #" << savingsAccount.getId()

<< " is: $" << savingsAccount.getBalance() << " ";

  

  

  

  

  

  

  

return 0;

}

Explanation / Answer

import java.io.*;


class Curr_acct      //CURRENT ACCOUNT CLASS
{
         final int max_limit=20;
         final int min_limit=1;
         final double min_bal=500;
         private String name[]=new String[20];
         privateint accNo[]=newint[20];
         private String accType[]=new String[20];
         privatedouble balAmt[]=newdouble[20];
         staticint totRec=0;
       
        //Intializing Methodpublicvoid initialize()
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

       
       
        //TO ADD NEW RECORDpublicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

               if (totRec>max_limit)
               {
                    System.out.println(" Sorry we cannot admit you in our bank... ");
                    permit=false;
               }

               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record              
               System.out.println(" =====RECORDING NEW ENTRY=====");
               try{
                          accNo[totRec]=totRec;    //Created AutoNumber to accNo so no invalid id occurs
                        System.out.println("Account Number : "+accNo[totRec]);
                       
                     BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                     System.out.print("Enter Name : ");
                     System.out.flush();
                     name[totRec]=obj.readLine();

                     accType[totRec]="Current Account";
                     System.out.println("Account Type : "+accType[totRec]);                    

                    do{
                           System.out.print("Enter Initial Amount to be deposited : ");
                           System.out.flush();
                           str=obj.readLine();
                           balAmt[totRec]=Double.parseDouble(str);
                         }while(balAmt[totRec]<min_bal);     

                  System.out.println(" ");
                    }
                catch(Exception e)
                {}
            }
        }

       
       
        //TO DISPLAY DETAILS OF RECORDpublicvoid display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                          
             

          //TO DEPOSIT AN AMOUNTpublicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println(" =====DEPOSIT AMOUNT=====");
             
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);
                         if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                         {
                              System.out.println(" Invalid Account Number ");
                              valid=false;
                         }
          
                        if (valid==true)
                       {
                            System.out.print("Enter Amount you want to Deposit : ");
                            System.out.flush();
                            str=obj.readLine();
                            amt=Double.parseDouble(str);

                            balAmt[acno]=balAmt[acno]+amt;

                            //Displaying Depsit Details
                            System.out.println(" After Updation...");
                            System.out.println("Account Number : "+acno);
                            System.out.println("Balance Amount : "+balAmt[acno]+" ");
                        }
                 }
            catch(Exception e)
            {}
       }


     //TO WITHDRAW BALANCEpublicvoid withdraw()
        {
              String str;
              double amt,checkamt,penalty;
              int acno;
              boolean valid=true;
              System.out.println(" =====WITHDRAW AMOUNT=====");
             
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                  
                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);

                          if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                             {
                                System.out.println(" Invalid Account Number ");
                                valid=false;
                            }

                        if (valid==true)
                        {
                                System.out.println("Balance is : "+balAmt[acno]);
                                System.out.print("Enter Amount you want to withdraw : ");
                                System.out.flush();
                                str=obj.readLine();
                                amt=Double.parseDouble(str);

                                checkamt=balAmt[acno]-amt;

                                if(checkamt >= min_bal)
                                 {
                                    balAmt[acno]=checkamt;
                                    //Displaying Depsit Details
                                    System.out.println(" After Updation...");
                                    System.out.println("Account Number : "+acno);
                                    System.out.println("Balance Amount : "+balAmt[acno]+" ");
                                }
                                else
                                 {
                                    System.out.println(" Your Balance has gone down and so penalty is calculated");
                                    //Bank policy is to charge 20% on total difference of balAmt and min_bal to be

maintain
                                    penalty=((min_bal - checkamt)*20)/100;
                                    balAmt[acno]=balAmt[acno]-(amt+penalty);
                                    System.out.println("Now your balance revels : "+balAmt[acno]+" ");
                                }
                        }
                 }
            catch(Exception e)
            {}
       }

}

class Sav_acct        //SAVING ACCOUNT CLASS
{
         final int max_limit=20;
         final int min_limit=1;
         final double min_bal=500;
         private String name[]=new String[20];
         privateint accNo[]=newint[20];
         private String accType[]=new String[20];
         privatedouble balAmt[]=newdouble[20];
         staticint totRec=0;
       
        //Intializing Methodpublicvoid initialize()
        {
             for(int i=0;i<max_limit;i++)
             {
                name[i]="";
                accNo[i]=0;
                accType[i]="";
                balAmt[i]=0.0;
            }
        }

       
       
        //TO ADD NEW RECORDpublicvoid newEntry()
        {
               String str;
               int acno;
               double amt;
               boolean permit;
                permit=true;

               if (totRec>max_limit)
               {
                    System.out.println(" Sorry we cannot admit you in our bank... ");
                    permit=false;
               }

               if(permit = true)   //Allows to create new entry
               {
               totRec++;         // Incrementing Total Record              
               System.out.println(" =====RECORDING NEW ENTRY=====");
               try{
                          accNo[totRec]=totRec;    //Created AutoNumber to accNo so no invalid id occurs
                        System.out.println("Account Number : "+accNo[totRec]);
                       
                     BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                     System.out.print("Enter Name : ");
                     System.out.flush();
                     name[totRec]=obj.readLine();

                     accType[totRec]="Saving Account";  
                     System.out.println("Account Type : "+accType[totRec]);

                    do{
                           System.out.print("Enter Initial Amount to be deposited : ");
                           System.out.flush();
                           str=obj.readLine();
                           balAmt[totRec]=Double.parseDouble(str);
                         }while(balAmt[totRec]<min_bal);      //Validation that minimun amount must be 500

                  System.out.println(" ");
                    }
                catch(Exception e)
                {}
            }
        }

       
       
        //TO DISPLAY DETAILS OF RECORDpublicvoid display()
        {
              String str;
              int acno=0;
              boolean valid=true;
                          
              System.out.println(" =====DISPLAYING DETAILS OF CUSTOMER===== ");
              try{
                 BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                 System.out.print("Enter Account number : ");
                 System.out.flush();
                 str=obj.readLine();
                 acno=Integer.parseInt(str);
                  if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                     {
                          System.out.println(" Invalid Account Number ");
                          valid=false;
                     }

                    if (valid==true)
                      {    
                        System.out.println(" Account Number : "+accNo[acno]);
                        System.out.println("Name : "+name[acno]);
                        System.out.println("Account Type : "+accType[acno]);
                       
                        //Bank policy is to give 10% interest on Net balance amt
                        balAmt[acno]=balAmt[acno]+(balAmt[acno]/10);
                        System.out.println("Balance Amount : "+balAmt[acno]+" ");
                      }
                 }
            catch(Exception e)
            {}
        }

          //TO DEPOSIT AN AMOUNTpublicvoid deposit()
        {
              String str;
              double amt;
              int acno;
              boolean valid=true;
              System.out.println(" =====DEPOSIT AMOUNT=====");
             
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));

                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);
                         if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                         {
                              System.out.println(" Invalid Account Number ");
                              valid=false;
                         }
          
                        if (valid==true)
                       {
                            System.out.print("Enter Amount you want to Deposit : ");
                            System.out.flush();
                            str=obj.readLine();
                            amt=Double.parseDouble(str);

                            balAmt[acno]=balAmt[acno]+amt;

                            //Displaying Depsit Details
                            System.out.println(" After Updation...");
                            System.out.println("Account Number : "+acno);
                            System.out.println("Balance Amount : "+balAmt[acno]+" ");
                        }
                 }
            catch(Exception e)
            {}
       }

     //TO WITHDRAW BALANCEpublicvoid withdraw()
        {
              String str;
              double amt,checkamt;
              int acno;
              boolean valid=true;
              System.out.println(" =====WITHDRAW AMOUNT=====");
             
              try{
                   //Reading deposit value
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                  
                        System.out.print("Enter Account No : ");
                        System.out.flush();
                        str=obj.readLine();
                        acno=Integer.parseInt(str);

                          if (acno<min_limit || acno>totRec)   //To check whether accNo is valid or Not
                             {
                                System.out.println(" Invalid Account Number ");
                                valid=false;
                            }

                        if (valid==true)
                        {
                                System.out.println("Balance is : "+balAmt[acno]);
                                System.out.print("Enter Amount you want to withdraw : ");
                                System.out.flush();
                                str=obj.readLine();
                                amt=Double.parseDouble(str);

                                checkamt=balAmt[acno]-amt;

                                if(checkamt >= min_bal)
                                 {
                                    balAmt[acno]=checkamt;
                                    //Displaying Depsit Details
                                    System.out.println(" After Updation...");
                                    System.out.println("Account Number : "+acno);
                                    System.out.println("Balance Amount : "+balAmt[acno]+" ");
                                }
                                else
                                 {
                                    System.out.println(" As per Bank Rule you should maintain minimum balance of Rs

500 ");
                                }
                        }
                 }
            catch(Exception e)
            {}
       }
}

class Bank_improved
{
    publicstaticvoid main(String args[])
    {
        String str;
        int choice,check_acct=1,quit=0;
        choice=0;

         Curr_acct curr_obj = new Curr_acct();
         Sav_acct sav_obj = new Sav_acct();

         System.out.println(" =====WELLCOME TO BANK DEMO PROJECT===== ");


while( quit!=1)
{
        try{
           BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
           System.out.print("Type 1 for Current Account and Any no for Saving Account : ");
           System.out.flush();
           str=obj.readLine();
           check_acct=Integer.parseInt(str);
           }
           catch(Exception e) {}

    if(check_acct==1)
     {
        do//For Current Account
        {
        System.out.println(" Choose Your Choices ...");
        System.out.println("1) New Record Entry ");
        System.out.println("2) Display Record Details ");
        System.out.println("3) Deposit...");
        System.out.println("4) Withdraw...");
        System.out.println("5) Quit");
         System.out.print("Enter your choice : ");
        System.out.flush();
              try{
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                   str=obj.readLine();
                   choice=Integer.parseInt(str);

                          switch(choice)
                           {
                            case 1 : //New Record Entry
                                            curr_obj.newEntry();
                                           break;
                            case 2 : //Displaying Record Details
                                           curr_obj.display();
                                           break;
                            case 3 : //Deposit...
                                            curr_obj.deposit();
                                           break;
                            case 4 : //Withdraw...
                                            curr_obj.withdraw();
                                            break;
                            case 5 : System.out.println(" .....Closing Current Account.....");
                                            break;
                            default : System.out.println(" Invalid Choice ");
                          }
                    }
                catch(Exception e)
                {}
            }while(choice!=5);
    }
else
{
      do//For Saving Account
        {
        System.out.println("Choose Your Choices ...");
        System.out.println("1) New Record Entry ");
        System.out.println("2) Display Record Details ");
        System.out.println("3) Deposit...");
        System.out.println("4) Withdraw...");
        System.out.println("5) Quit");
         System.out.print("Enter your choice : ");
        System.out.flush();
              try{
                   BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                   str=obj.readLine();
                   choice=Integer.parseInt(str);

                          switch(choice)
                           {
                            case 1 : //New Record Entry
                                            sav_obj.newEntry();
                                           break;
                            case 2 : //Displaying Record Details
                                           sav_obj.display();
                                           break;
                            case 3 : //Deposit...
                                            sav_obj.deposit();
                                           break;
                            case 4 : //Withdraw...
                                            sav_obj.withdraw();
                                            break;
                            case 5 : System.out.println(" .....Closing Saving Account.....");
                                            break;
                            default : System.out.println(" Invalid Choice ");
                          }
                    }
                catch(Exception e)
                {}
            }while(choice!=5);
      }

try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print(" Enter 1 for Exit : ");
System.out.flush();
str=obj.readLine();
quit=Integer.parseInt(str);
}catch (Exception e){}
}
}
}