Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an ATM C++ program simulation to do the three common tasks: withdraw, depo

ID: 3863357 • Letter: W

Question

Write an ATM C++ program simulation to do the three common tasks: withdraw, deposit and balance checking using three C++ functions. You must define 3 users. Each user information is stored in an array. The WETHDRAW function to make money withdrawal. The DEPOSIT function to deposit money in the account. The CHECKING function to check the account balance. To withdraw money successfully from the account the balance must be greater than the amount of money to be taken out of that account. The application will prompt the user to enter the account user name and password. If the user name is predefined it then asks for the password. It checks the password. The user has 3 tries to get the password correct. Otherwise, the account will be locked and no transactions can be done. Once the user name and password entered correctly, the application displays the main menu to choose between 3 transactions: withdraw (W), deposit (D), and balance checking (C) or exit (E). After the user finishes its transaction, the application must display the main menu again and user enters (E) to close the program. The user name of the 3 users must be stored in an array “USERSNAME” The password of the 3 users must be stored in an array “PASSWORD” The 3 accounts balance must be stored in an array “BALANCE”

Explanation / Answer

C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   string names[3] = {"u1", "u2", "u3"};
   string passwords[3] = {"p1", "p2", "p3"};
   int Balance[3] = { 1000, 2000, 3000};
   bool islocked[3] = {false,false,false};
   while(true)
   {
       string uname;
       cout << "Enter USername ";
       cin >> uname;
       bool flag = false;
       int i = 0;
       for (i = 0; i < 3; ++i)
       {
           if(names[i] == uname)
           {
               flag = true;
               break;
           }
       }
   if(i <= 2)
   {
       if(islocked[i] == false)
           {
               string pass;
               if(flag == true)
               {
                   int attempts = 3;
                   while(attempts > 0)
                   {
                       cout << "Enter password ";
                       cin >> pass;
                       if(passwords[i] == pass)
                       {
                           break;
                       }
                       else
                       {
                           cout << "Invalid password! ";
                       }
                       attempts--;
                   }

                   if(attempts <= 0)
                   {
                       cout << "Your account is locked! ";
                       islocked[i] = true;
                   }
                   else
                   {
                       int c;
                       cout << "Menu! 1.Enter 1 to check Balance 2. Enter 2 to Deposite Money 3.Enter 3 to Widraw Money 4. Enter 4 to exit " << endl;
                       cin >> c;
                       if(c == 1)
                       {
                           cout << "YOur Balance is = " << Balance[i] << endl;  
                       }
                       else if(c ==2)
                       {
                           int am;
                           cout << "Enter amount to Deposite" << endl;
                           cin >> am;
                           if(am > 0)
                           {
                               Balance[i] = Balance[i] + am;
                           }
                           else
                           {
                               cout << "Deposite amount must be positive!" << endl;
                           }
                       }
                       else if(c == 3)
                       {
                           int am;
                           cout << "Enter amount to Widraw" << endl;
                           cin >> am;
                           if(Balance[i] >= am)
                           {
                               Balance[i] = Balance[i] - am;
                               cout << "Transaction Successful ";
                           }
                           else
                           {
                               cout << "Insufficient Balance!" << endl;
                           }                      
                       }
                       else
                       {
                           continue;  
                       }
                   }
               }
               else
               {
                   cout << "NO user found with USername = " << uname << endl;
               }
           }
           else
           {
               cout << "Your account is locked, please contact to bank! ";
           }
       }
       else
       {
           cout << "No USer with this username ";
       }
   }
   return 0;
}

Sample Output:

Enter USername
u1
Enter password
p1
Menu!
1.Enter 1 to check Balance
2. Enter 2 to Deposite Money
3.Enter 3 to Widraw Money
4. Enter 4 to exit

2
Enter amount to Deposite
1000
Enter USername
u1
Enter password
p1
Menu!
1.Enter 1 to check Balance
2. Enter 2 to Deposite Money
3.Enter 3 to Widraw Money
4. Enter 4 to exit

1
YOur Balance is = 2000
Enter USername
u1
Enter password
p1
Menu!
1.Enter 1 to check Balance
2. Enter 2 to Deposite Money
3.Enter 3 to Widraw Money
4. Enter 4 to exit

3
Enter amount to Widraw
3000
Insufficient Balance!
Enter USername
u1
Enter password
p1
Menu!
1.Enter 1 to check Balance
2. Enter 2 to Deposite Money
3.Enter 3 to Widraw Money
4. Enter 4 to exit

3
Enter amount to Widraw
1500
Transaction Successful
Enter USername
u1
Enter password
u2
Invalid password!
Enter password
u1
Invalid password!
Enter password
p1
Menu!
1.Enter 1 to check Balance
2. Enter 2 to Deposite Money
3.Enter 3 to Widraw Money
4. Enter 4 to exit

1
YOur Balance is = 500
Enter USername

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote