A bank charges $10.00 a month plus the following check fees for a commercial che
ID: 3805004 • Letter: A
Question
A bank charges $10.00 a month plus the following check fees for a commercial checking account. $ 0.10 each for 1-19 checks $ 0.08 each for 20-39 checks $ 0.06 each for 40-59 checks $ 0.04 each for 60 or more checks The bank also charges a low balance fee of $15.00 if the balance of the account falls below $400.00 (before any check fees are applied.) This program prompts the user for the beginning balance and the number of checks written. It then computes the bank's service charges for the month and directs the service fee report to an output file. The user is given the name of the data file to which the service charges have been reported when an appropriate sentence is displayed to the output screen. Input(keyboard): double begin_balance; int checks; Constants: MIN_BAL = 400.00 // minimum balance MONTHLY_FEE = 10.00 // base monthly fee LOW_BAL_FEE = 15.00 // low balance fee FEE_LEVEL1 = 0.10 // fee: 1-19 checks FEE_LEVEL2 = 0.08 // fee: 20-39 checks FEE_LEVEL3 = 0.06 // fee: 40-59 checks FEE_LEVEL4 = 0.04 // fee: 60 or more checks CHECK_LEVEL1 = 19 // 1-19 checks CHECK_LEVEL2 = 39 // 20-39 checks CHECK_LEVEL3 = 59 // 40-59 checks ======================================================================= Output Samples: ** BELOW MINIMUM balance/POSITIVE number of checks written ** Sample Console Output: Author's Name C.S.1428.25? Lab Section: L? --/--/-- <blank line> <blank line> Enter the following information about your checking account. Beginning balance: $100 Number of checks written: 10 The bank's service fees have been written to prog4_25?out.txt. Sample File Output(file - prog4_25?out.txt): Author's Name C.S.1428.25? Lab Section: L? --/--/-- <blank line> <blank line> Low balance fee applied: ??.?? Number of checks written: ?? Check fee applied: ??.?? Monthly fee applied: ??.?? Total banking fees: $ ??.?? ======================================================================= Output Samples: ** BALANCE EXCEEDS MINIMUM requirement/POSITIVE number of checks written ** Sample Console Output: Same Layout As Previous Example Screen Output Sample File Output(file - prog4_25?out.txt): Author's Name C.S.1428.25? Lab Section: L? --/--/-- <blank line> <blank line> Number of checks written: ?? Check fee applied: ??.?? Monthly fee applied: ??.?? Total banking fees: $ ??.?? ======================================================================= Output Samples: ** NEGATIVE balance/POSITIVE number of checks written ** Sample Console Output: Author's Name C.S.1428.25? Lab Section: L? --/--/-- <blank line> <blank line> Enter the following information about your checking account. Beginning balance: $-10 You entered a negative beginning balance. Your account is currently overdrawn! Number of checks written: 10 The bank's service fees have been written to prog4_25?out.txt. Sample File Output(file - prog4_25?out.txt): Same Layout As First Example File Output ======================================================================= Output Samples: ** BALANCE EXCEEDS MINIMUM requirement/NEGATIVE number of checks written ** Author's Name C.S.1428.25? Lab Section: L? --/--/-- <blank line> <blank line> Enter the following information about your checking account. Beginning balance: $550.50 Number of checks written: -10 Number of checks must be zero or more. Try again. Number of checks written: 10 The bank's service fees have been written to prog4_25?out.txt. Sample File Output(file - prog4_25?out.txt): Same Layout As Second Example File Output ======================================================================= The program is processed as follows: - The user's personal information is written to the console. - The user's personal information is written to a file. - The user is prompted for his/her beginning bank balance. - If a negative value is entered for the beginning balance, - an urgent message is written to the console indicating the account is overdrawn - Do - The user is prompted for the number of checks written - If a negative number of checks is entered - a message is written to the console indicating the number of checks must be zero or more; user is told to'try again' While the number of checks is less than zero - Calculate the check fee using a multi-way branch - If the account balance is less than the minimum monthly balance, - the total monthly fees are calculated (standard monthly fee + check fee + a low balance fee) - the low balance fee along with an appropriate message is written to the bank's monthly service fee report (file) otherwise (else) - the total monthly fees are calculated (standard monthly fee + check fee) - The bank's monthly service fee report is written to the file - A message is written to the console indicating the name of the file to which the bank's service fee report has been reported ======================================================================= All monetary output values are displayed to two decimal places. ======================================================================= <Output will vary based on actual input.> */
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
double MIN_BAL = 400.00; // minimum balance
double MONTHLY_FEE = 10.00; // base monthly fee
double LOW_BAL_FEE = 15.00; // low balance fee
double FEE_LEVEL1 = 0.10; // fee: 1-19 checks
double FEE_LEVEL2 = 0.08; // fee: 20-39 checks
double FEE_LEVEL3 = 0.06; // fee: 40-59 checks
double FEE_LEVEL4 = 0.04; // fee: 60 or more checks
int CHECK_LEVEL1 = 19; // 1-19 checks
int CHECK_LEVEL2 = 39; // 20-39 checks
int CHECK_LEVEL3 = 59; // 40-59 checks
double begin_balance;
int checks;
printf("Author's Name ");
printf("C.S.1428.25? ");
printf("Lab Section: L? ");
printf("--/--/-- ");
printf("Enter the following information about your checking account. ");
printf(" Beginning balance: $");
scanf("%lf", &begin_balance);
if (begin_balance < 0)
{
printf(" You entered a negative beginning balance. ");
printf(" Your account is currently overdrawn! ");
}
printf(" Number of checks written: ");
scanf("%d", &checks);
int isNegativeChecks = checks < 0;
if (isNegativeChecks)
{
printf(" Number of checks must be zero or more. ");
printf(" Try again. ");
}
printf(" The bank's service fees have been written to prog4_25?out.txt. ");
int isLowBalance = begin_balance < MIN_BAL;
double checkFees;
if (checks >= 0)
{
if (checks <= CHECK_LEVEL1)
{
checkFees = checks*FEE_LEVEL1;
}
else if(checks <= CHECK_LEVEL2)
{
checkFees = CHECK_LEVEL1*FEE_LEVEL1 + (checks-CHECK_LEVEL1)*FEE_LEVEL1;
}
else if(checks <= CHECK_LEVEL3)
{
checkFees = CHECK_LEVEL1*FEE_LEVEL1 +
(CHECK_LEVEL2-CHECK_LEVEL1)*FEE_LEVEL1 +
(checks - CHECK_LEVEL2)*FEE_LEVEL2;
}
else
{
checkFees = CHECK_LEVEL1*FEE_LEVEL1 +
(CHECK_LEVEL2-CHECK_LEVEL1)*FEE_LEVEL1 +
(CHECK_LEVEL3 - CHECK_LEVEL2)*FEE_LEVEL2 +
(checks - CHECK_LEVEL3)*FEE_LEVEL4;
}
}
double totalFees = 0;
FILE *fh = fopen("prog4_25?out.tx", "w");
fprintf(fh, "Author's Name ");
fprintf(fh, "C.S.1428.25? ");
fprintf(fh, "Lab Section: L? ");
fprintf(fh, "--/--/-- ");
if (isLowBalance && !isNegativeChecks)
{
fprintf(fh, "Low balance fee applied: %f ", LOW_BAL_FEE);
totalFees += LOW_BAL_FEE;
}
if (!isNegativeChecks)
{
fprintf(fh, "Number of checks written: %d ", checks);
fprintf(fh, "Check fee applied: %f ", checkFees);
totalFees += checkFees;
}
fprintf(fh, "Monthly fee applied: %f ", MONTHLY_FEE);
totalFees += MONTHLY_FEE;
fprintf(fh, " Total banking fees: %f ", totalFees);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.