You are on page 1of 2

#include<iostream.h> #include<conio.h> #include<stdio.h> #include<fstream.h> #include<process.

h> struct member { char name[30] ; long int code, bal ; long int amt ; void withdraw() { cout<<"Enter amount to withdraw" ; cin>>amt ; if(amt<bal ) { bal -= amt ; cout<<"withdraw successful!" ; } else cout<<"Error!"<<"\t insufficient balance" ; } void deposit() { cout<<"Enter amount to deposit " ; cin>>amt ; bal +=amt ; cout<<"Deposit successful!" ; } void showdetails() { cout<<"\n\n\n WELCOME " ; cout.write(name,30) ; cout<<"\n\n\n Code:" <<code ; cout<<"\n\n\n Balance:" <<bal ; } void openacc() {ofstream fout ; fout.open("cust_data.dat",ios::app) ; cout<<"\n\n\n Enter name:" ; gets(name) ; cout<<"\n\n Opening balance:" ; cin>>bal ; cout<<"\n\n Code:" ; cin>>code ; fout<<name<<bal<<code ; fout.close(); } } obj ; void main() { clrscr() ; cout<<"\n\n\n \t\t Welcome to the ATM" ; cout<<" \n\n \t\t Press enter to proceed" ; cout<< "\n\n#################################################################### ##########################" ; getch() ; clrscr() ; int opt ;

char ch='y' ; ifstream fin; ofstream fout ; int c ; while(ch=='y'|| ch=='Y') { fin.open("cust_data.dat",ios::in|ios::binary) ; fout.open("temp.dat",ios::in|ios::binary) ; clrscr() ; place:; cout<<"\n\n\n Press 1 to open account" ; cout<<"\n\n\n Press 2 to view balance" ; cout<<"\n\n\n Press 3 to exit" ; cin>>opt ; switch(opt) { case 1:obj.openacc() ; break ; case 2:ch='y' ; break ; case 3:exit(1) ; } clrscr() ; cout<<"\n\n\n\n Enter your code" ; cin>>c ; fin.seekg(0) ; if(obj.code==c) { obj.showdetails() ; cout<<"\n\n\n Press 1 to withdraw" ; cout<<"\n Press 2 to deposit" ; cout<<"\n Press 3 to exit" ; int i=0 ; cin>>i ; switch(i) { case 1:obj.withdraw() ; break ; case 2:obj.deposit() ; break; case 3: clrscr() ; cout<<"\n Thank You for Using ATM"; getch(); break; default:cout<<"Invalid!!" ; ch='n' ; } getch() ; } else fout.write((char*) &obj,sizeof(obj)) ; fin.close() ; fout.close() ; remove("cust_data.dat") ; rename("temp.dat","cust_data.dat") ; } clrscr() ; gotoxy(15,10) ; getch() ; }

You might also like