Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Create the logic of an Automated Teller Machine. The user will be presented with a menu of options. When the user selects an option, the

Create the logic of an Automated Teller Machine. The user will be presented with a menu of options. When the user selects an option, the corresponding function will need to be called. You will cut and paste the main.cpp below into your project. Do not change any of the code in main.cpp.

Instead, add two other files to your project - ATM.h and ATM.cpp. Implement all your functions in ATM.cpp, add function headers to ATM.h for your functions, and use #include "ATM.h" at the top of your .cpp files.

The Specifics

The following functions must be implemented:

Function Name: printMenu
Input: None
Output: None
Description: Prints the menu to the user. The menu should contain four options: (1) Print balance (2) Deposit (3) Withdrawal (4) Quit.
Function Name: getUserSelection
Input: None
Output: Integer representing user's choice.
Description: Prompts the user to input a value corresponding to the menu selections.
Function Name: printBalance
Input: Double passed by constant value representing the user's current balance
Output: None
Description: Pretty prints the current balance to the screen with a dollar sign and two decimal places along with a friendly message.
Function Name: deposit
Input: Double passed by reference representing the user's current balance
Output: Double representing the amount deposited
Description: Prompts the user to enter a positive amount to deposit. Validates the amount is positive. If the amount is positive, then modifies the user's balance and returns the amount deposited. Otherwise, returns a value signifying there was an error.
Function Name: withdraw
Input: Double passed by reference representing the user's current balance
Output: Double representing the amount withdrawn
Description: Prompts the user to enter a positive amount to withdraw. Validates there is enough money in the account to withdraw. If there is enough balance, then modifies the user's balance and returns the amount withdrawn. Otherwise, returns a value signifying there was an error.
With this structure, our main.cpp file must match the following implementation. Your job is to create the functions so the program runs as expected.

#include
#include
using namespace std;

#include "ATM.h"

int main() {
  int userChoice;
  double currentBalance = 0, amount = 0;
  cout << "Welcome to the Infinite ATM!" << endl;
  do {
    printMenu();
    userChoice = getUserSelection();
    switch( userChoice ) {
      case 1:
        printBalance( currentBalance );
        break;
      case 2:
        amount = deposit( currentBalance );
        if( amount > 0 ) {
          cout << "Thank you for depositing $" << fixed << setprecision(2) << amount << endl;
        } else {
          cout << "It seems you are making a withdrawal.  Perhaps try that instead?" << endl;
        }
        break;
      case 3:
        amount = withdraw( currentBalance );
        if( amount > 0 ) {
          cout << "Here is your $" << fixed << setprecision(2) << amount << "." << endl;
        } else {
          if( amount < -10 ) {
            cout << "We are sorry, we are not in the business of giving away money." << endl;
          } else {
            cout << "We are sorry, you have insufficient reserves in your treasure store." << endl;
          }
        }
        break;
      case 4:
        cout << "Thanks for coming!" << endl;
        break;
      default:
        cout << "It is not clear what you are trying to do." << endl;
    }
  } while( userChoice != 4 );
  return 0;
}
A sample run of the program is below with user input italicized for emphasis:

    Welcome to the Infinite ATM!
    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 1

    You currently have $0.00.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 2

    How many dubloons would you like to deposit?
    4.50
    Thank you for depositing $4.50 dubloons!

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 1

    You currently have $4.50.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 3

    How much do you wish to take out?
    3
    Here are your $3.00 dubloons!

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 1

    You currently have $1.50.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 3

    How much do you wish to take out?
    3
    We are sorry, you have insufficient reserves in your treasure store.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 3

    How much do you wish to take out?
    -3
    We are sorry, we are not in the business of giving away money.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 2

    How many dubloons would you like to deposit?
    -5
    It seems you are trying to make a withdrawal.  Perhaps try that instead?

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 7

    It is not clear what you are trying to do.

    Please make a selection:
    (1) Print Current Balance
    (2) Deposit Dubloons
    (3) Withdraw Dubloons
    (4) Quit
    Choice: 4


Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

include include using namespace std include ATMh int main int userChoice double currentBalance 0 amo... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Statistics

Authors: Prem S. Mann

8th Edition

9781118473986, 470904100, 1118473981, 978-0470904107

More Books

Students explore these related Law questions

Question

Is there any formal training for teaching?

Answered: 3 weeks ago

Question

Explain the pages in white the expert taxes

Answered: 3 weeks ago