HOME

Thursday, July 7, 2016

Programm using static data member,class and member functions , to check balance, deposit and withdraw in c++

/* wap a program using class named as Bank, with a static data member
and deposit,withdraw and check balance member functions to deposit and
withdraw or check balance respectively; apply conditions *
--ameer tataroo ameer, no copyrights.. do what ever you want to do with this
if you face any problem contact me on ameertataruu@gmail.com */
#include <iostream>
#include <iomanip>// for setw function
#include <conio.h>//for getch() function
#include <windows.h>//for system() function
using namespace std;
class bank
{
    static double amount_in;//i declared the static variable inside class
public :
    void withdraw()
    {
        system("cls");
        double withd;
        cout<<"how much amount do you want to withdraw\n";
        cin>>withd;
        if(amount_in>500)
        {
            amount_in = amount_in - withd;
        cout<<"\n you have successfully withdrawn "<<setw(10)<<withd;//setw(10)is used instead of \t
        cout<<"\n your remaining balance is "<<setw(10)<<amount_in;

        }
        else {
                cout<<"\n your current account balance is "<<setw(10)<<amount_in;
          cout<<"\n you should maintain minimum of "<<setw(10)<<amount_in;
        }
    }
    void deposit()
    {
        system("cls");
        double dep;
        cout<<"\n how much amount do you want to deposit "<<setw(10);
        cin>>dep;
              if(dep <= 5000)
              {
                  amount_in = amount_in + dep;
                  cout<<"\n amount successfully deposited and new balance is "<<setw(10)<<amount_in;
              }
              else {
                cout<<"\n sorry amount entered exceeds the limit ";
              }
    }
    void check()
    {
        cout<<"\n your current balance is "<<setw(10)<<amount_in;
    }
};
double bank::amount_in=500; //i defined the static variable which was defined in the class here
int main()
{
    system("title simple withdraw and deposit using static variable");
    bank b;
     char c,h;
   start : system("cls");
   cout<<"-----------welcome to bank management system---------";
     cout<<"\n\n\na.withdraw\tb.check balance\nc.deposit\n\n\n";
     c=getch();
     switch (c)
     {
     case 'a':
    b.withdraw();
    break;
     case 'b':
        b.check();
        break;
     case 'c':
        b.deposit();
        break;
     default:
        cout<<"\n\n-------wrong option terminating transaction-----\n";

     }
     cout<<"\n\n\n\t want to check balance or continue with another transaction ?(y/n)\n\n ";
     h=getch();
     if(h=='y'||h=='Y')
     {
         goto start;
     }

    return 0;
}