Thursday, June 16, 2011

Source Code for Banking Management System(In WinBgim Graphics Library)

#include<graphics.h>
#include<string>
#include<ctime>
#include<cstdio>
#include<fstream>
using namespace std;

#define UNPUSHED 0
#define PUSHED 1

#define BEFORE 1
#define AFTER 0

///////////////////////////////FUNCTION PROTOTYPES

void introduction();
void next_button();
void exit_test();
void back_to_menu();
void working_space();
void our_zone();
struct tm get_date();       //return type is a structure tm
void menu_help(int);
void delaysharp(bool& broken);
void get_s(int x,int y,char temp[]);
float to_float(char []);
void get_n(int,int,char []);
void testing();
void clear_text_box();
int goto_main();
class button
{
      int left,top,right,bottom;
      char tag[25];
      bool flag;
      int button_no;
      static int chooser;
      public:
             button(){}
             button(int lt,int tp,int rt,int bt,char tg[],bool fg,int no){
                        left=lt;      top=tp;
                        right=rt;     bottom =bt;
                        strcpy(tag,tg);
                        flag=fg;
                        button_no=no;
                        }
             static void choose(int i)
             {
                    chooser=i;
             }
             void make_button();
             bool test_click(int ,int);
             bool test_hover(int ,int,int);
};

class logon
{
      private:
              int accno;
              char name[10];
              char password[10];
              char handler;                   //bank customer 'C' or officer 'O'
      public:
             void change_password(int);
             void new_account(int,char);
             void delete_account(int);
             bool entry(int &meth,int &acno);
};

class interest
{
      private:
              int accno;
              float total_intr;
      public:
              void give_interest(int recno,float &intr);
              void reset_interest(int recno);
              void new_interest(int t_accno);
};

class account_info
{
      private:
             void draw_table();
             void modify_account(int, char t_name[30], char t_address[30]);     // Function to modify the customer account

             int accno;
             char name[30], address[30];
             float balance;
      public:
            void add_to_file(int, char t_name[30], char t_address[30], float);        // For brie info of customers
            void display_list(void);   // Displaying customers account list
            void delete_account(int);  // Deleting customers account
            void update_balance(int t_accno,float t_balance);     // For updating the customer account
            void edit(void);            // To modify or close the customer account information
            void modify(int);           // To modify the customer account information
            int last_accno(void);         // To know the last account number
            bool find_account(int);       // To find if the account is in "account_info.txt" or not
            void calculate_interest();    //to find daily interest
            float give_balance(int);     // To give current balance amount of a particular customer
            int recordno(int);
            int accountno(int recno);
            void display(int);           // To display the customer account
            void forex();
            void draw_table1();
};

class account
{
     public:
          void new_account(void);           // Function to create a new account
          void close_account(int);          // Function to close an account
          void display_account(void);       // Function to display the accounts
          void display_account(int &recno);
          void display_pri_account(int &recno);
          void transaction(void);              // To display the transaction process
          void transaction(int acno);
          void transfer(int accno);
          void add_to_file(int, int, int, int, char, char t_type[10], float, float);
                                               // Function to add transaction records
     private:

          void delete_account(int);            // Function to delete a transaction record
          void box_for_display(int);           // Function for displaying box
          int accno;
          char type[6];                        // Account type as Cheque or Cash
          int dd, mm, yy;                      // To store the system date/ Enter date
          char tran;                           // As the account type is Deposit or Withdraw
          float  amount, balance;
};
class menu
{
      public:
             void blank();
             void private_menu(int);
             void control_menu();
             int main_menu();
             int new_menu();
             int view_menu(bool,int=26);
             int trans_menu(bool);
             int edit_close();
             int close_menu();
             int edit_menu();
             int depo_draw();
             int save_trans_menu();
             int main_menu_2();
             int next_menu(bool);

};

class sys_time
{
      char my_date[80];     //arbitary date format
      int dd,mm,yy;         //To store the system date
      struct tm get_date()
      {
             time_t rawtime;
             struct tm *time_details;
             time(& rawtime);                      //get current time in seconds
             time_details=localtime(&rawtime);     //change time into parts defined in structure tm
             return *time_details;
      }
      public:
             void set_date()
             {
                  struct tm from_sys;
                  from_sys=get_date();
                  dd=from_sys.tm_mday;             //day of month
                  mm=from_sys.tm_mon+1;            //month(jan=0 & so on)
                  yy=from_sys.tm_year+1900;        //tm_year=year since 1900 thus we have to add 1900
                                                   //to get current year
                  strftime(my_date,80,"%d %B %Y",& from_sys);    //see time.h
             }
             void show_date(int x,int y)                         //x,y means position
             {
                  outtextxy(x,y,my_date);
             }
             void return_date(int &d,int &m,int &y)              //pass by reference
             {
                  d=dd;
                  m=mm;
                  y=yy;
             }
};
sys_time t1;                                    //global object variable

//////////////////////for class menu
void menu::blank()
{
     int maxx = getmaxx();
     int maxy = getmaxy();
     setviewport(3,92,198,maxy-2,1);
     setbkcolor(WHITE);
     clearviewport();
     setviewport(0,0,maxx,maxy,0);
     our_zone();
}
void menu::control_menu()
{
     int opt;
     bool flag=1;
     account a;
     account_info ini;
     do{
          opt=main_menu();
          blank();
          switch(opt)
          {
                case 1:
                     a.new_account();
                     break;
                case 2:
                     ini.display_list();
                     break;
                case 3:
                     a.transaction();
                     break;
                case 4:
                     ini.edit();
                     break;
                case 5:
                     ini.calculate_interest();
                     break;
                case 6:
                     flag=0;
          }
     }while (flag);


}
void menu::private_menu(int t_accno)
{
     int opt;
     bool flag=1;
     account a;
     account_info ini;
     logon l;
     int recno=ini.recordno(t_accno);
     do{
          opt=main_menu_2();
          blank();
          switch(opt)
          {
                case 1:
                     a.display_pri_account(recno);
                     break;
                case 2:
                     a.transfer(t_accno);
                     break;
                case 3:
                     l.change_password(t_accno);
                     break;
                case 4:
                     flag=0;

          }
     }while (flag);


}
int menu::main_menu()
{
     //make menu buttons
     button b1(20,130,180,155,"NEW ACCOUNT",UNPUSHED,1);
     button b2(20,175,180,200,"VIEW ACCOUNTS",UNPUSHED,2);
     button b3(20,220,180,245,"TRANSACTIONS",UNPUSHED,3);
     button b4(20,265,180,290,"EDIT ACCOUNT",UNPUSHED,4);
     button b5(20,310,180,335,"INTEREST",UNPUSHED,5);
     button b6(20,355,180,380,"EXIT",UNPUSHED,6);
     blank();
     b1.make_button();
     b2.make_button();
     b3.make_button();
     b4.make_button();
     b5.make_button();
     b6.make_button();
     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           if(ismouseclick(WM_MOUSEMOVE))
                                           {
                                           getmouseclick(WM_MOUSEMOVE,mousex,mousey);
                                           if(b1.test_hover(mousex,mousey,1))               break;
                                           else if(b2.test_hover(mousex,mousey,2))          break;
                                           else if(b3.test_hover(mousex,mousey,3))          break;
                                           else if(b4.test_hover(mousex,mousey,4))          break;
                                           else if(b5.test_hover(mousex,mousey,5))          break;
                                           else if(b6.test_hover(mousex,mousey,6))          break;
                                           }
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
        else if(b4.test_click(mousex,mousey))         return 4;
        else if(b5.test_click(mousex,mousey))         return 5;
        else if(b6.test_click(mousex,mousey))         return 6;

     }
     while(!cor_clk);

}

int menu::main_menu_2()
{
     //make menu buttons
     button b1(20,130,180,155,"VIEW DETAILS",UNPUSHED,1);
     button b2(20,175,180,200,"TRANSFER AMOUNT",UNPUSHED,2);
     button b3(20,220,180,245,"CHANGE PASSWORD",UNPUSHED,3);
     button b4(20,265,180,290,"LOG OUT",UNPUSHED,4);

     blank();
     b1.make_button();
     b2.make_button();
     b3.make_button();
     b4.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
        else if(b4.test_click(mousex,mousey))         return 4;

     }
     while(!cor_clk);

}
int menu::new_menu()
{
     //make menu buttons
     button b1(20,130,180,155,"SAVE ENTRY",UNPUSHED,0);
     button b2(20,175,180,200,"CHANGE ENTRY",UNPUSHED,0);
     button b3(20,220,180,245,"MAIN MENU",UNPUSHED,0);

     blank();
     b1.make_button();
     b2.make_button();
     b3.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
     }
     while(!cor_clk);
}
int menu::view_menu(bool f,int row)
{
    int recno;
     //make menu buttons
     button b1(20,130,180,155,"INDIVIDUAL A/C",UNPUSHED,0);
     button b2(20,175,180,200,"MAIN MENU",UNPUSHED,0);
     button b3(20,220,180,245,"NEXT PAGE",UNPUSHED,0);
    // button b4(20,265,180,290,"EXIT",UNPUSHED,0);
     blank();
     b1.make_button();
     b2.make_button();
     //b4.make_button();
     if (f)
        b3.make_button();
    //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN )&&!ismouseclick(WM_LBUTTONDBLCLK))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(f && b3.test_click(mousex,mousey))    return 3;
        //else if(b4.test_click(mousex,mousey));   return 4;
        getmouseclick(WM_LBUTTONDBLCLK,mousex,mousey);

        if(mousex>245&&mousex<450)
        {
                                 if(mousey>144&&mousey<(108+18*row))               //144=108+18*2
                                                        return mousey;
        }
     }
     while(!cor_clk);
}
int menu::trans_menu(bool f)
{
     //make menu buttons
     button b1(20,130,180,155,"EDIT",UNPUSHED,0);
     button b2(20,175,180,200,"TRANSACTIONS",UNPUSHED,0);
     button b3(20,220,180,245,"CLOSE ACCOUNT",UNPUSHED,0);
     button b4(20,265,180,290,"MAIN MENU",UNPUSHED,0);
     button b5(20,310,180,335,"NEXT PAGE",UNPUSHED,0);


     blank();
     b1.make_button();
     b2.make_button();

     b3.make_button();
     b4.make_button();
     if (f)
        b5.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
        else if(b4.test_click(mousex,mousey))         return 4;
        else if(f && b5.test_click(mousex,mousey))    return 5;

     }
     while(!cor_clk);

}
int menu::edit_close()
{
      //make menu buttons
     button b1(50,130,150,155,"EDIT",UNPUSHED,0);
     button b2(50,175,150,200,"CLOSE",UNPUSHED,0);
     button b3(50,220,150,245,"CANCEL",UNPUSHED,0);

     blank();
     b1.make_button();
     b2.make_button();
     b3.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
     }
     while(!cor_clk);
}
int menu::close_menu()
{
     button b1(50,130,150,155,"CLOSE",UNPUSHED,0);
     button b2(50,175,150,200,"CANCEL",UNPUSHED,0);

     blank();
     b1.make_button();
     b2.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
     }
     while(!cor_clk);
}

int menu::edit_menu()
{
     button b1(50,130,150,155,"EDIT",UNPUSHED,0);
     button b2(50,175,150,200,"CANCEL",UNPUSHED,0);
     blank();
     b1.make_button();
     b2.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
     }
     while(!cor_clk);
}
int menu::depo_draw()
{
     //make menu buttons
     button b1(20,130,180,155,"DEPOSIT",UNPUSHED,0);
     button b2(20,175,180,200,"WITHDRAW",UNPUSHED,0);
     button b3(20,220,180,245,"MAIN MENU",UNPUSHED,0);

     blank();
     b1.make_button();
     b2.make_button();
     b3.make_button();

     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;
        else if(b3.test_click(mousex,mousey))         return 3;
     }
     while(!cor_clk);
}
int menu::save_trans_menu()
{
     button b1(50,130,150,155,"SAVE",UNPUSHED,0);
     button b2(50,175,150,200,"CANCEL",UNPUSHED,0);

     blank();
     b1.make_button();
     b2.make_button();
     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(b2.test_click(mousex,mousey))         return 2;

     }
     while(!cor_clk);
}
int menu::next_menu(bool f)
{
     button b1(20,130,180,155,"MAIN MENU",UNPUSHED,0);
     button b2(20,175,180,200,"NEXT PAGE",UNPUSHED,0);

     blank();
     b1.make_button();
     if(f)
          b2.make_button();
     //test if a button is clicked
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))
        {
                                           delay(1);
        }

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here

        if(b1.test_click(mousex,mousey))              return 1;
        else if(f&&b2.test_click(mousex,mousey))      return 2;

     }
     while(!cor_clk);
}

/////////////////////////////////////for class logon
void logon::new_account(int t_accno,char diff)
{
     fstream file;
     file.open("LOGON.txt",ios::out|ios::app|ios::binary);
     accno=t_accno;
     sprintf(name,"%d",t_accno);
     sprintf(password,"%d",t_accno);
     handler=diff;
     //strcpy(name,"TELLER");
     //strcpy(password,"BANK");
     file.write(reinterpret_cast<char*>(this),sizeof(logon));
     file.close();
}

void get_pass(int x,int y,char  temp[])
{
     char temp2[10];
     setcolor(COLOR(0,150,0));
     rectangle(x-5,y-2,x+250,y+20);
     setfillstyle(SOLID_FILL,WHITE);
     floodfill(x+5,y+5,COLOR(0,150,0));
     char input;
     temp[0]='\0';
     temp2[0]='\0';
     int i=0,j=0;
     bool broken=false;

     setcolor(BLACK);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setbkcolor(WHITE);
     do{
                       //for cursor blinking
          while(!kbhit())
          {
                         j=textwidth(temp);                              //wrong strlen(temp);
                         outtextxy(x+j,y,"|");
                         delaysharp(broken);
                         if(broken)
                                   break;


                         outtextxy(x+j,y,"  ");
                         delaysharp(broken);
          }
          input=getch();


          if(input=='\b')
              i-=2;

          else if(input=='\r'||input=='\t')
          {
               outtextxy(x+j,y," ");
               i--;
          }

          else
          {
               temp[i]=input;
               temp2[i]='*';
          }

          temp[++i]='\0';
          temp2[i]='\0';
          floodfill(x+5,y+5,COLOR(0,150,0));
          outtextxy(x,y,temp2);
          if(i<0)             i=0;

     }
     while(input!='\r'&& input!='\t');         //until tab or enter is pressed

}
bool logon::entry(int &meth,int &acno)
{
     char ch_name[10],ch_pass[10];

     setfillstyle(SOLID_FILL,COLOR(190,200,230));
     floodfill(50,50,RED);
     setbkcolor(COLOR(190,200,230));
     setcolor(COLOR(0,0,0));
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);

     outtextxy(215,100,"PROVIDE YOUR NAME / ACCOUNT NO AND PASSWORD ");
     outtextxy(215,200,"USERNAME(A/C NO) :");
     outtextxy(215,230,"PASSWORD         :");
     get_s(410,200,ch_name);
     get_pass(410,230,ch_pass);
     fstream file;
     file.open("LOGON.txt",ios::in|ios::binary);
     file.read(reinterpret_cast<char*>(this),sizeof(logon));
     while(file)
     {
                if(strcmp(ch_name,name)==0&&strcmp(ch_pass,password)==0)
                {
                                                                  if(handler=='O')        //officer
                                                                            meth=1;
                                                                  else
                                                                  {
                                                                       meth=2;
                                                                       acno=accno;
                                                                  }

                                                                  return 1;
                }
                file.read(reinterpret_cast<char*>(this),sizeof(logon));
     }
     file.close();
     return 0;

}
void logon::delete_account(int t_accno)
{
     fstream file;
     fstream temp;
     file.open("LOGON.txt",ios::in|ios::binary);
     temp.open("TEMP.txt",ios::out|ios::binary);
     file.seekg(0,ios::beg);
     temp.seekp(0,ios::beg);
     file.read(reinterpret_cast<char*>(this),sizeof(logon));
     while(file)
     {
                if(accno!=t_accno)
                              temp.write(reinterpret_cast<char*>(this),sizeof(logon));
                file.read(reinterpret_cast<char*>(this),sizeof(logon));
     }
     file.close();
     temp.close();
     remove("LOGON.txt");
     rename("TEMP.txt","LOGON.txt");

}
void logon::change_password(int t_accno)
{
     bool flag;
     char oldpass[10],newpass[10],conpass[10];
     clear_text_box();
     fstream file;
     file.open("LOGON.txt",ios::in|ios::out|ios::binary);
     file.seekg(0,ios::beg);
     int count = 0;

     do
     {
          setcolor(BLACK);
          setbkcolor(WHITE);
          setusercharsize(1,1,2,1);
          settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
          settextjustify(LEFT_TEXT,TOP_TEXT);
          outtextxy(260,120,"OLD PASSWORD     :");
          outtextxy(260,150,"NEW PASSWORD     :");
          outtextxy(260,180,"CONFIRM PASSWORD :");
          get_pass(510,120,oldpass);
          get_pass(510,150,newpass);
          get_pass(510,180,conpass);
          clear_text_box();
          file.read(reinterpret_cast<char*>(this),sizeof(logon));
          while(file)
          {
                count++;
                if(accno==t_accno)
                                  break;
                file.read(reinterpret_cast<char*>(this),sizeof(logon));
          }
          if(strcmp(oldpass,password)!=0)
          {
                   setcolor(COLOR(190,0,0));
                   outtextxy(260,80,"ERROR : WRONG PASSWORD ENTERED");
                   flag=1;
          }
          else if(strcmp(newpass,conpass)!=0)
          {
                   setcolor(COLOR(190,0,0));
                   outtextxy(260,80,"ERROR : CONFIRM PASSWORD DOES NOT MATCH WITH THE NEW PASSWORD");
                   flag=1;
          }
          else flag=0;

     }while(flag);

     strcpy(password,newpass);
     int location=(count-1)*sizeof(logon);
     file.seekp(location,ios::beg);
     file.write(reinterpret_cast<char*>(this),sizeof(logon));
     file.close();
     setcolor(COLOR(190,0,0));
     outtextxy(260,180,"PASSWORD HAS BEEN CHANGED SUCCESSFULLY");
     back_to_menu();
     clear_text_box();
}

//////////////////////////////////for class interest
//for new account opened
void interest:: new_interest(int t_accno)
{
     fstream file;
     file.open("INTEREST.txt",ios::out|ios::app|ios::binary);
     total_intr=0.0;
     file.write(reinterpret_cast<char*>(this), sizeof(interest));
     file.close();
}
void interest:: give_interest(int recno,float &intr)
{
     fstream file;
     file.open("INTEREST.txt",ios::out|ios::in|ios::binary);
     int location=(recno-1)*sizeof(interest);
     file.seekg(location,ios::beg);
     file.read(reinterpret_cast<char*>(this), sizeof(interest));
     total_intr+=intr;
     intr=total_intr;
     file.seekp(location,ios::beg);
     file.write(reinterpret_cast<char*>(this), sizeof(interest));
     file.close();
}
//for new month
void interest:: reset_interest(int recno)
{
     fstream file;
     file.open("INTEREST.txt",ios::out|ios::in|ios::binary);
     int location=(recno-1)*sizeof(interest);
     file.seekg(location,ios::beg);
     file.read(reinterpret_cast<char*>(this), sizeof(interest));
     total_intr=0.0;
     file.seekp(location,ios::beg);
     file.write(reinterpret_cast<char*>(this), sizeof(interest));
     file.close();
}

//////////////////////////////////////for class account_info
//find if an aount exists
bool account_info::find_account(int t_accno)
{
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     file.seekg(0, ios::beg);
     bool found = 0;

     // Searches the specified record in account_info.txt data file
     file.read(reinterpret_cast<char*>(this), sizeof(account_info));
     while (file)
     {
          if (accno == t_accno)
          {
               found = 1;
               break;
          }
          file.read(reinterpret_cast<char*>(this), sizeof(account_info));
     }
     file.close();
     return found;
}
// Function to find the last account number
int account_info::last_accno(void)
{
     int count=0;
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     if(!file)                              //for first use
              return 0;

     file.seekg(0, ios::beg);               //else take to beginning(0 bits from beginning
     //search through all acc till last and then take its acc no
     file.read((char *)this, sizeof(account_info));
     while (!file.eof())
     {
               count = accno;
               file.read((char *)this, sizeof(account_info));
     }
     file.read((char *)this, sizeof(account_info));
     count =accno;
     file.close();
     return count;
}

/* This function add_to_file() is used to create new/fresh record in the data file */
void account_info::add_to_file(int t_accno, char t_name[30], char t_address[30], float t_balance)
{
     accno = t_accno;
     strcpy(name, t_name);
     strcpy(address, t_address);
     balance = t_balance;
     fstream file;

     // Appends new account record with the balance into account_info.txt data file
     file.open("account_info.txt", ios::out|ios::binary|ios::app);
     file.write((char *)this, sizeof(account_info));
     file.close();

}
//TABLE FOR DISPLAY
void account_info::draw_table()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     clear_text_box();
     setcolor(COLOR(75,0,150));
     setusercharsize(2,1,1,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(CENTER_TEXT,TOP_TEXT);
     setbkcolor(WHITE);

     outtextxy(503,72,"EXISTING ACCOUNT LIST");
     outtextxy(230,90,"A/C");
     outtextxy(230,108,"NO");
     outtextxy(348,90,"NAME");
     outtextxy(560,90,"ADDRESS");
     outtextxy(730,90,"BALANCE");
     setlinestyle(SOLID_LINE,0,NORM_WIDTH );
     //to make table
     line(210,88,790,88);
     line(210,124,790,124);
     line(210,88,210,576);
     line(245,88,245,576);
     line(450,88,450,576);
     line(670,88,670,576);
     line(790,88,790,576);
     line(210,576,790,576);         //576=108+18*26
}
void account_info::draw_table1()
{
     int maxx=getmaxx();
     int maxy=getmaxy();

     setcolor(COLOR(75,0,150));
     setusercharsize(2,1,1,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(CENTER_TEXT,TOP_TEXT);
     setbkcolor(WHITE);

     outtextxy(503,72,"Current Exchange Rate   (IN RUPEES)");
     outtextxy(230,90,"S.No");
     //outtextxy(230,108,"Currency");
     outtextxy(320,90,"Currency");
     outtextxy(470,90,"Rate");
     outtextxy(620,90,"Buying Rate");
     outtextxy(830,90,"Selling Rate");
     setlinestyle(SOLID_LINE,0,NORM_WIDTH );
     //to make table
     line(210,88,930,88);
     line(210,124,930,124);
     line(210,88,210,576);
     line(255,88,255,576);
     line(400,88,400,576);
     line(530,88,530,576);
     line(730,88,730,576);
     line(930,88,930,576);
     line(210,576,930,576);         //576=108+18*26
      setcolor(COLOR(180,2,300));
     outtextxy(230,140,"1.");  outtextxy(320,140,"Indian Rs");
     outtextxy(460,140,"100"); outtextxy(620,140,"160.00");
     outtextxy(830,140,"160.15");
     outtextxy(230,190,"2.");  outtextxy(320,190,"US Dollar");
     outtextxy(460,190,"1"); outtextxy(620,190,"73.75");
     outtextxy(830,190,"74");
     outtextxy(230,240,"3.");  outtextxy(320,240,"EURO");
     outtextxy(460,240,"1"); outtextxy(620,240,"92.15");
     outtextxy(830,240,"92.40");
     outtextxy(230,290,"4.");  outtextxy(320,290,"Pound");
     outtextxy(460,290,"1"); outtextxy(620,290,"115.00");
     outtextxy(830,290,"115.25");
     outtextxy(230,340,"5.");  outtextxy(320,340,"Swiss Franc");
     outtextxy(460,340,"1"); outtextxy(620,340,"63.17");
     outtextxy(830,340,"63.42");
     outtextxy(230,390,"6.");  outtextxy(320,390,"Australian $");
     outtextxy(460,390,"1"); outtextxy(620,390,"63.09");
     outtextxy(830,390,"63.34");
     outtextxy(230,440,"7.");  outtextxy(320,440,"Canadian $");
     outtextxy(460,440,"1"); outtextxy(620,440,"70.60");
     outtextxy(830,440,"70.85");
     outtextxy(230,490,"8.");  outtextxy(320,490,"Qatar Riyal");
     outtextxy(460,490,"1"); outtextxy(620,490,"20.20");
     outtextxy(830,490,"20.45");
}
void account_info::display_list(void)
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     float t_bal = 0.0;
     menu m;
     int opt;
     int recno=0;
     account a;
     //to get from file
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     file.seekg(0,ios::beg);
     setbkcolor(WHITE);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     if(!file){
              outtextxy(250,150,"SORRY ! NO ACCOUNTS REGISTERED YET");
              return;
              }
     draw_table();
     // Reads all the records to display on the screen
     char ch_accno[15],ch_bal[15];
     int row=2;
     setcolor(COLOR(50,150,0));
     setbkcolor(WHITE);
     setusercharsize(1,2,1,2);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);

     file.read((char *)this, sizeof(account_info));


     do
     {

          sprintf(ch_accno,"%d",accno);
          sprintf(ch_bal,"%.2f",balance);
          settextjustify(CENTER_TEXT,TOP_TEXT);
          outtextxy(228,108+18*row,ch_accno);
          settextjustify(LEFT_TEXT,TOP_TEXT);
          outtextxy(250,108+18*row,name);
          outtextxy(455,108+18*row,address);
          settextjustify(RIGHT_TEXT,TOP_TEXT);
          outtextxy(785,108+18*row,ch_bal);


          t_bal = t_bal + balance;

          row++;
          file.read((char *)this, sizeof(account_info));
          if(row==26&&!file.eof())
          {
                     row++;
                     sprintf(ch_bal,"%.2f",t_bal);
                     outtextxy(665,108+18*row,"TOTAL AMOUNT");
                     outtextxy(785,108+18*row,ch_bal);
                     opt=m.view_menu(1);
                     m.blank();
                     clear_text_box();
                     switch(opt)
                     {
                                        case 1:
                                             a.display_account();
                                             return;
                                        case 2:
                                             return;
                                        case 3:
                                             break;
                                        default:
                                             recno+=(opt-126)/18;
                                             a.display_account(recno);
                                             return;
                     }
                     //to delete existing list to show new ones

                     draw_table();
                     setcolor(COLOR(50,150,0));
                     setusercharsize(1,2,1,2);
                     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                     row=1;

                     settextjustify(RIGHT_TEXT,TOP_TEXT);
                     outtextxy(665,108+18*row,"B/F");
                     outtextxy(785,108+18*row,ch_bal);
                     row++;
                     recno+=24;

          }


     } while (file);
     file.close();
     sprintf(ch_bal,"%.2f",t_bal);
     outtextxy(665,594,"TOTAL AMOUNT");
     outtextxy(785,594,ch_bal);
     opt=m.view_menu(0,row);
     m.blank();
     clear_text_box();
     switch(opt)
     {
             case 1:

                  a.display_account();
                  return;
             case 2:
                  return;
             case 3:
                  display_list();
             default:
                         recno+=(opt-126)/18;
                         a.display_account(recno);
                         return;

     }
}
// Function for deleting a account from account_info.txt file
void account_info::delete_account(int del_accno)
{
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     fstream temp;
     temp.open("TEMP.txt", ios::out|ios::binary);
     file.seekg(0,ios::beg);
     temp.seekp(0,ios::beg);
     // Uses a copy method to delete the account from INTITAL.txt data file
     //doesn't copy the account details which is to be deleted
     file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     while (!file.eof())
     {
          if (accno != del_accno)
               temp.write(reinterpret_cast<char *>(this), sizeof(account_info));
          file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     }
     file.close();
     temp.close();
     remove("account_info.txt");
     rename("TEMP.txt","account_info.txt");

}

// Function for displaying single account details
void account_info::display(int t_accno)
{
     int maxx=getmaxx();
     int maxy=getmaxy();

     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     file.seekg(0, ios::beg);

     // Displays the record contents matching with t_accno from account_info.txt data file
     file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     while (file)
     {
          char ch_temp[5];
          setbkcolor(WHITE);
          setusercharsize(1,2,1,2);
          settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
          if (t_accno == accno)
          {
                      setcolor(COLOR(50,150,0));
                      settextjustify(LEFT_TEXT,TOP_TEXT);
                      outtextxy(225,90,"ACCOUNT NO :");
                      outtextxy(225,108,"NAME       :");
                      outtextxy(225,126,"ADDRESS    :");
                      outtextxy(225,144,"CURRENT AMT:");

                      sprintf(ch_temp,"%d",t_accno);
                      setcolor(COLOR(30,5,250));
                      outtextxy(350,90,ch_temp);
                      outtextxy(350,108,name);
                      outtextxy(350,126,address);
                      sprintf(ch_temp,"%.2f",balance);
                      outtextxy(350,144,ch_temp);
                      break;
          }
          file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     }
     file.close();
}
// Function for returning the record no. for updating balance */
int account_info::recordno(int t_accno)
{
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     file.seekg(0, ios::beg);
     int count = 0;
     // Finds the record position in account_info.txt data file
     file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     while (file)
     {
          count++;
          if (t_accno == accno)
               break;
          file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     }
     file.close();
     return count;
}
int account_info::accountno(int recno)
{
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     int location=(recno-1)*sizeof(account_info);
     file.seekg(location, ios::beg);
     file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     return accno;
}

void account_info::edit(void)
{
     menu m;
     int opt;
     account a;
     int maxx=getmaxx();
     int maxy=getmaxy();
     char t_name[30], t_address[30];
     int t_accno;
     char ch_acno[5];
     setcolor(BLACK);
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     outtextxy(260,120,"ENTER A/C NO TO BE EDITED :");
     get_n(540,120,ch_acno);
     t_accno=int(to_float(ch_acno));
     if(!find_account(t_accno))
     {
                                    setcolor(COLOR(200,0,0));
                                    setbkcolor(WHITE);
                                    setusercharsize(1,2,1,2);
                                    settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                                    settextjustify(CENTER_TEXT,TOP_TEXT);
                                    outtextxy((210+maxx)/2,300,"NON-EXISTING A/C NO ENTERED");
                                    setcolor(COLOR(250,25,250));
                                    outtextxy((210+maxx)/2,318,"(PRESS ANY KEY TO RETURN TO MENU)");
                                    getch();
                                    clear_text_box();
                                    return;
     }

     clear_text_box();
     display(t_accno);
     setcolor(COLOR(200,50,0));
     outtextxy(260,200,"ABOVE ACCOUNT CAN BE EDITED OR CLOSED");

     opt=m.edit_close();
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     modify(t_accno);
                     return;
                case 2:
                     a.close_account(t_accno);
                     return;
                case 3:
                     return;
     }
}
// Pass parameters to data file
void account_info::modify_account(int t_accno, char t_name[30], char t_address[30])
{
     int recno = recordno(t_accno);
     int location = (recno-1) * sizeof(account_info);
     fstream file;
     file.open("account_info.txt", ios::out|ios::in|ios::binary);
     file.seekg(location);
     file.read(reinterpret_cast<char*>(this),sizeof(account_info));   //get old info
     strcpy(name, t_name);                                            //modify info
     strcpy(address, t_address);
     file.seekp(location);
     file.write(reinterpret_cast<char*>(this),sizeof(account_info)); //account updated
     file.close();
}
void account_info::modify(int modify_acno)
{
     menu m;
     int opt;
     char t_name[30], t_address[30];

     display(modify_acno);
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setcolor(COLOR(200,50,0));
     outtextxy(260,200,"ENTER NEW DETAILS FOR ABOVE ACCOUNT");
     setcolor(BLACK);
     outtextxy(260,230,"NAME            :");
     outtextxy(260,260,"ADDRESS         :");
     get_s(510,230,t_name);
     get_s(510,260,t_address);
     setcolor(COLOR(200,50,0));
     outtextxy(260,300,"WARNING!!!");
     outtextxy(260,318,"ABOVE ACCOUNT DETAILS WILL BE CHANGED PERMANENTLY");
     opt=m.edit_menu();
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     break;
                case 2:
                     return;
     }
     // Pass parameters to data file
     modify_account(modify_acno, t_name, t_address);
}
//Function for updating the balance for the given account no.
void account_info::update_balance(int t_accno,float t_balance)
{
     int recno = recordno(t_accno);
     int location = (recno-1) * sizeof(account_info);     // Find the location in file
     fstream file;
     file.open("account_info.txt", ios::out|ios::in|ios::binary);
     file.seekg(location);                                // go to location
     file.read(reinterpret_cast<char*>(this),sizeof(account_info));   //get old info
     balance = t_balance;
     file.seekp(location);
     file.write(reinterpret_cast<char*>(this),sizeof(account_info)); //account updated
     file.close();
}
float account_info::give_balance(int t_accno)
{
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);
     file.seekg(0, ios::beg);
     float t_balance;

     // Gives the last balance of an individual account
     file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     while (file)
     {
          if (accno == t_accno)
          {
               t_balance = balance;
               break;
          }
          file.read(reinterpret_cast<char *>(this), sizeof(account_info));
     }
     file.close();
     return t_balance;
}
//to calculate daily interest
void account_info::calculate_interest()
{
     account a;
     interest i;
     int t_accno;
     float t_balance,t_interest,rate=6.0,t_tax;
     int recno;
     fstream file;
     file.open("account_info.txt", ios::in|ios::binary);

     int d1, m1, y1;
     t1.return_date(d1,m1,y1);
     file.seekg(0, ios::beg);
     file.read(reinterpret_cast<char*>(this), sizeof(account_info));
     while (file)
     {
           t_accno=accno;
           t_balance=balance;
           t_interest=(t_balance*rate)/(100*365);                   //I=PTR/100->T=1 day=1/365 year
           recno=recordno(t_accno);
           i.give_interest(recno,t_interest);
           if(d1==1)
           {
                    t_balance+=t_interest;
                    a.add_to_file(t_accno,d1,m1,y1,'D',"INTRS",t_interest,t_balance);
                    update_balance(t_accno,t_balance);
                    i.reset_interest(recno);
                    t_tax=t_interest*5/100;           //5% tax payment to goverment
                    t_balance-=t_tax;
                    a.add_to_file(t_accno,d1,m1,y1,'W',"TAXP5",t_tax,t_balance);
                    update_balance(t_accno,t_balance);

           }

           file.read(reinterpret_cast<char*>(this), sizeof(account_info));
     }
     file.close();
     setbkcolor(WHITE);
     setusercharsize(2,2,4,2);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setcolor(COLOR(200,50,0));
     outtextxy(260,200,"Interest Calculated Successfully.");
     setcolor(BLACK);
}

// Function for creating new account for new customer.

void account::new_account(void)
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     menu m;
     int opt;
     bool flag;

     char t_name[30], t_address[30],t_initial[10];
     float t_depo = 0.0;
     account_info ini;


     int t_accno;
     t_accno = ini.last_accno();
     t_accno++;
     do
     {
          clear_text_box();
          setcolor(BLACK);
          setbkcolor(WHITE);
          setusercharsize(1,1,2,1);
          settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
          settextjustify(LEFT_TEXT,TOP_TEXT);
          outtextxy(260,120,"NAME            :");
          outtextxy(260,150,"ADDRESS         :");
          outtextxy(260,180,"INITIAL DEPOSIT :");
          get_s(510,120,t_name);
          get_s(510,150,t_address);
          get_n(510,180,t_initial);
          t_depo=to_float(t_initial);

          opt=m.new_menu();
          m.blank();
          clear_text_box();
          switch(opt)
          {
                     case 1:
                          flag=0;
                          break;
                     case 2:
                          flag=1;
                          break;
                     case 3:
                          return;
          }

     }while (flag);
     float t_amount;
     t_amount = t_depo;
     char t_tran, t_type[10];
     t_tran = 'D';
     strcpy(t_type, "OPEN");
     int d1,m1,y1;
     t1.return_date(d1,m1,y1);
     // Appends the records contents into both account_info.txt and BANKING.txt data files
     ini.add_to_file(t_accno, t_name, t_address, t_depo);
     add_to_file(t_accno,d1,m1,y1, t_tran, t_type, t_amount, t_depo);
     interest i;
     i.new_interest(t_accno);

     logon l;
     l.new_account(t_accno,'C');
     ini.display(t_accno);
     setcolor(COLOR(200,50,50));
     outtextxy(260,200,"ACCOUNT CREATED SUCCESSFFULLY");
     outtextxy(260,220,"ACCOUNT HOLDER CAN ALSO LOG ON TO OUR e-BANKING SERVICE");
     outtextxy(260,240,"USERNAME AND PASSWORD ARE SAME AS THE ACCOUNT NO INITIALLY");
     outtextxy(260,260,"CHANGE USERNAME AND PASSWORD SOON!!!");
     back_to_menu();
     clear_text_box();
}
//to save banking transaction to  file
void account::add_to_file(int t_accno, int d1, int m1, int y1, char t_tran, char t_type[10],float t_amount, float t_balance)
{
     fstream file;
     file.open("BANKING.txt", ios::out|ios::app|ios::binary);
     accno = t_accno;
     dd = d1;
     mm = m1;
     yy = y1;
     tran = t_tran;
     strcpy(type, t_type);
     amount = t_amount;
     balance = t_balance;

     // Appends the transaction record into BANKING.txt data file
     file.write(reinterpret_cast<char *>(this), sizeof(account));
     file.close();
}
void account::box_for_display(int t_accno)
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     account_info ini;
     ini.display(t_accno);
     setcolor(COLOR(200,0,120));
     settextjustify(CENTER_TEXT,TOP_TEXT);
     outtextxy(500,178,"STATEMENT OF ACCOUNT");

     setcolor(COLOR(75,0,150));
     setusercharsize(2,1,1,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(CENTER_TEXT,TOP_TEXT);
     setbkcolor(WHITE);

     outtextxy(270,208,"DATE");
     outtextxy(355,208,"TYPE");
     outtextxy(455,208,"DEBIT");
     outtextxy(588,208,"CREDIT");
     outtextxy(723,208,"BALANCE");

     //to make table
     setlinestyle(SOLID_LINE,0,NORM_WIDTH );
     line(220,206,790,206);
     line(220,224,790,224);
     line(220,206,220,596);
     line(320,206,320,596);
     line(390,206,390,596);
     line(520,206,520,596);
     line(655,206,655,596);
     line(790,206,790,596);
     line(220,596,790,596);


}
void account::display_account(void)
{
     int t_accno;
     char ch_acno[5];          //to save string entered for account no
     setcolor(BLACK);
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     outtextxy(260,120,"ENTER A/C NO FOR DETAILS:");
     get_n(540,120,ch_acno);
     t_accno=int(to_float(ch_acno));
     account_info ini;
     if(!ini.find_account(t_accno))
     {
                                    setcolor(COLOR(200,0,0));
                                    setbkcolor(WHITE);
                                    setusercharsize(1,2,1,2);
                                    settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                                    settextjustify(CENTER_TEXT,TOP_TEXT);
                                    outtextxy((210+getmaxx())/2,300,"NON-EXISTING A/C NO ENTERED");
                                    setcolor(COLOR(250,25,250));
                                    outtextxy((210+getmaxx())/2,318,"(PRESS ANY KEY TO RETURN TO MENU)");
                                    getch();
                                    clear_text_box();
                                    return;
     }
     // Display the format from this function
     int recno=ini.recordno(t_accno);
     display_account(recno);

}
void account::display_account(int &recno)
{
     menu m;
     int opt;
     char date[15];
     char ch_temp[12];
     account_info ini;
     int t_accno=ini.accountno(recno);

     clear_text_box();
     box_for_display(t_accno);
     int row = 1;
     fstream file;
     file.open("BANKING.txt", ios::in|ios::binary);
     file.read(reinterpret_cast<char *>(this), sizeof(account));
     while (!file.eof())
     {
          if (accno == t_accno)
          {
               setcolor(COLOR(30,5,250));
               settextjustify(CENTER_TEXT,TOP_TEXT);
               sprintf(date,"%d/%d/%d",yy,mm,dd);
               outtextxy(270,208+18*row,date);
               outtextxy(355,208+18*row,type);
               settextjustify(RIGHT_TEXT,TOP_TEXT);
               if (tran == 'D')                    //credit
               {
                    sprintf(ch_temp,"%.2f",amount);
                    outtextxy(650,208+18*row,ch_temp);
               }
               else                                //debit
               {
                    sprintf(ch_temp,"%.2f",amount);
                    outtextxy(515,208+18*row,ch_temp);
               }
               sprintf(ch_temp,"%.2f",balance);
               outtextxy(785,208+18*row,ch_temp);
               row++;

               if (row > 20)
               {
                     opt=m.trans_menu(1);
                     m.blank();
                     clear_text_box();
                     switch(opt)
                     {
                                case 1:
                                     ini.modify(t_accno);
                                     return;
                                case 2:
                                     transaction(t_accno);
                                     return;
                                case 3:
                                     close_account(t_accno);
                                     return;
                                case 4:
                                     return;
                                case 5:
                                     break;
                     }

                     //to delete existing list to show new ones
                     clear_text_box();
                     box_for_display(t_accno);
                     row=1;
                     setcolor(COLOR(30,5,250));
                     setusercharsize(1,2,1,2);
                     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                     settextjustify(RIGHT_TEXT,TOP_TEXT);
                     outtextxy(650,208+18*row,"B/F");
                     outtextxy(785,208+18*row,ch_temp);        //last balance
                     row++;
               }
          }
          file.read(reinterpret_cast<char *>(this), sizeof(account));
     }
     file.close();
     opt=m.trans_menu(0);
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     ini.modify(t_accno);
                     return;
                case 2:
                     transaction(t_accno);
                     return;
                case 3:
                     close_account(t_accno);
                     return;
                case 4:
                     return;
                case 5:
                     break;
     }


}
void account::display_pri_account(int &recno)
{
     menu m;
     int opt;
     char date[15];
     char ch_temp[12];
     account_info ini;
     int t_accno=ini.accountno(recno);

     clear_text_box();
     box_for_display(t_accno);
     int row = 1;
     fstream file;
     file.open("BANKING.txt", ios::in|ios::binary);
     file.read(reinterpret_cast<char *>(this), sizeof(account));
     while (!file.eof())
     {
          if (accno == t_accno)
          {
               setcolor(COLOR(30,5,250));
               settextjustify(CENTER_TEXT,TOP_TEXT);
               sprintf(date,"%d/%d/%d",yy,mm,dd);
               outtextxy(270,208+18*row,date);
               outtextxy(355,208+18*row,type);
               settextjustify(RIGHT_TEXT,TOP_TEXT);
               if (tran == 'D')                    //credit
               {
                    sprintf(ch_temp,"%.2f",amount);
                    outtextxy(650,208+18*row,ch_temp);
               }
               else                                //debit
               {
                    sprintf(ch_temp,"%.2f",amount);
                    outtextxy(515,208+18*row,ch_temp);
               }
               sprintf(ch_temp,"%.2f",balance);
               outtextxy(785,208+18*row,ch_temp);
               row++;

               if (row > 20)
               {
                     opt=m.next_menu(1);
                     m.blank();
                     clear_text_box();
                     switch(opt)
                     {
                                case 1:
                                     return;
                                case 2:
                                     break;

                     }

                     //to delete existing list to show new ones
                     clear_text_box();
                     box_for_display(t_accno);
                     row=1;
                     setcolor(COLOR(30,5,250));
                     setusercharsize(1,2,1,2);
                     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                     settextjustify(RIGHT_TEXT,TOP_TEXT);
                     outtextxy(650,208+18*row,"B/F");
                     outtextxy(785,208+18*row,ch_temp);        //last balance
                     row++;
               }
          }
          file.read(reinterpret_cast<char *>(this), sizeof(account));
     }
     file.close();
     opt=m.next_menu(0);
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     return;
                case 2:
                     break;
     }


}

// Function for making daily transaction (Deposit 'D'/Withdraw 'W')
void account::transaction(void)
{
     int t_accno;
     char ch_acno[5];
     setcolor(BLACK);
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     outtextxy(260,120,"ACCOUNT NO FOR TRANSACTION:");
     get_n(540,120,ch_acno);
     t_accno=int(to_float(ch_acno));
     account_info ini;
     if(!ini.find_account(t_accno))
     {
                                    setcolor(COLOR(200,0,0));
                                    setbkcolor(WHITE);
                                    setusercharsize(1,2,1,2);
                                    settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                                    settextjustify(CENTER_TEXT,TOP_TEXT);
                                    outtextxy((210+getmaxx())/2,300,"NON-EXISTING A/C NO ENTERED");
                                    setcolor(COLOR(250,25,250));
                                    outtextxy((210+getmaxx())/2,318,"(PRESS ANY KEY TO RETURN TO MENU)");
                                    getch();
                                    clear_text_box();
                                    return;
     }
     clear_text_box();
     transaction(t_accno);

}
void account::transaction(int acno)
{
     menu m;
     int opt;
     bool flag;
     account_info ini;
     ini.display(acno);
     setcolor(COLOR(200,50,0));
     outtextxy(260,200,"DEPOSIT OR WITHDRAW CAN BE MADE IN ABOVE ACCOUNT");
     opt=m.depo_draw();
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     flag=0;
                     break;
                case 2:
                     flag=1;
                     break;
                case 3:
                     return;
     }
     int d1,m1,y1;
     char ch_amt[12];
     float amt,t_balance;
     char t_tran,t_type[6];
     t_balance=ini.give_balance(acno);
     ini.display(acno);
     setcolor(BLACK);
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);

     if(flag==0)                                //deposit
     {
                              outtextxy(260,200,"ENTER DEPOSIT AMOUNT :");
                              get_n(500,200,ch_amt);
                              amt=to_float(ch_amt);
                              t_tran='D';
                              strcpy(t_type,"CDEPO");
                              t_balance+=amt;
     }
     else                                        //withdrawal
     {
         outtextxy(260,200,"ENTER WITHDRAWL AMOUNT :");
         get_n(520,200,ch_amt);
         amt=to_float(ch_amt);
         if((t_balance-amt)<500.0)
         {
                     setcolor(COLOR(200,50,50));
                     outtextxy(260,300,"WITHDRAWL AMOUNT EXCEEDS THE LIMIT");
                     outtextxy(260,320,"MINIMUM BALANCE OF RS.500 MUST BE MAINTAINED");
                     back_to_menu();
                     clear_text_box();
                     return;
         }
         t_tran='W';
         strcpy(t_type,"CWDRL");
         t_balance-=amt;
     }
     opt=m.save_trans_menu();
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     break;
                case 2:
                     return;

     }
     t1.return_date(d1,m1,y1);
     // Modified records are updated in data bases.
     ini.update_balance(acno,t_balance);
     add_to_file(acno, d1, m1, y1, t_tran, t_type, amt, t_balance);
     ini.display(acno);
     setcolor(COLOR(200,50,50));
     outtextxy(260,200,"ACCOUNT HAS BEEN UPDATED SUCESSFULLY");
     back_to_menu();
     clear_text_box();

}
void account::transfer(int t_accno)
{
     menu m;
     int opt;
     char ch_amt[12];
     char ch_acno[5];
     int des_accno;
     float amt;
     int d1,m1,y1;
     account_info ini;
     setbkcolor(WHITE);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setcolor(COLOR(200,50,50));
     outtextxy(260,200,"AMOUNT CAN BE TRANSFERED FROM THIS ACCOUNT TO ANOTHER");
     setcolor(BLACK);
     outtextxy(260,280,"ENTER TRANSFER AMOUNT :");
     outtextxy(260,310,"DESTINATION ACCOUNT NO:");
     get_n(500,280,ch_amt);
     amt=to_float(ch_amt);
     get_n(500,310,ch_acno);
     des_accno=int(to_float(ch_acno));

     if(!ini.find_account(des_accno))
     {
                                    clear_text_box();
                                    setcolor(COLOR(200,0,0));
                                    setbkcolor(WHITE);
                                    setusercharsize(1,2,1,2);
                                    settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
                                    settextjustify(CENTER_TEXT,TOP_TEXT);
                                    outtextxy((210+getmaxx())/2,300,"NON-EXISTING A/C NO ENTERED");
                                    setcolor(COLOR(250,25,250));
                                    outtextxy((210+getmaxx())/2,318,"(PRESS ANY KEY TO RETURN TO MENU)");
                                    getch();
                                    clear_text_box();
                                    return;
     }
     setcolor(COLOR(200,50,50));
     outtextxy(225,70,"DESTINATION ACCOUNT DETAILS");
     ini.display(des_accno);

     opt=m.save_trans_menu();
     m.blank();
     clear_text_box();
     switch(opt)
     {
                case 1:
                     break;
                case 2:
                     return;
     }
     float balance1,balance2;
     balance1=ini.give_balance(t_accno);
     balance2=ini.give_balance(des_accno);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     if((balance1-amt)<500.0)
     {
                              setcolor(COLOR(200,50,50));
                              outtextxy(260,200,"TRANSFER AMOUNT EXCEEDS THE LIMIT");
                              outtextxy(260,220,"MINIMUM BALANCE OF RS.500 MUST BE MAINTAINED");
     }
     else
     {
          balance1-=amt;
          balance2+=amt;
          t1.return_date(d1,m1,y1);
          // Modified records are updated in data bases.
          ini.update_balance(t_accno,balance1);
          ini.update_balance(des_accno,balance2);
          char t_type[10];
          sprintf(t_type,"TO%d",des_accno);
          add_to_file(t_accno, d1, m1, y1, 'W',t_type, amt, balance1);
          sprintf(t_type,"FRM%d",t_accno);
          add_to_file(des_accno, d1, m1, y1, 'D',t_type, amt, balance2);
          setcolor(COLOR(200,50,50));
          outtextxy(225,70,"DESTINATION ACCOUNT DETAILS");
          ini.display(des_accno);

          setcolor(COLOR(200,50,50));
          outtextxy(260,200,"BOTH ACCOUNTS HAVE BEEN UPDATED SUCESSFULLY");
     }
     back_to_menu();
     clear_text_box();

}
// Function for deleting an account from BANKING.txt file.
void account::delete_account(int t_accno)
{
     fstream file;
     file.open("BANKING.txt", ios::in|ios::binary);        // Open to read records
     fstream temp;
     temp.open("TEMP.txt", ios::out|ios::binary);          // Open to write records
     file.seekg(0, ios::beg);
     temp.seekp(0, ios::beg);                              // Positioned from begining of the file

     // Uses the copy method for deleting the transaction record from BANKING.txt data file
     file.read(reinterpret_cast<char *>(this), sizeof(account));
     while (!file.eof())
     {
          if (accno != t_accno)
               temp.write(reinterpret_cast<char *>(this), sizeof(account));
          file.read(reinterpret_cast<char *>(this), sizeof(account));
     }
     file.close();
     temp.close();
     remove("BANKING.txt");
     rename("TEMP.txt","BANKING.txt");

}

//for deletion of account
void account::close_account(int del_accno)
{
     logon l;
     menu m;
     int opt;
     account_info ini;
     ini.display(del_accno);
     setcolor(COLOR(200,0,0));
     setbkcolor(WHITE);
     setusercharsize(1,2,1,2);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     outtextxy(225,322,"WARNING !!!");
     outtextxy(225,340,"ABOVE ACCOUNT WILL BE REMOVED FROM DATABASE PERMANENTLY");
     outtextxy(225,358,"ACCOUNT INFORMATION CAN NOT BE RETRIEVED AFTER CLOSING");
     opt=m.close_menu();
     m.blank();
     clear_text_box();
     switch(opt)
     {
             case 1:
                  break;
             case 2:
                  return;
     }
     // Function calls to delete the existing account from file
     ini.delete_account(del_accno);
     delete_account(del_accno);
     l.delete_account(del_accno);
     clear_text_box();
     settextjustify(CENTER_TEXT,TOP_TEXT);
     outtextxy((210+getmaxx())/2,300,"ACCOUNT DELETED SUCCESSFULLY");
     delay(500);
     clear_text_box();
}
/////////////////////////////////for class button
int button::chooser=0;                                    //global declaration

void button :: make_button()                              //for member function
{
     //get center point
     int midx=(left+right)/2;
     int midy=(top+bottom)/2;
     //draw rectangle
     setcolor(DARKGRAY);
     setlinestyle(SOLID_LINE,1,THICK_WIDTH);
     line(left,top,right,top);
     line(left,bottom,right,bottom);
     line(left,top,left,bottom);
     line(right,top,right,bottom);
     //fill button
     setfillstyle(SOLID_FILL,LIGHTGRAY);
     floodfill(midx,midy,DARKGRAY);
      //draw black and white shadows
     if (flag==UNPUSHED)    setcolor(BLACK);
     else setcolor(DARKGRAY);
     setlinestyle(SOLID_LINE,1,NORM_WIDTH);
     line(left+1,bottom+1,right+1,bottom+1);
     line(right+1,top+1,right+1,bottom+1);

     if (flag==UNPUSHED)    setcolor(WHITE);
     else setcolor(BLACK);
     line(left+1,top+1,right-1,top+1);
     line(left+1,top+1,left+1,bottom-1);
     //write button name
     if (flag==UNPUSHED)    setcolor(COLOR(0,50,200));
     else setcolor(COLOR(150,60,0));
     setbkcolor(LIGHTGRAY);
     setusercharsize(1,2,1,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(CENTER_TEXT,CENTER_TEXT);
     outtextxy(midx,midy+4,tag);

}
bool button :: test_click(int x,int y)
{

     if((x>left&&x<right)&&(y>top&&y<bottom))
     {
                                             flag=PUSHED;             //button is pushed
                                             make_button();
                                             delay(400);
                                             flag=UNPUSHED;
                                             make_button();
                                             return 1;
     }
     else return 0;
}

bool button :: test_hover(int x,int y,int no)
{
     if((x>left&&x<right)&&(y>top&&y<bottom))
     {
                                             if(button_no!=chooser)
                                             {
                                             menu_help(no);
                                             choose(no);
                                             return 1;
                                             }
     }
     else return 0;
}

///////////////////////////////for header ,menu box ,text box etc.....
void make_banner()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     introduction();               //introdution
     //for button
     button exit(maxx-250,maxy-75,maxx-50,maxy-50,"CLICK TO CONTINUE",UNPUSHED,0);
     exit.make_button();
     setcolor(DARKGRAY);
     setlinestyle(SOLID_LINE,1,THICK_WIDTH);
     rectangle(0,0,maxx,60);
     setfillstyle(SOLID_FILL,LIGHTGRAY);
     floodfill(10,10,DARKGRAY);
     for(int i=maxx;;i-=2)
     {
             setcolor(COLOR(0,0,250));     //rgb color blue
             setbkcolor(LIGHTGRAY);
             settextjustify(LEFT_TEXT,CENTER_TEXT);
             setusercharsize(2, 1, 1, 1);
             settextstyle(BOLD_FONT,HORIZ_DIR,0);


             outtextxy(i,35," NEPAL BANK ");
             delay(1);

             if (i<-780)
                i=maxx;
             int mx,my;                    //for mouse position
             if( ismouseclick(WM_LBUTTONDOWN ))
             {
                 getmouseclick(WM_LBUTTONDOWN,mx,my);
                 if(exit.test_click(mx,my))
                 {
                 delete &exit;
                 floodfill(10,10,DARKGRAY);
                 setcolor(COLOR(0,0,0));                              //RGB black
                 settextstyle(BOLD_FONT,HORIZ_DIR,0);
                 settextjustify(CENTER_TEXT,CENTER_TEXT);
                 outtextxy(maxx/2,35,"NEPAL BANK");
                 setviewport(210, 70, maxx-3,maxy-3, 0);//1 means truncate at edges
                 setbkcolor(WHITE);
                 clearviewport();       //erases similar to cleardevice() i.e. with current bk color
                 //back to normal
                 setviewport(0,0,maxx,maxy,0);
                 break;
                 }
             }

     }

}

void text_box()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     setcolor(LIGHTGRAY);
     setlinestyle(SOLID_LINE,1,THICK_WIDTH);
     rectangle(205,65,maxx,maxy);
     rectangle(207,67,maxx-2,maxy-2);
     setcolor(BLACK);
     setlinestyle(SOLID_LINE,1,NORM_WIDTH);
     line(208,68,maxx-3,68);
     line(208,68,208,maxy-3);
     line(maxx-3,68,maxx-3,maxy-3);
     line(208,maxy-3,maxx-3,maxy-3);
}
void clear_text_box()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     setviewport(210, 70, maxx-3,maxy-3, 1);
     setbkcolor(WHITE);
     clearviewport();
     setviewport(0,0,maxx,maxy,0);
}
void menu_box()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     setcolor(DARKGRAY);
     setlinestyle(SOLID_LINE,1,THICK_WIDTH);
     rectangle(0,65,200,maxy);
     line(0,90,200,90);
     setfillstyle(SOLID_FILL,LIGHTGRAY);
     floodfill(10,70,DARKGRAY);
     setcolor(BLACK);
     setlinestyle(SOLID_LINE,1,NORM_WIDTH);
     line(0,91,199,91);
     line(1,91,1,maxy-1);
     line(201,65,201,maxy);
     setcolor(COLOR(0,0,0));
     setbkcolor(LIGHTGRAY);
     settextjustify(CENTER_TEXT,CENTER_TEXT);
}

////////////////////////////////////for different buttons outside menu
void exit_test()
{

     int maxx=getmaxx();
     int maxy=getmaxy();
     button exit(maxx-250,maxy-75,maxx-50,maxy-50,"CLICK TO EXIT",UNPUSHED,0);
     exit.make_button();
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))                {delay(1);}

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here
        cor_clk = exit.test_click(mousex,mousey);
     }
     while(!cor_clk);


}
void next_button()
{

     int maxx=getmaxx();
     int maxy=getmaxy();
     button exit(maxx-250,maxy-75,maxx-50,maxy-50,"CLICK TO CONTINUE",UNPUSHED,0);
     exit.make_button();
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))                {delay(1);}

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here
        cor_clk = exit.test_click(mousex,mousey);
     }
     while(!cor_clk);
}
void back_to_menu()
{

     int maxx=getmaxx();
     int maxy=getmaxy();
     button menu(maxx-250,maxy-75,maxx-50,maxy-50,"BACK TO MAIN MENU",UNPUSHED,0);
     menu.make_button();
     int mousex,mousey;              //for mouse position
     bool cor_clk=0;
     do
     {
        while(!ismouseclick(WM_LBUTTONDOWN ))                {delay(1);}

        getmouseclick(WM_LBUTTONDOWN,mousex,mousey);        //output of ismouselick(WM_LBUTTONDOWN) comes here
        cor_clk = menu.test_click(mousex,mousey);
     }
     while(!cor_clk);
}
//////////////////////////////////////for introduction and help
void introduction()
{
     int maxx=getmaxx();
     int maxy=getmaxy();
     setcolor(COLOR(180,40,240));
     setbkcolor(WHITE);
     setusercharsize(1,1,3,1);                                    //using RGB color
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(CENTER_TEXT,CENTER_TEXT);
     outtextxy(maxx/2+100,90,"WELCOME TO BANK MANAGEMENT SOFTWARE");
     outtextxy(maxx/2+100,235,"FROM THE PROGRAMME YOU CAN.......");
     setcolor(COLOR(10,110,70));
     setusercharsize(1,2,1,2);
     settextstyle(SIMPLEX_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,CENTER_TEXT);
     //about the program
     outtextxy(230,140,"*      This software keeps records on daily banking transactions");
     outtextxy(230,160,"*      This program is capable of holding any number of accounts");
     outtextxy(230,180,"*      This program has the forex exchange service");
     outtextxy(230,200,"*      This program automatically distributes interest to all accounts on daily basis");
     //instructions
     outtextxy(230,270,"*      Open new account for a particular person");
     outtextxy(230,290,"*      View existing accounts ( individual or all existing accounts )");
     outtextxy(230,310,"*      View transactions of individual accounts or view overall daily transactions");
     outtextxy(230,330,"*      Make deposits or withrawals of account holders");
     outtextxy(230,350,"*      Buy and sell the foreign currency");
     outtextxy(230,370,"*      Modify existing bank accounts");
     outtextxy(230,390,"*      Supply interests to all bank accounts on daily balance");
     outtextxy(230,410,"*      Delete unnecessary accounts from the database");
     outtextxy(230,430,"*      And many more features");
     //instruction to continue
     setcolor(COLOR(180,40,240));
     outtextxy(230,450,"       Click below to proceed into the programme......");

}

void our_zone()
{
     button us(4,getmaxy()-150,196,getmaxy()-4,"",UNPUSHED,0);      us.make_button();
     button time(4,getmaxy()-179,196,getmaxy()-154,"",UNPUSHED,0);  time.make_button();

     setcolor(COLOR(50,125,125));
     setusercharsize(1,2,1,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     t1.show_date(100,getmaxy()-162);
     outtextxy(100,getmaxy()-117,"Developed by:");
     outtextxy(100,getmaxy()-97,"OPEN SOURCE LOVER ");
     outtextxy(100,getmaxy()-77,"ENJOY");
}

void menu_help(int button)
{
     setviewport(8,getmaxy()-146,192,getmaxy()-8,1);
     setbkcolor(LIGHTGRAY);
     clearviewport();
     setviewport(0,0,getmaxx(),getmaxy(),1);
     setbkcolor(LIGHTGRAY);
     setcolor(COLOR(110,50,150));
     settextjustify(CENTER_TEXT,CENTER_TEXT);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     outtextxy(100,getmaxy()-117,"CLICK THIS BUTTON");
     switch (button)
     {
            case 1:

                 outtextxy(100,getmaxy()-97,"TO CREATE A NEW");
                 outtextxy(100,getmaxy()-77,"ACCOUNT");
                 break;
            case 2:
                 outtextxy(100,getmaxy()-97,"TO VIEW EXISTING");
                 outtextxy(100,getmaxy()-77,"ACCOUNTS");
                 break;
            case 3:
                 outtextxy(100,getmaxy()-97,"FOR DEPOSITS AND");
                 outtextxy(100,getmaxy()-77,"WITHDRAWLS");
                 break;
            case 4:
                 outtextxy(100,getmaxy()-97,"TO EDIT OR");
                 outtextxy(100,getmaxy()-77,"CLOSE ANY ACCOUNT");
                 break;
            case 5:
                 outtextxy(100,getmaxy()-97,"TO CALCULATE");
                 outtextxy(100,getmaxy()-77,"DAILY INTEREST");
                 break;
            case 6:
                 outtextxy(100,getmaxy()-97,"TO EXIT FROM");
                 outtextxy(100,getmaxy()-77,"THE PROGRAMME");
                 break;
     }
}

//////////////////////////////for string and number inputs
//for checking inputs while blinking
void delaysharp(bool& broken) //broken means there is an input(if true)
{
    int count=0;
    while(count<10)
            {
                delay(50);             //checks input every 50 ms but blinks every 50*10=500 ms
                if(kbhit())
                {
                    broken=true;
                    return;
                }
                count++;
            }
    broken=false;
}
//to take string input
void get_s(int x,int y,char  temp[])
{
     setcolor(COLOR(0,150,0));
     rectangle(x-5,y-2,x+250,y+20);
     setfillstyle(SOLID_FILL,WHITE);
     floodfill(x+5,y+5,COLOR(0,150,0));
     char input;
     temp[0]='\0';
     int i=0,j=0;
     bool broken=false;

     setcolor(BLACK);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setbkcolor(WHITE);
     do{
                       //for cursor blinking
          while(!kbhit())
          {
                         j=textwidth(temp);                              //wrong strlen(temp);

                         outtextxy(x+j,y,"|");
                         delaysharp(broken);
                         if(broken)
                                   break;


                         outtextxy(x+j,y,"  ");
                         delaysharp(broken);
          }
          input=getch();


          if(input=='\b')
              i-=2;

          else if(input=='\r'||input=='\t')
          {
               outtextxy(x+j,y," ");
               i--;
          }

          else
               temp[i]=input;

          temp[++i]='\0';

          floodfill(x+5,y+5,COLOR(0,150,0));
          outtextxy(x,y,temp);
          if(i<0)             i=0;

     }
     while(input!='\r'&& input!='\t');         //until tab or enter is pressed

}
// to convert string to float
float to_float(char c[])
{

      float num=0;
      int deci=BEFORE;
      int pos=1;
      int j=strlen(c);
      for(int i=0;i<j;i++)
      {
                if(c[i]>='0'&&c[i]<='9')
                {
                                        float digit=float(c[i])-48;;
                                        if(deci==BEFORE)
                                        {
                                               num=num*10+digit;
                                        }
                                        else
                                        {
                                            num+=digit/(10*pos);
                                            pos*=10;
                                        }
                }
                else if(c[i]=='.'&& deci==BEFORE)
                {
                     deci=AFTER;
                }
      }
      return num;
}
//to take string input for integers/float values
void get_n(int x, int y,char source[])
{
     setcolor(COLOR(0,150,0));
     rectangle(x-5,y-2,x+250,y+20);
     setfillstyle(SOLID_FILL,WHITE);
     int flag=1;
     char input;
     source[0]='\0';
     int i=0,j;
     bool broken=false;
     setcolor(BLACK);
     setusercharsize(1,1,2,1);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,0);
     settextjustify(LEFT_TEXT,TOP_TEXT);
     setbkcolor(WHITE);
     do{
                       //for cursor blinking
          while(!kbhit())
          {
                         j=textwidth(source);                              //wrong strlen(temp);

                         outtextxy(x+j,y,"|");
                         delaysharp(broken);
                         if(broken)
                                   break;

                         outtextxy(x+j,y,"  ");
                         delaysharp(broken);
          }
          input=getch();
          if(input=='\b')
              i-=2;

          else if(input=='\r')
          {
               outtextxy(x+j,y," ");
               i--;
          }

          else if((input>='0'&& input<='9')||(input=='.'&&flag==1))
          {
               source[i]=input;
               if(input=='.')
                               flag=0;
          }
          else{i--;}
          source[++i]='\0';
          floodfill(x+5,y+5,COLOR(0,150,0));
          outtextxy(x,y,source);
          if(i<0)             i=0;

     }
     while(input!='\r'&& input!='\t');

}
void type(int x,int y,int s,char string[])
{
     char temp[2];
     if(s==2)
     {
             for(int i=0;i<strlen(string);i++)
             {
                     delay(20);
                     settextstyle(8,0,s);
                     setcolor(WHITE);
                     temp[0]=string[i];
                     temp[1]='\0';
                     outtextxy(x+(13*i+50),y,temp);
             }
     }
     else
     {
          for(int i=0;i<strlen(string);i++)
          {
                  delay(200);
                  settextstyle(10,0,s);
                  setcolor(BLACK);
                  temp[0]=string[i];
                  temp[1]='\0';
                  outtextxy(x+(32*i),y,temp);
          }
     }
}
void welcome()
{
    int maxx=getmaxx();
    int maxy=getmaxy();
    setfillstyle(SOLID_FILL,LIGHTBLUE);
    bar(0,0,maxx,maxy);
    setbkcolor(LIGHTBLUE);
    setcolor(WHITE);
    settextstyle(0,0,2);
    bar(maxx-50,0,maxx,maxy);
    settextstyle(8,0,5);
    setcolor(BLACK);
            outtextxy(700,200,"WELCOME TO");
    char str5[]="BANKING MANAGEMENT SYSTEM";
    type(100,300,6,str5);

    settextstyle(9,0,4);
    setcolor(BLACK);
    outtextxy(500,maxy-120,"DEVELOPED BY:");
    char str2[]="OPEN SOURCE LOVER";
    char str3[]="ENJOY";
    type(460,maxy-80,2,str2);
    type(460,maxy-60,2,str3);
    getch();

}

void intro()
{
    menu_box();
    text_box();
    introduction();                    //introduction
    make_banner();
}
//MAIN FUNCTION
int main()
{
    menu m;
    initwindow(getmaxwidth(),getmaxheight()-30,"BANKING MANAGEMENT SYSTEM");
    welcome();
    logon l;
    int method,acno;
    bool flag;
    do{
       t1.set_date();

       do
       {
                     flag=l.entry(method,acno);
       }
       while(!flag);
       l.new_account(0,'O');
       setfillstyle(SOLID_FILL,WHITE);
       floodfill(100,100,RED);
       intro();
       switch(method)
       {
                     case 1:
                          m.control_menu();
                          break;
                     case 2:
                          m.private_menu(acno);
                          break;
       }
       exit_test();
    }while(1);
    closegraph();
    return 0;
}

No comments:

Post a Comment