Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   my C++ banking project (http://www.go4expert.com/forums/cpp-banking-project-t24319/)

simmy 30Dec2010 10:19

my C++ banking project
 
Project

simmy 30Dec2010 10:24

C++ banking project
 
Code:

#include <stdio.h>
#include <fstream.h>
#include <conio.h>
#include <process.h>
int i;
void line()
{
cout<<"\n-----------------------------------------------------------------------------\n";
}
class  acc
{

 int ano;char name[20];double bal;
 public:
 void  balwith(float i);
 void baldep(float i);
 float retbal();
  void getdata ()
  {
  cout<<"\nEnter account number :";cin>>ano;
  cout<<"Enter the name of the user :";cin>>name;
  bal=0;

  }
  void display()
  {

  cout<<"\nThe account details of the account no  "<<ano<<"  is: \n";
  cout<<"\nName  : "<<name;
  cout<<"\nBalance : "<< bal;

  }
  int retno()
  {
  return ano;
  }

  };
  void acc::balwith(float i)
  {
  bal=bal-i;
  }
  void acc::baldep(float i)
  {
    bal=bal+i;
  }
  float acc::retbal()
  {
  return bal;
  }
  void main()
  {
    clrscr();
    int c,num,s,pos,flag2=0;
    acc a,t;
    fstream f;

    cout<<"\n\n\n                  WELCOME TO C++ BANKING\n\n";
    do
    {
    cout<<"\n\n\n1.Create account 2.Deposit 3.Withdrawal ";cout<<"4.bank balance 5.Exit";/* 6.Delete account \n";7.Display all*/
    cout<<"\nEnter your choice :";
    cin>>c;
    switch(c)
    {
    case 1:f.open("aa.dat",ios::in|ios::out|ios::binary|ios::beg);



        cout<<"\nTo create an account :\n";
        a.getdata();

        while(f)
        {
        f.read((char*)&t,sizeof(t));
        if (a.retno() == t.retno())
          cout<<"\nsorry,The account number already existing\n";
        break;
        }
        f.seekp(ios::cur,ios::end);
        f.write((char*)&a,sizeof (a));
        cout <<"\Your account has been created, your balance is zero\n";
        f.close();
        break;

    case 2:f.open("aa.dat",ios::in|ios::out|ios::out|ios::binary);
        int flag1=0;
        cout<<"Enter the user account no in which u hav to deposit :\n";
        cin>>num;    f.seekp(0);
        while (f)
        {
        pos=f.tellp();
        f.read((char *)&a,sizeof(a));
        if (a.retno()==num)
        {
          cout<<"Enter the amount to deposit:\n";
          double newdep;cin>>newdep;
          a.baldep(newdep);
          f.seekp(pos);
          f.write ((char*)&a,sizeof(a));
          flag1=1;
          break;
        }
        }
        if (flag1==0)
          cout<<"\nSorry ,the account does not exist\n";
          f.seekp(ios::end);
        f.close();
        break;

      case 3:f.open("aa.dat",ios::in|ios::out|ios::binary);
        cout<<"Enter the user account no:";
        cin>>num;
        while (!f.eof())
        {
          pos =f.tellg();
          f.read((char*)&a,sizeof(a));
          if (a.retno()==num)
          {
          flag2=1;
          cout<<"\nEnter the amount to withdraw :";
          double with;cin>>with;
          float p;//to check wether thers enough balance
          p=a.retbal()-with;
          if (p<0)
          {
        cout<<"\nsorry,your bank balance is not enough\n";
          }
          else
        {
        a.balwith(with);
        cout<<"\nRs"<<with<<" has been withdrawn from the account "<<a.retno();
        }
          f.seekp(pos);
          f.write((char*)&a,sizeof(a));
          break;
          }
        }
        if (flag2==0)
          cout<<"The account does not exist\n";
        f.seekg(ios::cur,ios::end);
        f.close();
        break;

      case 4:f.open("aa.dat",ios::in|ios::binary|ios::beg);
          s=0;
        cout<<"\nTo know bankbalance \n";
        cout<<"Enter your account no:";
        cin>>num;

        while(!f.eof())
        {
          if (a.retno()==num)
          {
          s=1;
          line();
          cout<<"\nDisplaying:\n";
          a.display();line();

          break;
          }
          break;
        }
          if (s==0)
        cout<<"\nThe account does not exist \n";

          f.close();
          break;
      case 5: cout<<"\nYou are quitting\n";
          getch();
          exit(0);
      case 7: f.open("aa.dat",ios::in|ios::binary|ios::out|ios::beg);
          f.seekg (ios::cur,ios:: beg);

          f.read((char *)&a,sizeof(a));
          while (f)
          {
        a.display();
        f.read((char *)&a,sizeof(a));

          }
          f.seekg(ios::end);
          f.close();
          break;
      case 6:f.open("aa.dat",ios::in|ios::out);
        ofstream fout("temp.dat",ios::out); int tt=0;
        cout<<"Enter the account no: to be deleted:\n";
        int q;cin>>q;
        f.seekg(ios::cur,ios::beg);
        while (f)
        {
          f.read((char*)&a,sizeof(a));
          if (a.retno()==q)
          {
          tt=1;
          cout<<"\nThe following account is removed\n";
          a.display();
          }
          else
          {
        fout.write((char*)&a,sizeof(a));
          }
          }
          if (tt==0)
          cout <<"\nThe account to be deleted is not found\n";
          remove("aa.dat");
          rename("temp.dat","aa.dat");
          fout.close();f.close();
          break;

    default :cout <<"\nWrong choice ,try again\n";
    }

    }while (c!=5);

    getch();
  }

------------------------------

above is banking pgm i hav creatd by making use of files
but when i run the pgm ,the output is not coming properly
may be the data is not getting written into th file
pls help me' ,jus run the pgm in ur sys and find out the logical error
i want it by tomrro,31st dec

:crazy:


All times are GMT +5.5. The time now is 18:22.