Question

answer in c++ code.
use comments when writing the code to know what's your thinking.
there is three pictures with information

Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relation

-<-Welcome to Cash Fast ATM ->-> Account ID 11 That account ID doesnt exist. Please try again. Account ID >>5 0:Get Cash Men

enu Selection > Amount to Deposit $2500 Please insert depost envelope below. e:Get Cash 1:View Balance 2:Deposit 3:Exit Menu

Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with an initial balance of $50. This will allow the user to interact with a few accounts for testing purposes. The ATM class should have a public method named logln(int) that receives the account ID. Valid IDs for the ATM correspond to valid indices for the vector. Once a valid ID is entered, call a private method named mainMenu. mainMenu should display the main menu continually in a loop until the user decides to exit. Menu options include: View Current Balance, Withdraw Money, Deposit Money, and Exit. Exiting the main menu will return control back to main. The other menu options should be implemented as separate private methods Another feature of the ATM is validation of deposits and withdrawals. The ATM should check the account balance before withdrawing and also make sure a positive multiple of 20 is entered. There should be a maximum deposit limit in place. Appropriate error messages should be displayed when the user encounters these limits. From main, use a loop to allow the user to repeatedly log-in to the ATM. Demonstrate the functionality of the ATM class by logging in and out using several IDs and exercising all of the available menu options
--> Account ID 11 That account ID doesn't exist. Please try again. Account ID >>5 0:Get Cash Menu Selection >>> 1 Current Balance: $50.00 0:Get Cash 1:View Balance 2:Deposit 3:Exit enu Selection >>> 0 Amout to Withdraw > $55 Error. Multiples of 20 only. 0:Ge Menu Selection >>>0 Amout to Withdraw $60 Error. Can't withdraw more than the balance. 0:Get Cash 1:View Balance 2:Deposit 3:Exit enu Selection >>0 Amout to Withdraw $40 0:Get Cash 1:View Balance 2:Deposit 3:Exit Menu Selection >>> 1 Current Balance: $10.00 0:Get Cash 1:View Balance Menu Selection>>> 3 Thanks for your patronage! Please come again! 1:View Balance 2:Deposit 3:Exit t Cash 1:View Balance 2:Deposit 3:Exit 2:Deposit 3: Exit Account ID >>>3 0:Get Cash 1:View Balance 2:Deposit enu Selection >>2 Amount to Deposit $2500 Please insert depost envelope below. 3:Exit
enu Selection > Amount to Deposit $2500 Please insert depost envelope below. e:Get Cash 1:View Balance 2:Deposit 3:Exit Menu Selection>>> 1 Current Balance: $2550.00 : Get Cash Menu Selection >>> 2 Amount to Deposit$6000 Error. Maximum deposit amount is $5000.00 0:Get Cash 1:View Balance 2:Deposit 3:Exit Menu Selection>>> 3 Thanks for your patronage! Please come again! 1:View Balance 2:Deposit 3:Exit Account ID >>>5 0:Get Cash 1:View Balance enu Selection>>> 1 Current Balance: $10,00 2:Deposit 3:Exit e:Get Cash 1:View Balance 2:Deposit 3Exit enu Selection> Amout to Withdraw >>$10 Error, Multiples of 20 only. 0:Get Cash 1:View Balance 2:Deposit :Exit Menu Selection >>3 Thanks for your patronage! Please come again! Account ID >>>
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <vector>
using namespace std;

class Account
{
private:
    int accId;
    double balance;
public:
    Account(){}
    Account(int accId, double balance)
    {
        this->accId = accId;
        this->balance = balance;
    }
    int getAccountId()
    {
        return this->accId;
    }
    double getAccountBalance()
    {
        return this->balance;
    }
    void setAccountBalance(double amount)
    {
        this->balance = amount;
    }

};

class ATM
{
private:
    Account targetAccount;
    vector<Account> accounts;
    void mainMenu()
    {
        int choice;
        do{
            cout << endl << "0: Get Cash\t1: View Balance       2: Deposit\t3: Exit\nMenu Selection >>> ";
            cin >> choice;

            switch (choice)
            {
                case 0:
                    double withdrawAmount;
                    cout << endl << "Amount to Withdraw: ";
                    cin >> withdrawAmount;
                    while((int)withdrawAmount % 20 != 0 || withdrawAmount > targetAccount.getAccountBalance())
                    {
                        if((int)withdrawAmount % 20 != 0)
                            cout << endl << "ERROR: Multiples of 20 only.";
                        else if(withdrawAmount > targetAccount.getAccountBalance())
                            cout << endl << "ERROR: Can't withdraw more than the balance.";

                        cout << endl << "Amount to Withdraw: ";
                        cin >> withdrawAmount;
                    }
                    targetAccount.setAccountBalance(targetAccount.getAccountBalance() - withdrawAmount);
                    break;

                case 1:
                    cout << endl << "Current Balance: $" << targetAccount.getAccountBalance();
                    break;

                case 2:
                    double depositAmount;
                    cout << endl << "Amount to Deposit: ";
                    cin >> depositAmount;
                    while(depositAmount > 5000)
                    {
                        cout << endl << "ERROR: Maximum deposit amount is $5000";
                        cout << endl << "Amount to Deposit: ";
                        cin >> depositAmount;
                    }
                    targetAccount.setAccountBalance(targetAccount.getAccountBalance() + depositAmount);
                    cout << endl << "Please insert deposit envelope below.";
                    break;

                case 3:
                    cout << endl << "Thanks for your patronage! Please come again!" << endl;
                    break;
            }
        }while(choice >= 0 && choice <= 3);
    }
public:
    ATM()
    {
        // creating a vector of 10 accounts
        for(int i = 1; i <= 10; i++)
        {
            this->accounts.push_back(Account(i, 50));
        }
        int accId;
        cout << endl << "Account ID >>> ";
        cin >> accId;
        logIn(accId);
    }

    bool logIn(int accId)
    {
        bool found = false;
        int index = 0;
        for(int i = 0; i < this->accounts.size(); i++)
        {
            if(accId != accounts[i].getAccountId())
            {
                found = false;
            }
            else
            {
                found = true;
                index = i;
                break;
            }
        }
        if(found)
        {
            targetAccount = this->accounts[index];
            mainMenu();
        }
        else
            cout << endl << "That account doesn't exist. Please try again." << endl;
    }
};

int main()
{
    ATM();
    return 0;
}

********************************************************************* SCREENSHOT ******************************************************

Account ID >>> That account doesnt exist. Please try again. Process finished with exit code 0

Account ID >> 0: Get Cash 1: View Balance 2: Deposit 3: Exit Menu Selection >> Current Balance: $50 i 0: Get Cash 1: View Bal

Account ID >>> 0: Get Cash 1: View Balance 2: Deposit 3: Exit Menu Selection >>> Amount to Deposit: Please insert deposit env

Add a comment
Know the answer?
Add Answer to:
answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • Create a class named UserAccounts that defines an array of 8 accounts as an instance variable....

    Create a class named UserAccounts that defines an array of 8 accounts as an instance variable. In the default constructor of this class, write a loop that creates 8 accounts with ids 1 through 7 and initial balance of $50 for each account. Store these accounts in the array. When the program runs, it asks the use to enter a specific id. When the user enters a correct id, the system displays a menu as shown in the sample run...

  • Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

    Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you. Pointers and Dynamic Memory – Chapter 11 1. Write code using pointers and the Accounts class from week 1 assignment as follows – create a program in which you a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation b. Add an initial balance of...

  • Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached...

    Question 3.1 Draw the class diagram for the ATM program in Question 2.1. Please find attached the scenario in the photos. this is for programming logic and design Scenario A local bank intends to install a new automated teller machine (ATM) to allow users (i.e., bank customers) to perform basic financial transactions (see below figure). Each user can have only one account at the bank. ATM users should be able to do the following; View their account balance. Withdraw cash...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • This assignment must be completed on your own with your team mates. Don't give your code...

    This assignment must be completed on your own with your team mates. Don't give your code to others or use other students' code. This is considered academic m will result 0 marks) Write a java program that mange JUC Bank accounts services. The program should have the following: The total number of accounts (n) will be specified by the user at the beginning of the program. Depending upon the entered number, create three Arrays as following o o o Array...

  • C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions,...

    C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • 1- TigerOne Bank is a local bank that intends to install a new automated teller machine...

    1- TigerOne Bank is a local bank that intends to install a new automated teller machine (ATM) to allow its customers to perform basic financial transactions. Using the ATM machine users should be able to view their account balance, withdraw cash and deposit funds. The bank wants you to develop the software application that will be installed on the new ATM machines. The following are the requirements for the application:  Users are uniquely identified by an account number and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT