Question
I need the C++ code for the following program: Instructions to Exercise 20 of Chapter 1 have been posted below for your convenience. Exercise 20
I need the C++ code for the following program:
Instructions toExercise 20ofChapter 1have been posted below for your convenience.
Exercise 20 (Assume that the account balance is stored in the fileCh4_Ex15_Data.txt.)
An ATM allows a customer to withdraw a maximum of $500 per day. If a customer withdraws more than $300, the service charge is 4% of the amount over $300. If the customer does not have sufficient money in the account, the ATM informs the customer about the insufficient funds and gives the customer the option to withdraw the money for a service charge of $25.00. If there is no money in the account or if the account balance is negative, the ATM does not allow the customer to withdraw any money. If the amount to be withdrawn is greater than $500, the ATM informs the customer about the maximum amount that can be withdrawn. Write an algorithm that allows the customer to enter the amount to be withdrawn. The algorithm then checks the total amount in the account, dispenses the money to the customer, and debits the account by the amount withdrawn and the service charges, if any.
Your program should output account balance before and after withdrawal and service charges. Also save the account balance after withdrawal in the fileCh4_Ex15_Output.txt.
Ensure the output inCh4_Ex15_Output.txtis accurate to two decimal places.
Analyze the requirements
- We need to know how much money the customer wishes to withdraw -> Ask the user to enter the amount to be withdrawn
- We need to know how much money the account holds -> Read the account balance from the database
- We need to determine if a withdrawal is allowed at all based on the amount to be withdrawn (amount $500). If it isn't allowed, inform the customer about the maximum amount.
- We need to determine if a withdrawal is allowed at all based on the account balance (balance > 0) . If it isn't allowed, inform the customer.
- We need to calculate the service charge for amounts over $300
- We need to calculate the service charge for insufficient funds
- We need to calculate the total account debits by adding the service charge for amounts over $300, the service charge for insufficient funds, and the withdrawal amount
- If allowed, we need to tell the machine to output the withdrawal amount
- We need to subtract the total account debits from the current account balance and save the new account balance to the database
- We need to inform the user what the starting balance is
- We need to inform the user what the service charges are
- We need to inform the user what the ending balance is
Design the algorithm to accomplish the requirements
- Get the withdrawal amount from the user
- Input the account balance from the data file
- Compare the withdrawal amount with $500
- If the withdrawal amount is greater than $500, display a message to the user that the maximum amount is $500 (we still need to output the balances)
- Compare the account balance with $0
- If the account balance is less than or equal to $0, display a message to the user that they do not have any funds to make a withdrawal and end the program
- Compare the withdrawal amount with $300
- If the withdrawal amount is greater than $300, calculate the over $300 service charge as 0.04 * (withdrawal amount - 300)
- Compare the withdrawal amount with the account balance
- If the withdrawal amount is greater than the account balance
- Display a message to the user that they do not have sufficient funds and that they will be charged $25 if they continue and ask the user if they wish to continue.
- Get the response from the user
- If they respond "no" end the program.
- Otherwise, calculate the insufficient funds service charge as $25
- If the withdrawal amount is greater than the account balance
- Calculate total account debits as withdrawal amount + over $300 service charge + insufficient funds service charge and save as total debit.
- Send a message to the machine to dispense the withdrawal amount.
- Subtract the total debit from the account balance and save the new account balance to the output file
- Display the account balance before the withdrawal
- Display the account balance after the withdrawal
- Display the total service charges
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started