The program is a Bank Management System implemented using class and inheritance in C++. The program defines two types of accounts: saving account and current account. The user is prompted to enter the account type, and based on the input, the program creates an object of the corresponding class.
The account class is the base class, and it has three private member variables: name, accno, and atype. It contains two member functions: getAccountDetails() to get the account details from the user and displayDetails() to display the account details.
The current_account class and saving_account class both inherit from the account class. They have their own private member variables: balance and sav_balance, respectively, and their own member functions: c_deposit(),c_withdraw(),c_display(),s_deposit(),s_withdraw(), and s_display() for performing deposit, withdrawal, and balance checking operations for the current account and saving account.
The program prompts the user to enter their choice of operation to be performed on the account, and then calls the corresponding member function of the respective account object based on the user input. Finally, the program exits after thanking the user for banking with them.
The program uses switch statements for user choice inputs, while loops to keep prompting the user until they choose to exit, and the goto statement to exit the program when the user chooses the "Exit" option.
#include<iostream> using namespace std; //Bank Management System using Class & inheritance in C++ /* 1.Saving Account 2.current Account Account Creation Deposit Withdraw 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; 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 > 1000) { balance=balance-withdraw; cout<<"\nBalance Amount After Withdraw: "<<balance; } else { cout<<"\n Insufficient Balance"; } } }; class saving_account : public account { private: float sav_balance; 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 > 500) { sav_balance=sav_balance-withdraw; cout<<"\nBalance Amount After Withdraw: "<<sav_balance; } else { cout<<"\n Insufficient Balance"; } } }; int main() { current_account c1; saving_account s1; char type; cout<<"\nEnter S for saving customer and C for current a/c customer : "; cin>>type; int choice; 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; }
Enter S for saving customer and C for current a/c customer : s Enter Customer Name : Siva Enter Account Number : 123 Enter Account Type : Saving Choose Your Choice 1) Deposit 2) Withdraw 3) Display Balance 4) Display with full Details 5) Exit Enter Your choice: 1 Enter amount to Deposit : 1500 Choose Your Choice 1) Deposit 2) Withdraw 3) Display Balance 4) Display with full Details 5) Exit Enter Your choice: 3 Balance : 1530 Choose Your Choice 1) Deposit 2) Withdraw 3) Display Balance 4) Display with full Details 5) Exit Enter Your choice: 4 Customer Name : Siva Account Number : 123 Account Type : Saving Balance : 1530 Choose Your Choice 1) Deposit 2) Withdraw 3) Display Balance 4) Display with full Details 5) Exit Enter Your choice: 2 Balance :- 1530 Enter amount to be withdraw : 500 Balance Amount After Withdraw: 1030 Choose Your Choice 1) Deposit 2) Withdraw 3) Display Balance 4) Display with full Details 5) Exit Enter Your choice: 5 Thank You for Banking with us..To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions