Modify your checkbook balancing program from assignment 2 at follows: The user s
ID: 3670609 • Letter: M
Question
Modify your checkbook balancing program from assignment 2 at follows: The user should enter the transaction type and amount (if required) on a single line. In other words, there should km be a separate prompt message for the transaction amount. Use a separate function to do check processing and another function to do deposit processing Add additional service charges (see below). The program commands are as follows (see the sample program dialog near the bottom of this page) There is a $0.25 service charge for each check written. If the account balance falls below $800,00 at any time during the month, there is a $5,00 service charge for the month. If processing a check results in a negative balance, there is a $25 service charge (insufficient funds charge). This $25 fee is charged for each check that results m a negative balance For each transaction, print the command data (to confirm the transaction) the resulting account balance 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). 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 value. All dollar amounts should be pruned with 2 decimal places. Write a separate function to process each of the transaction types (check or deposit).Explanation / Answer
//Program:
#include <iostream>
#include <iomanip>
using namespace std;
double choiceC(double balance, double totalServCharge);
double choiceE(double balance, double totalServCharge);
double choiceD(double balance, double totalServCharge);
int main()
{
char choice = ' ';//user choice of transaction type
double balance = 0.0;//initial balance of the account
double totalServCharge = 0.0;
//set all amounts entered to have two decimal places displayed
cout<<fixed<<showpoint<<setprecision(2);
cout << "Modified Checkbook Balancing program " <<endl;
cout << "Please enter your beginning balance: ";
cin >> balance;
cout << endl;
//main menu
cout << "Please enter a transaction code using uppercase letters. "<<endl;
cout << "C - Process a Check"<<endl;
cout << "D - Process a Deposit"<<endl;
cout << "E - Do end of month processing and exit program"<<endl;
//how the program chooses what transaction to use
while (choice != 'E')
{
cout << "Transaction type: ";
cin >>choice;
//choice "c"
if (choice == 'C')
{
choiceC(balance,totalServCharge);
}
//choice 'd'
else if (choice == 'D')
{
choiceD(balance, totalServCharge);
}
else if (choice == 'E')
{
choiceE(balance,totalServCharge);
}
else
{
cout << "please enter a valid transaction type" << endl;
}
}
return 0;
}
double choiceC(double balance, double totalServCharge)
{
int numServCharge = 0;
int numLessEight = 0;
int numLessZero = 0;
const double SERVICE = .25;
const double LESSEIGHT = 5.0;
const double LESSZERO = 25.0;
double amount = 0.0;
cout << "please enter your tansaction amount: ";
cin >> amount;
//error statement if amount is negative
if (amount < 0)
{
cout << "a negative is a non-valid entry please try your transaction again"<<endl;
cout << "Please enter your transaction amount :";
cin >> amount;
}
//corect input by user
else if (amount > 0)
{
cout<<"Processing check for: $"<<amount<<endl;
}
//calculations for check balance
balance = balance - amount;
//balance condition statements
if (balance < 800)
{
cout << balance <<endl;
cout <<"Balance: "<<balance<<endl;
cout << "Service charge: $" << SERVICE << " for a check"<<endl;
cout << "serivce charge: $" << LESSEIGHT << " for a balance less than $800"<<endl;
numServCharge++;
numLessEight = 1;
}
else if (balance < 0)
{
cout <<"Balance: "<<balance<<endl;
cout << balance <<endl;
cout << "Service charge: $" << SERVICE << " for a check"<<endl;
cout << "Service charge: $" << LESSZERO << " for a balance less than $0.0" << endl;
numServCharge++;
numLessZero++;
totalServCharge = (numServCharge * SERVICE) + (numLessEight * LESSEIGHT) + (numLessZero * LESSZERO);
cout << totalServCharge <<endl;
return balance, totalServCharge;
}
}
double choiceD(double balance, double totalServCharge)
{
double amount = 0.0;
cout <<"Enter transaction amount: ";
cin >>amount;
//error statment for negative amount
if (amount < 0)
{
cout << "a negative is a non-valid entry please try your transaction again"<<endl;
cout << "Please enter your transaction amount :";
cin >> amount;
}
else if (amount > 0)
{
cout<<"Processing check for: $"<<amount<<endl;
}
cout<<"Processing deposit for: $"<<amount<<endl;
//calculate deposit amount
balance = balance + amount;
cout <<"Balance: "<<balance<<endl;
//calculate the total amount of service charges
cout <<"Total service charges: $"<<totalServCharge<<endl;
return balance, totalServCharge;
}
double choiceE(double balance, double totalServCharge)
{
cout <<"Processing end of the month "<<endl;
cout <<"Your total service charges were: $" <<totalServCharge <<endl;
cout <<"Final Balance: "<<balance - totalServCharge<<endl;
//if final balance is negative
if (balance < 0)
{
cout << "You owe us money!";
}
return 0;
}
//Output:
Modified Checkbook Balancing program
Please enter your beginning balance: 500
Please enter a transaction code using uppercase letters.
C - Process a Check
D - Process a Deposit
E - Do end of month processing and exit program
Transaction type: C
please enter your tansaction amount: 200
Processing check for: $200.00
300.00
Balance: 300.00
Service charge: $0.25 for a check
serivce charge: $5.00 for a balance less than $800
Transaction type: D
Enter transaction amount: 5000
Processing check for: $5000.00
Processing deposit for: $5000.00
Balance: 5500.00
Total service charges: $0.00
Transaction type: E
Processing end of the month
Your total service charges were: $0.00
Final Balance: 500.00
--------------------------------
Process exited after 17.73 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.