Question

Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance = 250, interest = 12% The program would ask the user to enter an account number, displays the account balance if the account exists, or an error if it doesn’t, then prompt the user to choose an operation from following 1) Deposit 2) Withdraw 3) Check Balance 4) Add Interest 5) Exit The follow-up scenario depends on each operation (e.g. for a withdrawal, your program should ask for the amount to withdraw, then either print an error if the withdrawal is bigger than the balance or an operation completed if it is less). After operations 1,2,4, the program should display the updated balance. When the user chooses to exit, the program should return to the main prompt of asking the user to enter an account number The program should terminate if the user input -1 in the account number field (35 points)

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

#include<iostream>
using namespace std;
class BankAccount
{
    private:
        int a[5];
        static double balance[5];
        double interest[5];
    public:
        //parameterized constructor to initialize the data
   BankAccount(int [],double [], double []);
   void check(int);
   void deposit(int);
   void withdraw(int);
   void checkbalance(int);
   void addinterest(int);
  
};

BankAccount :: BankAccount(int x[5],double y[5],double z[5])
{
   int i;
   for(i=0;i<5;i++)
   {
      a[i]=x[i];
      balance[i]=y[i];
      interest[i]= z[i];
   }
}

//body part of check()
void BankAccount :: check(int ac)
{
    for(int i=0;i<5;i++)
    { //find the account number
   if(a[i]==ac)
   { //printthe details
   cout<<"\n YOUR ACCOUNT DETAILS \n";
    cout<<"\n ACCOUNT NUMBER : "<<a[i];
    cout<<"\n YOUR BALANCE : "<<balance[i];
    cout<<"\n INTEREST RATE : "<<interest[i];
}
}
}
void BankAccount :: deposit(int ac)
{
   double amt;
   //ask the user to input the amount to deposit
   cout<<endl<<"Enter the amount to deposit";
   cin>>amt;
   for(int i=0;i<5;i++)
    if(a[i]==ac) //condition to find the account number
       balance[i] = balance[i] + amt; //update the balance
}
  
void BankAccount :: withdraw(int ac)
{
    double amt;
    //ask the amount to withdraw
    cout<<"\n Enter the amount to withdraw";
    cin>>amt;
    for(int i=0;i<5;i++)
    { //condition to find the account number
   if(a[i]==ac)
   {//check whether the amount is sufficient in account or not
    if(amt>balance[i])
    {
    cout<<"\n Insufficient Balance to withdraw "<<amt;
    //cout<<endl<<"Your Account Balance is : "<<balance[i];
}
    else
    { //update the balance
    balance[i] = balance[i]-amt;
    cout<<endl<<"Operation successful.";
}
}
}
}
void BankAccount :: checkbalance(int ac)
{ //loop tot diaply the details of an account
for(int i=0;i<5;i++)
   
   if(a[i]==ac)
       cout<<endl<<"Your Balance is "<<balance[i];
   }
void BankAccount :: addinterest(int ac)
   {
      for(int i=0;i<5;i++)
    // update the interest
   if(a[i]==ac)
      balance[i] = balance[i] + (balance[i] * interest[i]/100);
   }
   double BankAccount::balance[5] ={0,0,0,0,0};
   //driver program
   int main()
   {
      //declaretion and initialization of array
int x[5] = {101,201,108,302,204};
double y[5]={100,50,200,10,250};
double z[5] = {10,20,11,5,12} ;
      int opt;
      int ac,i;
      BankAccount b(x,y,z);
      while(1)
      { top: //labelname
      //ask for the account number
      opt=0;
         cout<<"\n Enter the account Number";
             cin>>ac;
             //if account number is -1then terminate the program
             if(ac==-1)
             exit(0);
             //loop to check the validity for account number
             for(i=0;i<5;i++)
             if(ac==x[i])
             {
                opt=1;
             break;
         }
         //condition for invalid account
         if(opt!=1)
         {
            cout<<endl<<"\n Invalid account number";
             goto top;
                   }
                   else
                   b.checkbalance(ac);
            
             //display the menu
         cout<<endl<<"1. Deposit 2. Withdraw 3. Check Balance 4. Add Interest 5. EXIT";
         cout<<endl<<"\n Enter your choice";
         cin>>opt;
         //if for deposit
         if(opt==1)
         {
            
             b.deposit(ac); //call to deposite method
                 b.checkbalance(ac); //call to checkbalace to diplay the balance
            
           }
           else //condition for withdraw
           if(opt==2)
           {
              
               b.withdraw(ac);//call to withdraw()
                   b.checkbalance(ac); //call to checkbalace to diplay the balance
           }
           else
           if(opt==3)
           {
             
             b.checkbalance(ac); //call to checkbalace to diplay the balance
               }
               else
               if(opt==4)
               {
                   b.addinterest(ac); //call to addinterest() to update the interest amount
                   b.checkbalance(ac); //call to checkbalace to diplay the balance
                   }
                   else
                   if(opt==5)
                   {//send the control to top
                   goto top;  
                   }
       }
   }

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...
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
  • c++ please    Define the class bankAccount to implement the basic properties of a bank account....

    c++ please    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Write a program called problem4.cpp that creates a histogram of the temperature values over the past...

    Write a program called problem4.cpp that creates a histogram of the temperature values over the past year. The temperature values ranges from 0 to 25 degrees, and the program should ask the use to input the number of days in the past year where the temperature was of each of these values. After the user inputs this data, the program should draw a histogram of these temperatures using the char ‘*’ and output the mode temperature (the temperature that occurred...

  • The program needs to be in python : First, create a BankAccount class. Your class should...

    The program needs to be in python : First, create a BankAccount class. Your class should support the following methods: class BankAccount (object): """Bank Account protected by a pin number.""" def (self, pin) : init "n"Initial account balance is 0 and pin is 'pin'."" self.balance - 0 self.pin pin def deposit (self, pin, amount): """Increment account balance by amount and return new balance.""" def withdraw (self, pin, amount): """Decrement account balance by amount and return amount withdrawn.""" def get balance...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Define the class bankAccount to implement the basic properties of a bank account. An object of...

    Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also, declare an array of 10 components of type bankAccount to process up...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

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
ADVERTISEMENT