1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
char ch156 = 156; // £ sign
int password();
int selectMenu ();
// code revoved to shorten it to less than 9000 chars
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);
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);
// code revoved to shorten it to less than 9000 chars
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;
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;
}
|