Bank Account

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

#include <iostream>

#include<string>
using namespace std;

class BankAccount {
private:
string accountNumber;
string accountHolderName;
double balance;

public:
void initAccount_1(string accNumber, string accHolderName,double initialBalance)
{
accountNumber = accNumber;
accountHolderName = accHolderName;
balance = initialBalance;
}

void initialAccount_2()
{
cout<<" Enter the account number :"<<endl;
cin>>accountNumber;
cout<<" Enter the account holder name:"<<endl;
cin>>accountHolderName;
cout<<" enter the balance :"<<endl;
cin>>balance;
}

void initAccount(string accNumber,string accHolderName,double initialBalance)


{
accountNumber=accNumber;
accountHolderName=accHolderName;
balance=initialBalance;
}

void deposit(double amount)


{
if(amount>0)
{
balance+=amount;
cout<<"deposited Rs."<<amount<<"into the account"<<endl;
}
else
{
cout<<"invalid amount for deposit"<<endl;
}
}
void withdraw(double amount)
{
if (amount > 0 && amount <= balance)
{
balance -= amount;
cout << "Withdraw Rs." << amount << " from the account" << endl;
}
else
{
cout << "Invalid amount for withdrawal or insufficient balance" << endl;
}
}

void display()
{
cout<<" Account Number :"<<accountNumber<<endl;
cout<<" account Holder Name :"<<accountHolderName<<endl;
cout<<" balance :"<<balance<<endl;
}
};

int main()

{
string an;
string ahn;
double bal;

BankAccount myAccount;
cout<<" Enter the account number :"<<endl;
cin>>an;
cout<<" enter the account holder name:"<<endl;
cin>>ahn;
cout<<" enter the balance :"<<endl;
cin>>bal;
myAccount.initAccount_1(an,ahn,bal);
//myAccount.init_Account_2();
myAccount.deposit(500.0);
myAccount.withdraw(200.0);
myAccount.display();
return 0;

You might also like