CONSTRUCTOR AND DESTRUCTOR USING C++
/*BANK OPERATION USIN CONSTRUCTOR AND DESTRUCTOR*/
PROGRAM:
d->deposit
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class account
{
private:
float balance;
float rate;
public:
account();
~account();
void deposit();
void withdraw();
void compound();
void getbalance();
void menu();
};
account::account()
{
cout<<"\n\t BANK OPERATION USIN CONSTRUCTOR AND DESTRUCTOR ";
cout<<"\n\t _______________________________________________\n";
cout<<"\n Enter the initial balance:\n";
cin>>balance;
cout<<"\n Interest rate:\n";
cin>>rate;
}
account::~account()
{
cout<<"\n Database has been deleted\n";
}
void account::deposit()
{
float amount;
cout<<"\n Enter the amount:";
cin>>amount;
balance=balance+amount;
cout<<"\n Current balance="<<balance;
}
void account::withdraw()
{
float amount;
cout<<"\n How much to withdraw? :\n";
cin>>amount;
if(amount<=balance)
{
balance=balance-amount;
cout<<"\n Amount drawn="<<amount<<endl;
cout<<"\n Current balance="<<balance<<endl;
}
else
cout<<0;
}
void account::compound()
{
float interest;
interest=balance*rate;
balance=balance+interest;
cout<<"\n Interest amount="<<interest<<endl;
cout<<"\n Total amount="<<balance<<endl;
}
void account::getbalance()
{
cout<<"\n Current balance=";
cout<<balance<<endl;
}
void account::menu()
{
cout<<"\n d->deposit"<<endl;
cout<<"\n w->withdraw"<<endl;
cout<<"\n c->compound interest"<<endl;
cout<<"\n g->getbalance"<<endl;
cout<<"\n q->quit"<<endl;
cout<<"\n option please ?:\n";
}
void main(void)
{
class account acct;
char ch;
clrscr();
acct.menu();
while((ch = getchar())!= 'q')
{
switch(ch)
{
case 'd':
acct.deposit();
break;
case 'w':
acct.withdraw();
break;
case 'c':
acct.compound();
break;
case 'g':
acct.getbalance();
break;
}
}
getch();
}
OUTPUT:
BANK OPERATION USIN CONSTRUCTOR AND DESTRUCTOR
________________________________________________________
Enter the initial balance:
1000
Interest rate:
0.2
w->withdraw
c->compound interest
g->getbalance
q->quit
option please ?:
d
Enter the amount:1000
Current balance=2000
g
Current balance=2000
w
How much to withdraw? :
500
Amount drawn=500
Current balance=1500
c
Interest amount=300
Total amount=1800
q
Database has been deleted
Comments
Post a Comment