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

For this programming assignment, you will simulate a bank\'s automated teller ma

ID: 3843914 • Letter: F

Question

For this programming assignment, you will simulate a bank's automated teller machine (ATM) that allows for deposits, withdrawals, and balance inquiries. An input file (named balances.txt) contains the account balances of twenty (25) customers; these values must be read into an array. You will create a menu-driven program that will allow the customer to deposit an amount, withdraw an amount, and/or view the account's balance. Your program will contain at least three (3) user-defined functions with the following names and descriptions: deposit: Prompts the user for the account number (i.e., a number between 1 and 25) and the amount to deposit; updates the customer's balance. The deposit amount must be at least $5. withdrawal: Prompts the user for the account number (i.e., a number between 1 and 25) and the amount to withdraw; updates the customer's balance. If the customer's balance is less than the $25 minimum balance requirement, the program notifies the user and does not allow the withdrawal. displayBalance: Displays the customer's account number and balance. If the customer's balance is less than the $25 minimum balance requirement, the program notifies the user that withdrawals are not allowed until the balance reaches $25. Once the user is ready to quit the program, your program will write to an output file (named .txt) all of the customers' account numbers and their balances. Successful completion of this assignment includes (but is not limited to): Use of f streams, selection, repetition, user-defined functions, arrays, and secure coding practices in this program Properly named .cpp file Inclusion of the algorithm used to develop your program as comments within your program A program that compiles and executes properly A program that properly reads data from the input file, performs the menu operations, and displays the adjusted customer balances and their account numbers in an output file.

Explanation / Answer

#include <fstream>
#include <iostream>
using namespace std;

class ATM{
   double balance[26];
public:
   ATM(){
       //reads balances.txt for input
       ifstream in("balance.txt");
       for(int i = 1; i <= 25; i++){
           in >> balance[i];
       }
       return;
   }
   void deposit(){
       int accountNo;
       cout << "Enter the account of user : ";
       cin >> accountNo;
       if( accountNo < 1 || accountNo > 25 ){
           cout << "Invalid account number" << endl;
           return;
       }
       double deposit;
       cout << "Enter the amount of deposit : ";
       cin >> deposit;
       if( deposit < 5.0 ){
           cout << "Deposit amount less than $5, not allowed" << endl;
           return;
       }
       else{
           balance[ accountNo ] += deposit;
       }
   }
   void withdrawl(){
       int accountNo;
       cout << "Enter the account of user : ";
       cin >> accountNo;
       if( accountNo < 1 || accountNo > 25 ){
           cout << "Invalid account number" << endl;
           return;
       }
       if( balance[accountNo] < 25.0 ){
           cout << "The customer's balance is less than $25. Withdrawl not allowed" << endl;
           return;
       }
       double withdrawl;
       cout << "Enter the amount to withdraw : ";
       cin >> withdrawl;
       if( withdrawl > balance[ accountNo ] ){
           cout << "Withdrawl amount more than the account balance" << endl;
           return;
       }
       else{
           balance[ accountNo ] -= withdrawl;
       }
   }
   void displayBalance(){
       cout << "Account Number : Balance" << endl;
       for(int i = 1; i <= 25; i++){
           cout << i << " : " << balance[i];
           if( balance[i] < 25 ){
               cout << " Withdrawls not allowed";
           }
           cout<< endl;
       }
   }  
};

void displayMenu(){
   cout << "Option 1 to make a deposit" << endl;
   cout << "Option 2 to make a withdrawl" << endl;
   cout << "Option 3 to display a balance" << endl;
}

int main(){
   ATM newATM;
   int option;
   while( true ){
       displayMenu();
       cout << "Enter your option : ";
       cin >> option;
       if( option == 1 ){
           newATM.deposit();
       }
       else if( option == 2 ){
           newATM.withdrawl();
       }
       else if( option == 3 ){
           newATM.displayBalance();
       }
       else{
           cout << "Incorrect Option. Please enter again" << endl;
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote