Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* OS = Windows 7
- Compiler = CodeBlocks 10.05
- ATM simulator - Password is "1234"
- */
- #include <iostream>
- #include <windows.h>
- #include <Stdlib.h>
- #include <ctime>
- #include <string>
- #include <cstdio>
- using namespace std;
- char ch156 = 156; // £ sign
- int password();
- int selectMenu ();
- double depositMoney(double mon);
- double widrawMoney(double WMoney);
- double balanceInquiry (double bal);
- char tryAgain();
- void quitProgram( );
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
- COORD coord;
- // Thanks to NULL on (http://www.cplusplus.com/articles/E6vU7k9E/) for your wisdom
- string getpass(const char *prompt, bool show_asterisk = true)
- {
- const char BACKSPACE = 8;
- const char RETURN = 13;
- int i = 0;
- string password;
- unsigned char ch = 0;
- coord.X = 13;
- coord.Y = 8;
- SetConsoleCursorPosition(console, coord);
- cout << prompt << endl;
- DWORD con_mode;
- DWORD dwRead;
- HANDLE hIn=GetStdHandle(STD_INPUT_HANDLE);
- GetConsoleMode( hIn, &con_mode );
- SetConsoleMode( hIn, con_mode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT) );
- while(ReadConsoleA( hIn, &ch, 1, &dwRead, NULL) && ch !=RETURN)
- {
- if(ch==BACKSPACE)
- {
- if(password.length()!=0)
- {
- if(show_asterisk)
- cout <<"\b \b";
- password.resize(password.length()-1);
- }
- }
- else
- {
- password+=ch;
- if(show_asterisk)
- {
- coord.X = 13 + i;
- coord.Y = 8;
- SetConsoleCursorPosition(console, coord);
- cout <<'*';
- i++;
- }
- }
- }
- coord.X = 0;
- coord.Y = 0;
- SetConsoleCursorPosition(console, coord);
- SetConsoleMode( hIn, con_mode );
- return password;
- }
- // MSDN - alternative to system("CLS");
- void cls(HANDLE hConsole)
- {
- COORD coordScreen = {0, 0}; // home for the cursor
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD dwConSize;
- // Get the number of character cells in the current buffer.
- if( !GetConsoleScreenBufferInfo(hConsole, &csbi))
- {
- return;
- }
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- // Fill the entire screen with blanks.
- if( !FillConsoleOutputCharacter(hConsole, // Handle to console screen buffer
- (TCHAR) ' ', // Character to write to the buffer
- dwConSize, // Number of cells to write
- coordScreen, // Coordinates of first cell
- &cCharsWritten ))// Receive number of characters written
- {
- return;
- }
- // Get the current text attribute.
- if( !GetConsoleScreenBufferInfo(hConsole, &csbi))
- {
- return;
- }
- // Set the buffer's attributes accordingly.
- if( !FillConsoleOutputAttribute(hConsole, // Handle to console screen buffer
- csbi.wAttributes, // Character attributes to use
- dwConSize, // Number of cells to set attribute
- coordScreen, // Coordinates of first cell
- &cCharsWritten )) // Receive number of characters written
- {
- return;
- }
- // Put the cursor at its home coordinates.
- SetConsoleCursorPosition(hConsole, coordScreen);
- }
- int main()
- {
- double balance = 10000.00;
- char ch;
- int select;
- password();
- do
- {
- select = selectMenu();
- switch (select)
- {
- case 1://add code here for DepositMoney
- balance = depositMoney(balance);
- break;
- case 2: //add code here for widrawMoney
- balance = widrawMoney(balance);
- break;
- case 3://add code here for balanceInquiry;
- balance = balanceInquiry(balance);
- break;
- case 4://add code here forquitProgram();
- quitProgram();
- ch = 'N';
- break;
- }
- if (ch != 'N')
- {
- ch = tryAgain();
- }
- }
- while (ch=='Y' || ch == 'y');
- return 0;
- }
- int password()
- {
- const char *correct_password="1234";
- //main double boarder
- char ch201 = 201; char ch199 = 198; char ch196 = 196; char ch182 = 182;
- char ch205 = 205; char ch186 = 186; char ch187 = 187; char ch204 = 204;
- char ch185 = 185; char ch200 = 200; char ch188 = 188; char prev = ' ';
- //internal PIN border
- char ch218 = 218; char ch191 = 191;
- char ch179 = 179;
- char ch192 = 192; char ch217 = 217;
- //Password screen
- cls(console);
- cout << ch201; cout.fill (205); cout.width (31); cout << ch187 << endl;
- cout << ch186 << " Welcome to ABC Banking Group " << ch186 << endl;
- cout << ch204; cout.fill (205); cout.width (31); cout << ch185 << endl;
- cout.fill (prev);
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout << " Please enter your " << ch186 << endl;
- cout << ch186; cout << " 4 digit PIN " << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout << " " << ch218 << ch196 << ch196 << ch196 << ch196 << ch196 << ch196 << ch196 << ch191 << " " << ch186 << endl;
- cout << ch186; cout << " " << ch179 << " " << ch179 <<" " << ch186 << endl;
- cout << ch186; cout << " " << ch192 << ch196 << ch196 << ch196 << ch196 << ch196 << ch196 << ch196 << ch217 << " " << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch200; cout.fill (205); cout.width (31); cout << ch188 << endl;
- string password = getpass("",true); // Show asterisks
- if(password == correct_password)
- //Todo - 1: error message if password is wrong and limmit number of attemps to 3.
- // 2: After 3 attemps lock the user out and advise the to contact the bank.
- return 0;
- }
- int selectMenu ()
- {
- int choice = 0;
- char ch201 = 201; char ch199 = 198; char ch196 = 196; char ch182 = 182;
- char ch205 = 205; char ch186 = 186; char ch187 = 187; char ch204 = 204;
- char ch185 = 185; char ch200 = 200; char ch188 = 188; char prev = ' ';
- //Select screen
- cls(console);
- cout << ch201; cout.fill (205); cout.width (31); cout << ch187 << endl;
- cout << ch186 << " Welcome to ABC Banking Group " << ch186 << endl;
- cout << ch204; cout.fill (205); cout.width (31); cout << ch185 << endl;
- cout.fill (prev);
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout << " Main Menu " << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch204; cout.fill (196); cout.width (31); cout << ch185 << endl;
- cout << ch186; cout << " 1 - Depsit Money " << ch186 << endl;
- cout << ch204; cout.fill (196); cout.width (31); cout << ch185 << endl;
- cout << ch186; cout << " 2 - Withdraw Money " << ch186 << endl;
- cout << ch204; cout.fill (196); cout.width (31); cout << ch185 << endl;
- cout << ch186; cout << " 3 - Balance Inquiry " << ch186 << endl;
- cout << ch204; cout.fill (196); cout.width (31); cout << ch185 << endl;
- cout << ch186; cout << " 4 - Quit and Exit? " << ch186 << endl;
- cout << ch200; cout.fill (205); cout.width (31); cout << ch188 << endl;
- cin >> choice;
- do
- {
- if((!(choice >= 1)) || (!(choice <= 4)))
- {
- cout << " INVALID Choice! Please choose options 1 - 4 " << endl;
- cin >> choice;
- }
- }
- while((!(choice >= 1)) || (!(choice <= 4)));
- return choice;
- }
- double depositMoney(double mon)
- {
- double amount = 0;
- cout << "Enter amount to deposit: " << ch156 ;
- cin >> amount;
- if(amount < 500)
- {
- do
- {
- cout << " INCORRECT Amount! Please depsit over " << ch156 << "500.00" << endl;
- cout << " Enter amount to deposit: " << ch156 ;
- cin >> amount;
- }
- while( amount < 500);
- }
- else
- {
- cout << " Transaction Sucsessful - Thank You!" << endl<< endl;
- mon += amount;
- }
- return mon;
- }
- double widrawMoney(double WMoney)
- {
- double amount = 0;
- bool draw;
- draw = true;
- if (WMoney >= 5000)
- {
- cout << "You can draw an amount between " << ch156 << " 100.00 - "
- << ch156 << "5000.00" << endl;
- draw = true;
- }
- if ((WMoney > 100) && (WMoney < 5000))
- {
- cout << "You can draw an amount between " << ch156 << " 100.00 - "
- << ch156 << WMoney << endl;
- draw = true;
- }
- if(WMoney < 100)
- {
- cout << "INSUFFICIONT FUNDS!" << endl;
- draw = false;
- }
- if (draw = true)
- {
- cout << "Enter the amount you wish to withdraw " << ch156 ;
- cin >> amount;
- if(amount > WMoney)
- {
- do
- {
- cout << " INCORRECT Amount! You can draw an amount between ";
- if(WMoney >= 5000)
- {
- cout << ch156 << " 100.00 - " << ch156 << "5000" << endl;
- }
- else if(WMoney < 5000)
- {
- cout << ch156 << " 100.00 - " << ch156 << WMoney << endl;
- }
- cout << " Enter amount to withdraw : " << ch156 ;
- cin >> amount;
- }
- while( amount > WMoney);
- }
- WMoney -= amount;
- }
- double total;
- int thous, fiveH, twoH, oneH;
- total = amount;
- cout << "\nAmount Breakdown :" << endl;
- if (amount >= 1000)
- {
- thous = int(amount) / 1000;
- cout << "Number of " << ch156 << "1000 : " << thous << endl;
- amount -= (thous * 1000);
- }
- if (amount >= 500)
- {
- fiveH = int(amount) / 500;
- cout << "Number of " << ch156 << "500 : " << fiveH << endl;
- amount -= (fiveH * 500);
- }
- if (amount >= 200)
- {
- twoH = int(amount) / 200;
- cout << "Number of " << ch156 << "200 : " << twoH << endl;
- amount -= (twoH * 200);
- }
- if (amount >= 100)
- {
- oneH = int(amount) / 100;
- cout << "Number of " << ch156 << "100 : " << oneH << endl;
- amount -= (oneH * 100);
- }
- cout << "\nTotal amount withdrawn " << ch156 << total << endl << endl;
- return WMoney;
- }
- double balanceInquiry(double bal)
- {
- cout << "Your current balance is " << ch156 << bal << endl << endl;
- return bal;
- }
- char tryAgain()
- {
- char ch;
- cout << "Would you like another transaction? [Y/N] : ";
- cin >> ch;
- ch = (toupper(ch));
- if (ch != 'Y' && ch != 'N')
- {
- do
- {
- cout << "Invalid Selection! Please choose Y/N : ";
- cin >> ch;
- ch = (toupper(ch));
- }
- while (ch != 'Y' && ch != 'N') ;
- }
- if(ch == 'N')
- quitProgram();
- return ch;
- }
- void quitProgram()
- {
- //main double boarder
- char ch201 = 201; char ch199 = 198; char ch196 = 196; char ch182 = 182;
- char ch205 = 205; char ch186 = 186; char ch187 = 187; char ch204 = 204;
- char ch185 = 185; char ch200 = 200; char ch188 = 188; char prev = ' ';
- char ch;
- //Exit screen
- cls(console);
- cout << ch201; cout.fill (205); cout.width (31); cout << ch187 << endl;
- cout << ch186 << " Welcome to ABC Banking Group " << ch186 << endl;
- cout << ch204; cout.fill (205); cout.width (31); cout << ch185 << endl;
- cout.fill (prev);
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout << " Thank you for using " << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout << " ABC Banking Group " << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch186; cout.width (31); cout << ch186 << endl;
- cout << ch200; cout.fill (205); cout.width (31); cout << ch188 << endl;
- // Delay the exit screen incase your compiler exits at the last return in main.
- // It also allows the user to acknowledge the exit screen.
- time_t start,end;
- double dif = 0.0;
- time (&start);
- do
- {
- time (&end);
- dif = difftime (end,start);
- }while(dif < 4); // 3 second delay
- }
Advertisement
Add Comment
Please, Sign In to add comment