Menu Driven Bank System Program in C++

 Banking System Program to Demonstrate Class, Constructor and Destructor




A simple banking system in which intital balance ans rate of interest are read through keyboard and these values are initialized using constructor member function. The destructor member function is defined in this program to destroy the class objects created using constructor.

The program consist of the following methods,

Initialize the balance and rate of interest using constructor

make deposit

Withdraw an amount

Find the compound interest

Know the balance amount

Display the menu options

Destroy the object of class


#include<iostream.h>

#include<stdio.h>

#include<conio.h>

class bank_system

{

private:

float balance;

float rate;

public:

bank_system(); //constructor

~bank_system(); //destructor

void deposit();

void withdraw();

void compound();

void balance();

void menu();

}; //end of class definition

bank_system::bank_system() //constructor

{

cout<<”Enter initial balance”<<endls;

cin>>balance;

cout<<”Rate of Interest”<<endl;

cin<<rate;

}

bank_system::~bank_system() //destructor

{

cout<<”Release data”<<endl;

}

//Deposit function

void bank_system::deposit()

{

float amount;

cout<<”Enter amount”<<endl;

cin<<amount;

balance=balance+amount;

}

//Withdraw amount

void bank_system::withdraw()

{

float amount;

cout<<”How much amount you want to withdraw”<<endl;

cin>>amount;

if(amount<=balance)

{

balance=balance-amount;

cout<<”The amount withdrawn” <<amount;<<endl;

cout<<”Current balance is” <<balance<<endl;

}

else

{

cout<<0;

}

//coumpound interest

void bank_system::compound()

{

float interest;

interest=balance*rate;

balance=balance_interest;

cout<<”Interest amount is” <<interest<<endl;

cout<<”Total amountis” <<balance <<endl;

}

//get current balance

void bank_system::balance()

{

cout<<”The current balance is” <<balance<<endl;

}

//Menu

void bank_system::menu()

{

cout<<”Deposit   -> d  ”<<endl;

cout<<”Withdraw -> w”<<endl;

cout<<”Compound Interest -> c”<<endl;

cout<<”Get Balance -> b”<<endl;

cout<<” Exit -> q”<<endl;

cout<<” Enter your option”<<endl;

}

void main()

{

bank_system obj;

char ch;

obj.menu();

while((ch=getchar())!=’q’)

{

switch(ch)

{

case ‘d’ :

obj.deposit();

break;

case ‘w’ :

obj.withdraw();

break;

case ‘c’ :

obj.compound();

break;

case ‘b’ :

obj.balance();

break;

}//end of switch case

}//end of while

}//end of main program  


टिप्पणी पोस्ट करा

0 टिप्पण्या