Bankaccount

You might also like

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

#include <iostream>

#include<string>
using namespace std;

class BankAccount{
int accountNumber;
string Name;
double balance;

public:
int getaccountNumber(){
return accountNumber;
}
string getName(){
return Name;
}
double getbalance(){
return balance;
}
void setaccountNumber(int num) {
accountNumber = num;
}
void setName( string name) {
Name = name;
}
void setbalance(double bal){
balance = bal;
}
void deposit(double amount) {
if (amount > 0) {
balance += amount;
cout << "Deposited $" << amount <<endl;
} else {
cout << "Invalid deposit amount" <<endl;
}
}
void withdraw(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
cout << "Withdrawn $" << amount <<endl;
} else if (amount <= 0) {
cout << "Invalid withdrawal amount." <<endl;
} else {
cout << "Insufficient balance"<<amount <<endl;
}
}
};
int main(){
BankAccount t1;
t1.setaccountNumber(2025);
cout<<"account number: ";
cout<<t1.getaccountNumber()<<endl;
t1.setName("vaishnavi");
cout<<" account owner name: ";
cout<<t1.getName()<<endl;
t1.setbalance(50000);
cout<<"balance: ";
cout<<t1.getbalance()<<endl;
int choice;
double amount;

while(true){
cout<<"menu"<<endl;
cout<<"1:deposite money"<<endl;
cout<<"2:withdraw money"<<endl;
cout<<"3:display balance"<<endl;
cout<<"4:exit"<<endl;
cout<<"enter choice"<<endl;
cin>>choice;

switch(choice){
case 1:
cout<<"enter amount to deposite: ";
cin>>amount;
t1.deposit(amount);
break;
case 2:
cout << "Enter the amount to withdraw: $";
cin >> amount;
t1.withdraw(amount);
break;
case 3:
cout <<"balance" <<t1.getbalance()<<endl;
break;

case 4:
cout << "Exiting the program." << endl;
return 0;
default:
cout << "Invalid choice "<<endl;
}
}

You might also like