Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Start with your checkbook balancing program from assignment 2 that helps you balance a checkbook at the end of a monthly statement period. Modify your

Start with your checkbook balancing program from assignment 2 that helps you balance a checkbook at the end of a monthly statement period. Modify your program as follows:

The user should enter the transaction type and amount (if required) on a single line. If there is a problem with the command (invalid transaction type or invalid amount), print an error message and have the user re-enter the whole command. You should never have a separate prompt for just the transaction type or for just the transaction amount. Note that this means that you do not need validation loops. The validation is done using selection (if or switch) inside the main transaction processing loop. You just need the one transaction processing loop that reads a command on each iteration.

You must divide your program into at least three different functions: a main function, a check-processing function and a deposit-processing function. You can add other functions if you want to.

Add additional service charges as described below.

Allow the program to start with an initial balance that is positive, zero or negative. There are no restrictions on the starting balance. This means is that the user could start a month with a negative balance.

These changes may require substantial reorganization of your program.

Program Input

The program commands (user input) are as follows (see the sample program dialog near the bottom of this page).

Transaction command

Meaning

C amount

Process a check for amount dollars, where amount is a floating-point number.

D amount

Process a deposit for amount dollars, where amount is a floating-point number.

E

Perform end-of-month processing and end the program.

Service Charges

There is a $0.35 service charge for each check written.

If the account balance falls below $1000.00 at any time during the month, there is a $10.00 service charge (low balance charge) for the month. If the balance stays at $1000 or more during the entire monthly statement period (program execution), there is no low balance charge for the month. Otherwise, there is a single $10.00 low balance charge for the month.

If processing a check results in a negative balance, there is a $30.00 service charge (insufficient funds charge). This $30.00 fee is charged for each check that results in a negative balance.

Note: Do not any deduct service charges from the account balance until the end of the month.

Program Output

For each transaction, print:

the transaction type and the amount (if any)

the resulting account balance

the type and amount of any new service charges resulting from the transaction

the total service charges accrued so far

At the end of the month, deduct the service charges and print the final balance. Your program dialog should look something like this example (user input is shown in bold).

Enter the beginning balance: 1200 Enter a transaction: C 50.25 Processing check for $50.25 Balance: $1149.75 Service charge: $0.35 for a check Total service charges: $.35 Enter a transaction: C 250 Processing check for $250.00 Balance: $899.75 Service charge: $0.35 for a check Service charge: $10.00 balance below $1000.00 Total service charges: $10.70 Enter a transaction: D 200 Processing deposit for $200.00 Balance: $1099.75 Total service charges: $10.70 Enter a transaction: E Processing end of month Final balance: $1089.05

Other requirements

Do not use global variables in any assignment. A global variable is a variable that is declared outside any function.

All input should be checked for reasonable values. You do not have to check for input that causes the stream to fail.

All dollar amounts should be printed with 2 decimal places.

Write a separate function to process each of the transaction types (check or deposit).

Previous Code

#include

#include

#include

using namespace std;

float checkingProc(float, float, float,float, int);

float deposits(float, float, float);

float procEnd(float, float);

int main ()

{

float bal;

char typeOfTrans;

float amt;

int end = 0;

float serv;

const float serv1 = 0.25;

int below = 0;

cout << "Checkbook Balancing Program ";

cout<<"C - check processing, write a check for x amount. Note: associated fees will be charged (including overage)."<

cout<<"D - deposit processing, deposit x amount."<

cout<<"E - end of month processing. Total deductions will be applied and final balance will be displayed."<

cout << "Enter the beginning balance: ";

cin >> bal;

floor(bal*pow(10,2))/pow(10,2);

while ( end == 0){

cout << " Enter a transaction: ";

cin >> typeOfTrans ;

if (typeOfTrans == 'C'){

cin >> amt;

serv += serv1;

floor(serv*pow(10,2))/pow(10,2);

bal = checkingProc(bal, serv1, serv, amt, below);

if (bal < 800 && below == 0){

serv += 5;

below = 1;

}

if (bal < 0)

serv +=25;

}

else if (typeOfTrans == 'D'){

cin >> amt;

if (amt < 0)

cout << "Enter a valid transaction. ";

else

bal = deposits(bal, serv, amt);

}

else if (typeOfTrans == 'E'){

cout << "Processing end of month";

procEnd(bal, serv);

end = 1;

}

else

cout << "Enter a valid transaction type. ";

}

return 0;

}

float checkingProc(float bal, float serv1, float serv, float amt, int below){

cout << "Processing check for $" << amt;

bal -= amt;

floor(bal*pow(10,2))/pow(10,2);

cout << " Balance: $";

cout << setprecision(2) << fixed << bal;

cout << " Service charge: $" << serv1;

cout << " for a check";

if (bal < 800 && below == 0){

cout << " Service charge: $5.00 bal below $800.00";

serv += 5.0;

}

if (bal < 0){

cout << " Service charge: $25.00 negative account bal";

serv += 25;

}

cout << " Total service charges: $" ;

cout << setprecision(2) << fixed << serv;

cout << " ";

return bal;

}

float deposits(float bal, float serv, float amt){

while (amt <= -1 ){

amt = 1;

cin >> amt;

if (!(amt > 0))

cout << " Please enter a positive number: ";

}

cout << "Processing deposit for $" << amt;

bal += amt;

floor(bal*pow(10,2))/pow(10,2);

cout << " Balance: $";

cout << setprecision(2) << fixed << bal;

cout << " Total service charges: $";

cout << setprecision(2) << fixed << serv;

cout << " ";

return bal;

}

float procEnd(float bal, float serv){

bal -= serv;

cout << " Final bal: $";

cout << setprecision(2) << fixed << bal;

return bal;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

What is the difference between a growth company and a growth stock?

Answered: 1 week ago