Write a programme in C++ to define a class to represent a bank account.

Define a class to represent a bank account
Include the following data members and member functions
Data Members
  •          Name of depositor
  •          Account number
  •          Type of account
  •          Balance amount in account
Member functions
  •          To assign initial values
  •          To Deposit an amount
  •          To withdraw an amount after checking the balance
  •          To display main balance







//Define a class to represent a bank account 
//Include the following data members and member functions

#include<iomanip>
#include<iostream>
using namespace std;
class BankAccount
{
    public:
        string depositer;
        string accono;
        char ch;
        float balance;
    public:
        void initial();
        void deposit();
        void show();
        void withdraw();        
};
void BankAccount::initial()
{
            cout<<"enter the name of depositor"<<endl;
            cin>>depositer;
            cout<<"enter account number"<<endl;
            cin>>accono;
            cout<<"enter type of account 'S' for saving account type and 'C' for current account"<<endl;
            cin>>ch;
            cout<<"!!!!CONGRATULATIONS ACCOUNT CREATED!!!!";
            cout<<"initial account balance = 0.0 "<<endl;
            balance=0.0;
            BankAccount::show();
}       
void BankAccount::show()
{
    cout<<"Name Of Depositor= "<<depositer<<endl;
    cout<<"Account Number = "<<accono<<endl;
    cout<<"AccountType=";
    if(ch=='S'||ch=='s')
    cout<<"SAVING"<<endl;
    else if(ch=='C'||ch=='c')
    cout<<"CURRENT"<<endl;
    else
    cout<<"BAD INPUT"<<endl;
    cout<<"Balance= "<<balance<<endl;   
}
void BankAccount::deposit()
{ 
    int added;
    cout<<"enter amount to be deposited"<<endl;
    cin>>added;
    balance=balance+added;  
    BankAccount::show();
}
void BankAccount::withdraw()
{
    int subtracted;
    cout<<"Enter Amount to be WIthdrawn"<<endl;
    cin>>subtracted;
    balance=balance-subtracted;
    BankAccount::show();
}
int main()
{
    BankAccount obj;    
    cout<<"Enter initial bank account details"<<endl;
    obj.initial();  
    cout<<"Deposit amount"<<endl;
    obj.deposit();  
    cout<<"Withdraw Amount"<<endl;
    obj.withdraw(); 
    return 0;
}

Comments

Most Popular Posts Of All Time