#include

#include

#include

#include

#include

int menu();

int search_key = 0;

    class customer{

    public:

     //constructor

     customer();

     //methods

     void deposit(double,char *);

     void withdrawal(double,char *);

     void search_cust(char *,customer) const;

     //getters

     void get_balance() const;

     void display_info(customer) const;

     //setters

     void open_account(customer *);

    private:

     char f_name[30];

     char l_name[30];

     char phone[10];

     char address[30];

     int cust_age;

     char cust_id[10];

     char cust_pin[10];

     char account_no[10];

     double balance;

};//end class customer definition

customer::customer()

    {

     strcpy(customer::f_name,"");

     strcpy(customer::l_name,"");

     customer::cust_age=0;

     strcpy(customer::cust_id,"");

     strcpy(customer::cust_pin,"");

     strcpy(customer::account_no,"");

     customer::balance=0.0;

}//end customer constructor

void customer::withdrawal(double amt,char *pin_no)

    {

     int pinkey = 0;customer c1;

     fstream read_customer("customer.txt",ios::in|ios::out);

     while(!read_customer.eof())

         {

        

         read_customer.read((char *) &c1, sizeof(c1)); 

        

         if(strcmp(c1.cust_pin,pin_no)==0)

             {

             pinkey = 1;

             if(c1.balance >= amt)

                 {

                 c1.balance -= amt;

                 read_customer.seekp((sizeof(c1) * -1),ios::cur);

                 read_customer.write((char *) &c1,sizeof(c1));

                 cout << "Your Transaction was successful";

                

                 }//end if

                 else

                     {

                     cout << "Your balance is: " << c1.balance <<

                     " You cannot withdraw amount requested" << endl;

                     }//end else

                    

                     break;

                     }//end if

                    

                     }//end while

                     if(pinkey == 0)

                     cout << "Pin# Incorrect";

                     cout << endl;getch();

                     read_customer.close();

                }//end withdrawal

                void customer::deposit(double amt,char *pin_no)

                    {

                     int pinkey = 0;customer c1;

                     fstream read_customer("customer.txt",ios::in|ios::out);

                     while(!read_customer.eof())

                         {

                        

                         read_customer.read((char *) &c1, sizeof(c1)); 

                        

                         if(strcmp(c1.cust_pin,pin_no)==0)

                             {

                             pinkey = 1;

                             if(c1.balance >= amt)

                                 {

                                 c1.balance += amt;

                                 read_customer.seekp((sizeof(c1) * -1),ios::cur);

                                 read_customer.write((char *) &c1,sizeof(c1));

                                 cout << "Your Transaction was successful" << endl;

                                 cout << "Your balance is: " << c1.balance << endl;

                                 }//end if

                                

                                 break;

                                 }//end if

                                

                                 }//end while

                                 if(pinkey == 0)

                                 cout << "Pin# Incorrect";

                                 cout << endl;getch();

                                 read_customer.close();

                            }//end deposit

                            void customer::get_balance() const

                                {

                                 char pin_no[10];customer cust;int pinkey=0;

                                 cout << "Enter pin#: ";

                                 cin >> pin_no;

                                 ifstream read_customer("customer.txt");

                                 while(!read_customer.eof())

                                     {

                                     read_customer.read((char *) &cust, sizeof(cust));

                                    

                                     if(read_customer.fail())

                                     break;

                                     if(strcmp(cust.cust_pin,pin_no)==0)

                                         {

                                         pinkey = 1;

                                         cout << "Your Balance is: $" << cust.balance << endl;

                                         break;

                                         }

                                        

                                        

                                         }//end while

                                         if(pinkey == 0)

                                         cout << "Pin# Incorrect";

                                         cout << endl;getch();

                                         read_customer.close();

                                    }//end get_balance

                                    void customer::search_cust(char *accno,customer cust) const

                                        {

                                         ifstream read_customer("customer.txt");

                                         while(!read_customer.eof())

                                             {

                                             read_customer.read((char *) &cust, sizeof(cust));

                                            

                                             if(read_customer.fail())

                                             break;

                                             if(strcmp(accno, cust.account_no) == 0)

                                                 {

                                                 display_info(cust);

                                                 search_key = 1;

                                                 }//end if

                                                 }//end while

                                                 read_customer.close();

                                            }

                                            void customer::display_info(customer cust) const

                                                {

                                                 cout << "Customer Details" << endl;

                                                 cout << "----------------" << endl;

                                                 cout << cust.f_name << endl;

                                                 cout << cust.l_name << endl;

                                                 cout << cust.account_no << endl;

                                                 cout << cust.phone << endl;

                                                 cout << cust.address << endl;

                                                 cout << cust.cust_age << endl;

                                                 cout << cust.cust_id << endl;

                                                 cout << cust.balance << endl;

                                                 cout << endl;getch();

                                            }

                                            void customer::open_account(customer * cust)

                                                {

                                                 cout << "Enter First Name: ";

                                                 cin >> cust->f_name;cin.get();

                                                 cout << "Enter Last Name: ";

                                                 cin >> cust->l_name;cin.get();

                                                 cout << "Enter Phone #: ";

                                                 cin >> phone;cin.get();

                                                 cout << "Enter Current Address: ";

                                                 cin.getline(cust->address,sizeof(cust->address));

                                                 cout << "Enter Age: ";

                                                 cin >> cust->cust_age;cin.get();

                                                 cout << "Enter Id#: ";

                                                 cin >> cust->cust_id;cin.get();

                                                 cout << "Enter Pin#: ";

                                                 cin >> cust->cust_pin;cin.get();

                                                 cout << "Enter Account#: ";

                                                 cin >> cust->account_no;cin.get();

                                                 cout << "Enter starting balance: $";

                                                 cin >> cust->balance;cin.get();

                                            }

                                            void main(void)

                                                {

                                                 //create object

                                                 customer c1;

                                                 int y;

                                                 double amt;

                                                 char pin_no[10],accno[10];

                                                    while(1){

                                                     if(y==6)

                                                     break;

                                                     system("cls");

                                                     y = menu();

                                                     switch(y)

                                                         {

                                                             case 1:{

                                                             cout << "Open Account" << endl;

                                                             cout << "------------" << endl;

                                                             c1.open_account(&c1);

                                                             //writing account info to file

                                                             ofstream write_customer("customer.txt",ios::app);  //writing to the participant file

                                                             write_customer.write((char *) &c1, sizeof(c1));

                                                             write_customer.close();

                                                             }

                                                             break;

                                                             case 2 :

                                                             cout << "Withdrawal" << endl;

                                                             cout << "----------" << endl;

                                                             cout << "Enter amount: $";

                                                             cin >> amt;

                                                             cout << "Enter Pin#: ";

                                                             cin >> pin_no;

                                                             c1.withdrawal(amt,pin_no);

                                                            

                                                             break;

                                                             case 3 :

                                                             cout << "Deposit" << endl;

                                                             cout << "-------" << endl;

                                                             cout << "Enter amount: $";

                                                             cin >> amt;

                                                             cout << "Enter Pin#: ";

                                                             cin >> pin_no;

                                                             c1.deposit(amt,pin_no);

                                                            

                                                             break;

                                                             case 4 :

                                                             c1.get_balance();

                                                            

                                                             break;

                                                             case 5:

                                                             cout << "Enter Account you want to search for: ";

                                                             cin >> accno;

                                                            

                                                             c1.search_cust(accno,c1);

                                                            

                                                             break;

                                                             case 6 :

                                                             cout << "Bye\n\nPress a key to exit\n";

                                                             cout << endl;getch();

                                                             break;

                                                             default:

                                                             cout << "\nIncorrect Option. Press a key to return to MENU";

                                                             getch();

                                                             break;

                                                             }//end switch

                                                             }//end while

                                                             exit(0);

                                                        }//end main

                                                        

                                                        /*-----------------------MENU DISPLAY-------------------------------*/

                                                        int menu()

                                                            {

                                                             int y=0;

                                                             cout << "\n\t\t\tWELCOME TO IVB's ATM\n";

                                                             cout << "\t\t --------------------------\n\n";

                                                             cout << "\t\t\t1. Open Account\n";

                                                             cout << "\t\t\t2. Cash Withdrawal\n";

                                                             cout << "\t\t\t3. Deposit Cash/Cheque\n";

                                                             cout << "\t\t\t4. Balance Request\n";

                                                             cout << "\t\t\t5. Search for Customer Details\n";

                                                             cout << "\t\t\t6. EXIT.\n\n\n";

                                                            

                                                             cout << "\t\t\tEnter option: ";

                                                             cin >> y;

                                                             cout << "\n\n\n";

                                                             return y;

                                                        }//end of menu