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
Practice Coding Task C++ ATM Machine with Some Classes Create an ATM machine in C++ with...
Practice Coding Task C++ ATM Machine with Some Classes Create an ATM machine in C++ with a few classes. Requirements: Automated Teller Machine (ATM) simulationGiven 3 trials, the user is able to see his balance by entering a four-digit pin that must NEVER be displayed on screen but masked by the Asterix (*) character. A list of pins stored on the file system must be loaded to verify the pin. The user should be able to withdrawfundsbelow a set limit...
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.)
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
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...
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a...
Problem 1: Given an array A[0 ... n-1], where each element of the array represents a vote in the election. Assume that each vote is given as integers representing the ID of the chosen candidate. Write the code determining who wins the election. Problem 2: How do we find the number which appeared maximum number of times in an array? ( Use Java and an original code )
Given an array A[0 … n-1], where each element of the array represent a vote in...
Given an array A[0 … n-1], where each element of the array represent a vote in the election. Assume that each vote is given as an integer representing the ID of the chosen candidate. Can you determine who wins the election? What is the complexity of your solution? Hint: it is similar to finding the element that is repeated the maximum number of times.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT