Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default

 



#include<iostream>
using namespace std;
class bank
{
    private:
        string name;
        long int accno;
        string acc_type ;
        long int balance;
    public:
        bank(){};
        bank(string n,long int ano ,long int bal,string sa)
        {
            name=n;
            accno=ano;
            balance=bal;
            acc_type = sa;
        }
        void setdata()
            {
                acc_type = "saving";
                cout<<"enter the name of account holder : "<<endl;
                cin>>name;
                cout<<"enter the account number of candidate : "<<endl;
                cin>>accno;
                cout<<"enter the balance : "<<endl;
                cin>>balance;
            }
        void check();
        void deposit();
        void display();

};

void bank :: deposit()
{
    long int amount;
    cout<<"how much money do you want to deposit : "<<endl;
    cin>>amount;
    balance=balance+amount;
}

void bank :: check()
{
    long int amnt;
        cout<<"how much money do you want to withdraw : "<<endl;
        cin>>amnt;
    if (balance>amnt)
    {
        balance=balance-amnt;
    }
    else
    cout<<"you have unsufficient balance that you cant withdraw money :"<<endl;
}

void bank :: display()
{
    cout<<"name of candidate is "<<name<<endl;
    cout<<"account no. :"<<accno<<endl;
    cout<<"account type : "<<acc_type<<endl;
    cout<<"total balance in your account is Rs. "<<balance<<endl;
}

int main()
{
    bank candidate;
    candidate.setdata();
    candidate.deposit();
    candidate.check();
    candidate.display();
}

output :

enter the name of account holder : Rahul enter the account number of candidate : 324 enter the balance : 700 how much money do you want to deposit : 200 how much money do you want to withdraw : 500 name of candidate is Rahul account no. :324 account type : saving total balance in your account is Rs. 400

Comments

Popular Post

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y