Question

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 to 10 customers and write a program to illustrate how to use your class. Example output is shown below: 1: Enter 1 to add a new customer. 2: Enter 2 for an existing customer. 3: Enter 3 to print customers data. 9: Enter 9 to exit the program. 1 Enter customer's name: Dave Brown Enter account type (checking/savings): checking Enter amount to be deposited to open account: 10000 Enter interest rate (as a percent): .01 1: Enter 1 to add a new customer. 2: Enter 2 for an existing customer. 3: Enter 3 to print customers data. 9: Enter 9 to exit the program. 3 Account Holder Name: Dave Brown Account Type: checking Account Number: 1100 Balance: $10000.00 Interest Rate: 0.01% ***************************** 1: Enter 1 to add a new customer. 2: Enter 2 for an existing customer. 3: Enter 3 to print customers data. 9: Enter 9 to exit the program.

C++ Programing

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

//Comment if you have doubts. and like the answer.

Account number series starts from 1100 .

//BankAccount.h
#ifndef BANK_ACCOUNT__H
#define BANK_ACCOUNT__H
#include<iostream>
using namespace std;
class bankAccount{
   public:
   //public fields.
       string accountHolderName;
       int accountNumber;
       string accountType;
       double balance;
       double interestRate;
       //static field to set account number series.
       static int accountNumSeries;
   public:
   //constructor to intilize fields.
       bankAccount(){
          
           accountHolderName = "";
           accountNumber = accountNumSeries;
           accountType = "";
           balance = 0;
           interestRate = 0.0;
           accountNumSeries++;
       }
       //method to withdraw given amount
       void withdraw(double amount)
       {
           //check amount is valid amount.
           if(amount <= 0)
           {
               cout<<"\nTransaction failed: invalid amount entered( > 0) to withdraw.\n";
               return;
           }
           //check for available funds.
           if(amount > balance)
           {
               cout<<"\nTransaction failed: Insufficient amount of funds in account.\n";
               return;
           }
           //if valid amount then remove from account balance
           balance-=amount;
           cout<<"\nTranscation Success: Available funds in account : "<<balance<<endl;
       }
       //depsit given amount in account.
       void deposit(double amount)
       {
           //check valid amount
           if(amount <= 0)
           {
               cout<<"\nTransaction failed: Please enter valid amount( > 0) to withdraw.\n";
               return;
           }
           //add to balance if valid.
           balance+=amount;
           cout<<"\nTranscation Success: Available funds in account : "<<balance<<endl;
       }
       //method to print all info of account.
       void printDetails()
       {
          
           cout << "\nAccount Holder Name : "<< accountHolderName;
           cout << "\nAccount Type : "<< accountType;
           cout << "\nAccount Number : " << accountNumber;
           cout << "\nBalance : " << balance;
           cout << "\nInterest Rate : " << interestRate<<"%";
           cout << "\n************************************\n";
       }
};
int bankAccount::accountNumSeries=1100;
#endif

//main.cpp
#include "BankAccount.h"
#include<limits>
//method to print menu.
void printMenu()
{
   cout<<"\n1: Enter 1 to add a new customer."
       <<"\n2: Enter 2 for an existing customer."
       <<"\n3: Enter 3 to print customers data."
       <<"\n9: Enter 9 to exit the program. "
       <<"\nEnter your choice: ";
}
//method that takes prompt to be printed and returns double value of amount.
//helps in getting amount as input for withdrawl,deposit .
double getAmountAsInput(string prompt)
{
   cout<<"\n"<<prompt;
   double balance;
   cin >> balance;
   return balance;
}
//main mehtod.
int main()
{
   int totalAccounts = 10;
   bankAccount accounts[totalAccounts];
   int choice = 0;
   int curIndex = 0;
   string accountHolderName;
   int accountNumber;
   string accountType;
   double balance;
   double interestRate;
   int subChoice;
   //till user quits.
   while(choice != 9)
   {
       printMenu();
       //get choice.
       cin >> choice ;
      
       switch(choice)
       {
           //if choice is to add new user.
           case 1:
           {
               if(curIndex == totalAccounts)
               {
                   cout<<"\nAccounts Limit Reached. \n";
               }
               else
               {
                   //clear any characters in cin buffer.since we are using getline()
                   //method to get account holder name.
                   //getline() takes any trailing characters in cin buffer.
                   cin.clear();
                   cin.ignore(numeric_limits<streamsize>::max(),'\n');
                   //get all fields
                   cout<<"\nEnter customer's name: ";
                   getline(cin,accountHolderName);
                   cout<<"\nEnter account type (checking/savings): ";
                   cin >> accountType;
                   balance = getAmountAsInput("Enter amount to be deposited to open account: ");
                   cout<<"\nEnter interest rate (as a percent): ";
                   cin >> interestRate;
                   //initilize fields.
                   accounts[curIndex].accountHolderName = accountHolderName;
                   accounts[curIndex].accountType = accountType;
                   accounts[curIndex].deposit(balance);
                   accounts[curIndex].interestRate = interestRate;
                   //increment array insertion index.
                   curIndex++;
               }
               break;
           }
           case 2:
           {
               //if option 2 selected get existing account number.
               //if account number is found, then asks for withdrawl,deposit or show account info choices.
               cout<<"\nEnter Existing customer account number : ";
               cin >> accountNumber;
               bool isFound = false;
               for(int i = 0;i<curIndex;i++)
               {
                  
                   if(accounts[i].accountNumber == accountNumber)
                   {
                       cout<<"\nHi: "<<accounts[i].accountHolderName<<", Please Choose any one of the options below:\n";
                       isFound = true;
                       cout<<"\nEnter 1. to deposit amount";
                       cout<<"\nEnter 2. to withdraw amount";
                       cout<<"\nEnter 3. to see account info";
                       cin >> subChoice;
                       if(subChoice == 1)
                       {
                           balance = getAmountAsInput("Enter amount to be deposited : ");
                           accounts[i].deposit(balance);
                       }
                       else if(subChoice == 2)
                       {
                           balance = getAmountAsInput("Enter amount to be withdrawed : ");
                           accounts[i].withdraw(balance);
                       }
                       else if(subChoice == 3)
                       {
                           accounts[i].printDetails();
                       }
                       else
                       {
                           cout<<"\nError: Invalid Choice.\n";
                       }
                   }
               }
               //if entered acc number not found print not found.
               if(isFound == false)
               {
                   cout<<"\nSorry.Account Number Not Found.\n";
               }
               break;
           }
           case 3:
           {
               for(int i = 0;i<curIndex;i++)
               {
                   accounts[i].printDetails();
               }
               break;
           }
           case 9:
           {
               cout<<"\nQuitting....";
               break;
           }
           default:
           {
               cout<<"\nInvalid choice. Try again\n";
           }
       }
      
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Define the class bankAccount to implement the basic properties of a bank account. An object of...
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...

  • 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...

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

    C++ 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

  • Please hlep as I've tried this C++ program and keep coming up with the wrong syntax...

    Please hlep as I've tried this C++ program and keep coming up with the wrong syntax somewhere. I need help defining 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...

  • 14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount...

    14 b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class inherits members to store the account number and the balance from the base class. A customer with a checking account typically receives interest, maintains a minimum balance, and pays service charges if the balance falls below the minimum balance. Add member variables to store this additional information. In addition to the operations inherited from the base class, this...

  • Write one for all three files in c++ E MISLI UCCIONS if Instructions Define the class...

    Write one for all three files in c++ E MISLI UCCIONS if Instructions 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...

  • 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...

  • 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...

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

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