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

Help needed with an ATM Machine C++ program. Using notes and other sources, here

ID: 3766822 • Letter: H

Question

Help needed with an ATM Machine C++ program.

Using notes and other sources, here's what I have so far from the homework posted below. I am not sure what I am doing wrong.

#include

using namespace std;

void PrintMenu1()

    {cout<<"ATM MACHINE ";

    cout<<"3- Deposit ";

    cout<<"4- Withdraw ";

    cout<<"5- Exit ";

    }

int main()

{int choice,selection;

double balance, amount;

do{

   PrintMenu1();

    cin>>choice;

    switch(choice)

       {

        case 4:cout<<"Enter amount: $";

                cin>>amount;

                if(amount>balance)

                     cout<<"Low balance ";

                else

                     balance-=amount;

                break;

        case 3:cout<<"Enter amount: $";

                cin>>amount;

                balance+=amount;

                break;

          case 5:cout<<"Goodbye! ";

                 break;

          default:cout<

          }

}while (choice!=6);

}else if(selection<1||selection>2)

    cout<

}while(selection!=2);

return 0;

}

INSTRUCTIONS

Design a class named Account that contains:

-An int data field named id for the account.

-A double data field named balance for the account.

-A no-arg constructor that creates a default account with id=0 and balance=0.

-A constructor that creates an account with specified values for id and balance.

-The accessor and mutator functions for id and balance.

-A function named withdraw(amount) that withdraws a specified amount from the account - by updating the balance.

-A function named deposit(amount) that deposits a specified amount to the account.

Write a test program that simulates an ATM machine.

-Create one Account object with id=1 and initial balance=100.

-Display the user’s balance.

-Display a main menu, as shown in the sample run, and ask the user to choose an option.

-The user can enter: 1 for withdrawing money, 2 for depositing money, and 3 for exiting the main menu.

-If the user chooses option 3, end the program.

-Otherwise, ask for the amount of money to withdraw or deposit (depending on the previous choice).

-Perform the withdrawal or deposit.

-Display the balance and the menu again.

-The program must allow multiple deposits and withdrawals in a single run. It only ends when the user chooses option 3.

Explanation / Answer

Here is the code for you. If you need any further refinements, just get back to me.

#include <iostream>
using namespace std;
class Account
{
int id;
double balance;
public:
Account()   //Default Constructor.
{
id = 0;
balance = 0;
}
Account(int i, double b)   //Constructor with input parameters.
{
this->setID(i);
this->setBalance(b);
}
void setID(int i)   //Mutator for id.
{
id = i;
}
void setBalance(double b)   //Mutator for balance.
{
balance = b;
}
int getID()           //Accessor for id.
{
return id;
}
double getBalance()   //Accessor for balance.
{
return balance;
}
    bool withdraw(double amount)    //A function named withdraw(amount) that withdraws a specified amount from the account - by updating the balance.
    {
    if(amount > balance)
    return false;
    else
    {
    balance -= amount;
    return true;
    }
    }
    void deposit(double amount)   //A function named deposit(amount) that deposits a specified amount to the account.
    {
    balance += amount;
    }
};

void printMenu()
{
cout<<"ATM MACHINE ";
cout<<"1- Deposit ";
cout<<"2- Withdraw ";
cout<<"3- Exit ";
cout<<"Enter your choice: ";
}
int main()
{
double amount;
bool status;
Account acct (1, 100);   //Create one Account object with id=1 and initial balance=100.
cout<<"The balance in the account is: "<<acct.getBalance()<<endl;   //Display the user’s balance.
int choice = 0;
while(choice != 3)   //Till the users chooses to exit.
{
printMenu();   //Print the menu.
cin>>choice;   //Read the choice.
switch(choice)
{
case 1:  
           cout<<"Enter the amount to deposit: ";   //Read the deposit amount.
           cin>>amount;  
           acct.deposit(amount);       //Call the function to deposit.
           cout<<"The amount is credited to your account"<<endl;
           cout<<"The balance in the account is: "<<acct.getBalance()<<endl;   //Display the user’s balance.
           break;
case 2:
           cout<<"Enter the amount to withdraw: ";   //Read the withdrawal amount.
           cin>>amount;  
           status = acct.withdraw(amount);       //Call the function to withdraw.
           if(status)           //If withdrawal is successful.
           cout<<"The amount is debited from your account."<<endl;
           else           //If withdrawal fails.
           cout<<"Insufficient funds."<<endl;
           cout<<"The balance in the account is: "<<acct.getBalance()<<endl;   //Display the user’s balance.
           break;
case 3:   exit(0);
default:   cout<<"Invalid menu option."<<endl;
}
}
}