Question

In: Computer Science

Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . ....

Simulate an ATM machine. Create ten accounts in an array with id 0, 1, . . . , 9, and initial balance $100. The system prompts the user to enter an id. If the id is entered incorrectly, ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can enter a choice 1 for viewing the current balance, 2 for withdrawing money, 3 for depositing money, and 4 for exiting the main menu. Once you exit, the system will prompt for an id again. Thus, once the system starts, it will not stop. In the main, check the id, and if the id is correct, call/involke the class for ATM.

Solutions

Expert Solution

BELOW IS THE CODE IN C++:

# include <iostream>
using namespace std;

class ATM
{
    float balance;
    public:
        int id;
    void set_all(int i,float money)
    {
        id = i;
        balance = money;
    }
    void check_balance()
    {
        cout<<"\n\t ACCOUNT BALANCE : "<<balance;
    }
    void deposit_money(float money)
    {
        if(money >= 0)
        {
            balance += money;
        }
        else if(money < 0)
        {
            cout<<"\n\t Depositing money can't be negative!!";
        }
        else
        {
            cout<<"\n\t Wrong Input!!PLEASE ENTER MONEY IN NUMBERS";
        }
    }
    void money_withdraw(float money)
    {
        if((money > 0) && (money <= balance))
        {
            balance -= money;
        }
        else
        {
            cout<<"\n\t Money can't be withdraw!! PLEASE ENTER A VALID AMOUNT";
        }
    }
};
int main()
{
    ATM ar[10];
    for(int i = 0 ; i < 10 ; i++)
    {
        ar[i].set_all(i,100);
    }
    int num;
    cout<<"_____________________WELCOME TO THE ATM_________________________";
    while(true)
    {
        cout<<"\n Enter your account id : ";
        cin>>num;
        if((num >= 0) && (num<=9))
        {
            int flag = 1;
            while(flag == 1)
            {
                int n;
                float money;
                cout<<"\n MENU FOR ACCOUNT ID = "<<ar[num].id;
                cout<<"\n Enter 1 for viewing the current balance";
                cout<<"\n Enter 2 for withdrawing money";
                cout<<"\n Enter 3 for depositing money";
                cout<<"\n Enter 4 for returning to mainmenu";
                cout<<"\n\t OPTION:";
                cin>>n;
                switch(n)
                {
                case 1:
                    ar[num].check_balance();
                    break;
                case 2:
                    cout<<"\n How much Money : ";
                    cin>>money;
                    ar[num].money_withdraw(money);
                    break;
                case 3:
                    cout<<"\n How much Money : ";
                    cin>>money;
                    ar[num].deposit_money(money);
                    break;
                case 4:
                    flag = 0;
                    break;
                default:
                    cout<<"\n\t Please Chose correct option!!";
                    break;
                }
            }
        }
        else
        {
            cout<<"\n\t Please enter valid Account ID !!";
        }

    }
}

OUTPUT:

DON'T FORGET TO GIVE A LIKE


Related Solutions

I need to create a program that will simulate an ATM. The program has to be...
I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get ** balance **withdraw **Deposit **exit the atm ** need to have a method that shows a receipt of everything that was done during the transaction
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases. We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance. The program must allow the following options: a) Create an account: request the account information and save it in the database. b) Enter the ATM: it will allow you to request the account number and will...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions: a) Employee name: b) Hours worked: c) Hourly rate: After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to...
Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0.
This program is for C.Create a two-dimensional array A using random integers from 1 to 10. Create a two-dimensional array B using random integers from -10 to 0. Combine the elements of A + B to create two- dimensional array C = A + B. Display array A, B and C to the screen for comparison. (Note a[0] + b[0] = c[0], a[1] + b[1] = c[1], etc.)
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
id GPA Hours Work Video Texts Male Brown 1 2.99 3 0 5.5 50 0 1...
id GPA Hours Work Video Texts Male Brown 1 2.99 3 0 5.5 50 0 1 2 3.25 25 0 0 300 0 0 3 3.20 11 24 0 30 0 0 4 3.20 14 0 16 40 1 1 6 3.20 20 0 0 150 1 1 7 2.04 3 8 40 1000 1 0 8 3.50 21 0 0 15 0 1 9 2.80 10 20 5 1500 0 1 10 3.82 100 0 0 0 0 1...
The heat of fusion of ice is 80 cal/g at 0 °C and 1 atm, and...
The heat of fusion of ice is 80 cal/g at 0 °C and 1 atm, and the ratio of the specific volume of water to that of ice is 1.000:1.091. The saturated vapor pressure and the heat of vaporization of water at 0 °C are 6.026 × 10-3 atm and 600 cal/g, respectively. Estimate the triple point of water using these data
C# - count =0; - Create a 2d array "items". string[,] items = new string[100, 4];...
C# - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when the user enters "0", stop the loop. - Users enter the item name, price, quantity, save this info and subtotal to array. - increase "count++" -convert price(decimal, Convert.ToDecimal() ) and quantity(int) to do multiplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and subtotal. accumulate...
DATA 2 ID X1 X2 X3 Y A 0 2 4 9 B 1 0 8...
DATA 2 ID X1 X2 X3 Y A 0 2 4 9 B 1 0 8 10 C 0 1 0 5 D 1 1 0 1 E 0 0 8 10 CORRELATION MATRIX Y X1 X2 X3 Y 1 ? -0.304 +0.889 X1 ? 1 -0.327 0 X2 -0.304 -0.327 1 -0.598 X3 +0.889 0 -0.598 1 1. What is the sum of squares regression for the full model? (Correct answer is 58, please show me how to get...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT