#include <iostream>
#include <string>
using namespace std;
// Bank Management System using Class & Inheritance in C++
/*
1. Saving Account
2. Current Account
3. Account Creation
4. Deposit
5. Withdraw
6. Balance
*/
class account {
private:
string name;
int accno;
string atype;
public:
void getAccountDetails() {
cout << "\nEnter Customer Name : ";
cin >> name;
cout << "Enter Account Number : ";
cin >> accno;
cout << "Enter Account Type : ";
cin >> atype;
}
void displayDetails() {
cout << "\n\nCustomer Name : " << name;
cout << "\nAccount Number : " << accno;
cout << "\nAccount Type : " << atype;
}
};
class current_account : public account {
private:
float balance = 0;
public:
void c_display() {
cout << "\nBalance : " << balance;
}
void c_deposit() {
float deposit;
cout << "\nEnter amount to Deposit : ";
cin >> deposit;
balance = balance + deposit;
}
void c_withdraw() {
float withdraw;
cout << "\n\nBalance : " << balance;
cout << "\nEnter amount to be withdraw : ";
cin >> withdraw;
if (balance >= withdraw && balance > 1000) {
balance = balance - withdraw;
cout << "\nBalance Amount After Withdraw: " << balance;
} else {
cout << "\nInsufficient Balance";
}
}
};
class saving_account : public account {
private:
float sav_balance = 0;
public:
void s_display() {
cout << "\nBalance : " << sav_balance;
}
void s_deposit() {
float deposit, interest;
cout << "\nEnter amount to Deposit : ";
cin >> deposit;
sav_balance = sav_balance + deposit;
interest = (sav_balance * 2) / 100;
sav_balance = sav_balance + interest;
}
void s_withdraw() {
float withdraw;
cout << "\nBalance : " << sav_balance;
cout << "\nEnter amount to be withdraw : ";
cin >> withdraw;
if (sav_balance >= withdraw && sav_balance > 500) {
sav_balance = sav_balance - withdraw;
cout << "\nBalance Amount After Withdraw: " << sav_balance;
} else {
cout << "\nInsufficient Balance";
}
}
};
int main() {
current_account c1;
saving_account s1;
char type;
int choice;
cout << "\nEnter S for saving customer and C for current a/c customer : ";
cin >> type;
if (type == 's' || type == 'S') {
s1.getAccountDetails();
while (1) {
cout << "\nChoose Your Choice" << endl;
cout << "1) Deposit" << endl;
cout << "2) Withdraw" << endl;
cout << "3) Display Balance" << endl;
cout << "4) Display with full Details" << endl;
cout << "5) Exit" << endl;
cout << "Enter Your choice: ";
cin >> choice;
switch (choice) {
case 1:
s1.s_deposit();
break;
case 2:
s1.s_withdraw();
break;
case 3:
s1.s_display();
break;
case 4:
s1.displayDetails();
s1.s_display();
break;
case 5:
goto end;
default:
cout << "\n\nEntered choice is invalid, TRY AGAIN";
}
}
}
else if (type == 'c' || type == 'C') {
c1.getAccountDetails();
while (1) {
cout << "\nChoose Your Choice" << endl;
cout << "1) Deposit" << endl;
cout << "2) Withdraw" << endl;
cout << "3) Display Balance" << endl;
cout << "4) Display with full Details" << endl;
cout << "5) Exit" << endl;
cout << "Enter Your choice: ";
cin >> choice;
switch (choice) {
case 1:
c1.c_deposit();
break;
case 2:
c1.c_withdraw();
break;
case 3:
c1.c_display();
break;
case 4:
c1.displayDetails();
c1.c_display();
break;
case 5:
goto end;
default:
cout << "\n\nEntered choice is invalid, TRY AGAIN";
}
}
}
else {
cout << "\nInvalid Account Selection";
}
end:
cout << "\nThank You for Banking with us..";
return 0;
}