Write a program in CPP to automate a banking system by facilitating creation of accounts, deposit, withdrawal and searching using files. Use an appropriate Bank class.

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>
#include<stdio.h>
class DEPOSITOR
{
      int acno;
      char name[30];
      int balance;
   public:
      void getdata(void);
      void showdata(void);
      void deposit(int);
      void withdraw(int);
};
void DEPOSITOR::deposit(int d_amt)
{
   balance = balance + d_amt;
}
void DEPOSITOR::withdraw(int w_amt)
{
   if (w_amt > balance)
      cout << "No sifficient Amount in the Account"<<endl;
   else
      balance = balance - w_amt;
}
void DEPOSITOR::getdata()
{
   cout<<"Enter Account No : ";
   cin >>acno;
   cout<<"Enter the Name : ";
   cin >>name;
   cout<<"Enter Amount : ";
   cin >>balance;
}
void DEPOSITOR::showdata()
{
   cout.setf(ios::left,ios::adjustfield);
   cout<<setw(5)<<acno;
   cout<<setw(20)<<name;
   cout<<setw(10)<<balance<<endl;
}
void main()
{
   DEPOSITOR d;
   int opt, ac;
   int a_amt;
   fstream file;
   file.open("DEPOSITOR.DAT", ios::in | ios::out);
   clrscr();
   do
   {
      d.getdata();
      file.write((char*)&d, sizeof(d));
      flushall();
      cout<<"Enter 1 to Continue...";
      cin>>opt;
   }
   while(opt==1);
   file.seekg(0);
   while (1)
   {
       cout<<"Menu"<<endl;
       cout<<"1. Deposit"<<endl;
       cout<<"2. Withdrawal"<<endl;
       cout<<"3. View"<<endl;
       cout<<"4. Exit"<<endl;
       cout<<"Enter Your Option : ";
       cin>>opt;
       if(opt==4)
   break;
       if(opt==1)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   cout<<"Enter The Amount to be Deposited : ";
   cin>>a_amt;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
   d.deposit(a_amt);
   d.showdata();
      file.seekp(loc);
   file.write((char*)&d, sizeof(d));
   flushall();
       }
       if(opt==2)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   cout<<"Enter The Amount to be Withdrew : ";
   cin>>a_amt;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
   d.withdraw(a_amt);
   d.showdata();
   file.seekp(loc);
   file.write((char*)&d, sizeof(d));
   flushall();
       }
       if(opt==3)
       {
   cout<<"Enter The Account Number : ";
   cin>>ac;
   int loc = (ac - 1)*sizeof(d);
   file.seekg(loc);
   file.read((char*)&d,sizeof(d));
   if(file.eof() != 0) break;
   d.showdata();
       }
   }
   cout<<"==================================================="<<endl;
   file.close();
}

Please do modifications and send to mes.murugan@gmail.com

No comments:

Post a Comment