0% found this document useful (0 votes)
582 views

Atm - C Code

This document contains code for an ATM simulation program with the following functionality: 1. It defines classes for different screens like the welcome screen, login screen, transaction screen etc. 2. It stores account details like account number, pin, balances etc. in a structure and array for 50 accounts. 3. It allows users to login using their account number and pin, check balance, withdraw or deposit money and perform multiple transactions in one session. 4. Graphics functions are used to display screens and get input from the user to navigate through the various transaction options.

Uploaded by

mpjuser
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
582 views

Atm - C Code

This document contains code for an ATM simulation program with the following functionality: 1. It defines classes for different screens like the welcome screen, login screen, transaction screen etc. 2. It stores account details like account number, pin, balances etc. in a structure and array for 50 accounts. 3. It allows users to login using their account number and pin, check balance, withdraw or deposit money and perform multiple transactions in one session. 4. Graphics functions are used to display screens and get input from the user to navigate through the various transaction options.

Uploaded by

mpjuser
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

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

h> //PROGRAM FOR ATM SIMULATION fstream inoutfile; static int var; struct records{ long int accountnumber; int accountpin; unsigned long int lastdepositamount; unsigned long int lastwithdrawlamount; unsigned long int currentbalance; }l[] = {72440,1,100000,1000,300000, 72441,2,1000,200,12000, 72442,3,200,340,13000, 72443,4,3000,4000,30000, 72444,5,340,450,1230, 72445,6,234,3400,45000, 72446,7,12300,34000,230000, 72447,8,4500,560,3400000, 72448,9,1000,2000,5000000, 72449,10,230,670,56778, 72450,11,345,678,29990 }; class first_page {public: void boundary() { int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void display() { cleardevice();setbkcolor(4); boundary(); gotoxy(30,10);textcolor(BLUE);printf("WELCOME TO BANK ATM"); gotoxy(30,11);textcolor(BLUE);printf("====================");

gotoxy(30,17);textcolor(BLUE);printf("INSERT YOUR CARD"); gotoxy(30,20);textcolor(BLUE);printf("Press Enter To Continue"); gotoxy(60,23);textcolor(BLUE);printf("Made By:-AKASH MITRA"); getch(); bar(); } void bar() { int midx, midy, i,r; midx = 10; midy = 190; /* loop through the fill patterns */ for(r=0;r<=620;r++) { for (i=SOLID_FILL; i<USER_FILL; i++) { /* draw the bar */ setcolor(1); bar3d(midx, midy, midx+r,midy+4,0,0); } delay(4); } } }; class second_page { public: long int i, accno, temp, password, flag; void boundary() { int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void bar() { int midx, midy, i,r; midx = 10; midy = 190; /* loop through the fill patterns */ for(r=0;r<=620;r++) { for (i=SOLID_FILL; i<USER_FILL; i++) { /* draw the bar */ setcolor(1); bar3d(midx, midy, midx+r,midy+4,0,0); } delay(4);

} } int dusra() { cleardevice();setbkcolor(4); boundary(); flag = temp = password = 0; gotoxy(30,2);textcolor(BLUE);printf("BANK ATM"); gotoxy(30,3);textcolor(BLUE);printf("========"); gotoxy(21,6);printf("ENTER YOUR ACCOUNT NUMBER: "); scanf("%ld",&accno); gotoxy(21,8);printf("ENTER YOUR PASSWORD: "); while((temp = getch()) != 13) { switch(temp) { case 48: temp = 0; break; case 49: temp = 1; break; case 50: temp = 2; break; case 51: temp = 3; break; case 52: temp = 4; break; case 53: temp = 5; break; case 54: temp = 6; break; case 55: temp = 7; break;

case 56: temp = 8; break; case 57: temp = 9; break; } putchar('*'); password = (password * 10) + temp; } for (i=0; i<11; i++) { if((l[i].accountnumber == accno) && (l[i].accountpin == password)) { flag = 1; var = i; } } gotoxy(21,22); printf("Press enter to continue\n"); bar(); return flag;

} }; class third_page { public: int left, top, right, bottom; void boundary() { left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void bar() { int midx, midy, i,r; midx = 10; midy = 190;

/* loop through the fill patterns */ for(r=0;r<=620;r++) { for (i=SOLID_FILL; i<USER_FILL; i++) { /* draw the bar */ setcolor(1); bar3d(midx, midy, midx+r,midy+4,0,0); } delay(4); } } int teesra() { int a; cleardevice();setbkcolor(1); boundary(); gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(30,5);textcolor(10);printf("Transaction Page"); gotoxy(30,10);printf("Enter Your Choice"); gotoxy(30,11);printf("1. TO CHECK YOUR CURRENT BALANCE"); gotoxy(30,12);printf("2. FOR WITHDRAWAL"); gotoxy(30,13);printf("3. FOR DEPOSIT"); gotoxy(30,14);printf("4. EXIT "); gotoxy(30,15);printf("Enter Option:- "); cin>>a; return (a); } }; class forth_page {public: void chohta(struct records *l2) { cleardevice();setbkcolor(1); boundary(); gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(20,8);cout<<"Your Current Balance Is= "; printf("Rs.%lu/-",l2[var].currentbalance); gotoxy(20,10);cout<<"Your Last Withdrawal Was= "; printf("Rs.%lu/-",l2[var].lastwithdrawlamount); gotoxy(20,12);cout<<"Your Last Deposite Is= "; printf("Rs.%lu/-",l2[var].lastdepositamount); gotoxy(20,20);cout<<"Plz Press Enter To Go To Transaction Page"; inoutfile.close(); getch(); } void boundary()

{ int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } }; class fifth_page {public: void boundary() { int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void panchva(struct records *l2) { int a,b,i;char x;unsigned long int w; cleardevice();setbkcolor(1); boundary(); gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(20,10);cout<<"ENTER YOUR ACCOUNT TYPE"; gotoxy(20,12);cout<<"1. FOR SAVINGS ACCOUNT"; gotoxy(20,14);cout<<"2. FOR RECURRING ACCOUNT "; gotoxy(20,16);printf("Enter Option:- "); cin>>a; switch(a) { case 1: cleardevice();setbkcolor(6); boundary();w=0; gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(30,5);printf("SAVINGS ACCOUNT"); gotoxy(20,10);textcolor(WHITE);printf("Your Current Balance Is= "); printf("Rs.%lu/-",l2[var].currentbalance); gotoxy(20,12);textcolor(WHITE);printf("Enter The Amount You Want To Withdraw= "); scanf("%lu",&w);

if(w > l2[var].currentbalance) { gotoxy(18,22); textcolor(2); printf("!!! INVALID AMOUNT ENTERED. PLEASE CHECK. !!!"); textcolor(15); } else { inoutfile.close(); l2[var].lastwithdrawlamount = w; l2[var].currentbalance -= w; inoutfile.open("Details.txt",ios::out | ios::binary); for(i=0; i<50; i++) inoutfile.write((char *) & l2[i],sizeof(l2[i])); inoutfile.close(); gotoxy(21,18); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); printf("YOUR NEW BALANCE AFTER WITHDRAWL:"); textcolor(2); gotoxy(54,18); printf("Rs.%lu/-",l[var].currentbalance); inoutfile.close(); } gotoxy(20,20);cout<<"Want To Perform Another Transaction"; gotoxy(20,22);cout<<"If YES Then Press Y Else Press N "; cin>>x; if(x=='y'||x=='Y') break; else cleardevice();setbkcolor(1); gotoxy(25,10);cout<<"THANK YOU FOR USING OUR FACILITIES"; delay(1000); exit(0); break; case 2: cleardevice();setbkcolor(6); boundary();w=0; gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(30,5);printf("SAVINGS ACCOUNT"); gotoxy(20,10);textcolor(WHITE);printf("Your Current Balance Is= "); printf("Rs.%lu/-",l2[var].currentbalance); gotoxy(20,12);textcolor(WHITE);printf("Enter The Amount You Want To Withdraw= ");

scanf("%lu",&w); if(w > l2[var].currentbalance) { gotoxy(18,22); textcolor(2); printf("!!! INVALID AMOUNT ENTERED. PLEASE CHECK. !!!"); textcolor(15); } else { inoutfile.close(); l2[var].lastwithdrawlamount = w; l2[var].currentbalance -= w; inoutfile.open("Details.txt",ios::out | ios::binary); for(i=0; i<50; i++) inoutfile.write((char *) & l2[i],sizeof(l2[i])); inoutfile.close(); gotoxy(21,18); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); printf("YOUR NEW BALANCE AFTER WITHDRAWL:"); textcolor(2); gotoxy(54,18); printf("Rs.%lu/-",l[var].currentbalance); inoutfile.close(); } gotoxy(20,20);cout<<"Want To Perform Another Transaction"; gotoxy(20,22);cout<<"If YES Then Press Y Else Press N "; cin>>x; if(x=='y'||x=='Y') break; else cleardevice();setbkcolor(1); gotoxy(25,10);cout<<"THANK YOU FOR USING OUR FACILITIES"; delay(1000); exit(0); break; default: cout<<"wrong entry"; } } }; class sixth_page {public: void boundary()

{ int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void chatva(struct records *l2) { cleardevice();setbkcolor(1); boundary();int a,b,i;char x;unsigned long int d; gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(20,10);cout<<"ENTER YOUR ACCOUNT TYPE"; gotoxy(20,12);cout<<"1. FOR SAVINGS ACCOUNT "; gotoxy(20,14);cout<<"2. FOR RECURRING ACCOUNT \n "; gotoxy(20,16);printf("Enter Option:- "); cin>>a; switch(a) { case 1: cleardevice();setbkcolor(6); boundary();d=0; gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(20,10);textcolor(WHITE);printf("Your Current Balance Is= "); printf("Rs.%lu/-",l2[var].currentbalance); gotoxy(20,12);textcolor(WHITE);printf("Enter The Amount You Want To Deposite= "); scanf("%lu",&d); inoutfile.close(); l2[var].lastdepositamount = d; l2[var].currentbalance += d; inoutfile.open("Details.txt",ios::out | ios::binary); for(i=0; i<50; i++) inoutfile.write((char *) & l2[i],sizeof(l2[i])); inoutfile.close(); gotoxy(21,18); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); printf("YOUR NEW BALANCE AFTER DEPOSIT: Rs. "); gotoxy(54,18); textcolor(2); printf("Rs.%lu/-",l[var].currentbalance); inoutfile.close();

gotoxy(20,20);cout<<"Want To Perform Another Transaction"; gotoxy(20,22);cout<<"If YES Then Press Y Else Press N "; cin>>x; if(x=='y'||x=='Y') break; else cleardevice();setbkcolor(1); gotoxy(25,10);cout<<"THANK YOU FOR USING OUR FACILITIES"; delay(1000); exit(0); break; case 2: cleardevice();setbkcolor(6); boundary();d=0; gotoxy(30,2);textcolor(RED+BLINK);printf("BANK ATM"); gotoxy(30,3);textcolor(RED+BLINK);printf("========"); gotoxy(20,10);textcolor(WHITE);printf("Your Current Balance Is= "); printf("Rs.%lu/-",l2[var].currentbalance); gotoxy(20,12);textcolor(WHITE);printf("Enter The Amount You Want To Deposite= "); scanf("%lu",&d); inoutfile.close(); l2[var].lastdepositamount = d; l2[var].currentbalance += d; inoutfile.open("Details.dat",ios::out | ios::binary); for(i=0; i<50; i++) inoutfile.write((char *) & l2[i],sizeof(l2[i])); inoutfile.close(); gotoxy(21,18); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); printf("YOUR NEW BALANCE AFTER DEPOSIT: Rs. "); gotoxy(54,18); textcolor(2); printf("Rs.%lu/-",l[var].currentbalance); inoutfile.close(); gotoxy(20,20);cout<<"Want To Perform Another Transaction"; gotoxy(20,22);cout<<"If YES Then Press Y Else Press N "; cin>>x; if(x=='y'||x=='Y') break; else cleardevice();setbkcolor(1); gotoxy(25,10);cout<<"THANK YOU FOR USING OUR FACILITIES"; delay(1000); exit(0);

break; default: cout<<"wrong entry"; } } }; class seventh_page { public: void boundary() { int left, top, right, bottom; left = 5; top = 1; right = 630; bottom = 197; /* draw a rectangle */ setcolor(8); rectangle(left,top,right,bottom); } void satva() { cleardevice();setbkcolor(1); boundary(); gotoxy(25,10); textcolor(3);cout<<"THANK YOU FOR USING OUR FACILITIES"; delay(1000); exit(0); } }; void main() { clrscr(); int h=0,i,j; struct records *l1; int gdriver = EGA, gmode =EGALO, errorcode; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); } inoutfile.open("Details.txt",ios::in | ios::binary); if(inoutfile.fail())

{ inoutfile.open("Details.txt",ios::out | ios::binary); for(i=0; i<11; i++) inoutfile.write((char *) & l[i],sizeof(l[i])); } inoutfile.close(); first_page a; second_page b; third_page c; forth_page d; fifth_page e; sixth_page f; seventh_page g; a.display(); h = b.dusra(); if(h == 1) { do { j = c.teesra(); switch(j) { case 1: clrscr(); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); l1 = l; d.chohta(l1); inoutfile.close(); break; case 2: clrscr(); inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); l1 = l; e.panchva(l1); break; case 3: clrscr();

inoutfile.open("Details.txt",ios::in | ios::binary); inoutfile.read((char *) & l,sizeof(l)); l1 = l; f.chatva(l1); break; case 4: g.satva(); default: gotoxy(16,35); textcolor(15); textcolor(2); cputs("!!! INVALID OPTION ENTERED. PLEASE CHECK. !!!"); getch(); clrscr(); textcolor(15); } } while(j != 4); } else { textcolor(15); textcolor(2); gotoxy(8,33); cputs("!!! INCORRECT ACCOUNT NUMBER/PIN ENTERED. PLEASE CHECK. !!!"); textcolor(15); getch(); exit(0); }

getch(); }

You might also like