Question

Must be written in C++ Bank Charges A bank charges $15 per month plus the following...

Must be written in C++

Bank Charges

A bank charges $15 per month plus the following check fees for a commercial checking account:

  • $0.10 per check each for fewer than 20 checks (1-19)

  • $0.08 each for 20–39 checks

  • $0.06 each for 40–59 checks

  • $0.04 each for 60 or more checks

Write a program that asks for the number of checks written during the past month, then computes and displays the bank’s fees for the month.

Input Validation:

  • Display an error message if input is not numeric

  • Display an error message if input is numeric and less than 0.

  • Do not compute a service fee if input is non-numeric or negative

  • Make sure that the dollar amount is displayed with 2 places after the decimal point

Note: The switch statement cannot be used here since there is no "equal to" condition. The conditions deal with values in a range.

Sample output from my version of Assignment 2

The following table shows 3 test runs of the program. Use input is shown in blue, highlighted text.

Test Run 1

Number of checks written this month: asd

Number of checks must be numeric.

Test Run 2

Number of checks written this month: -1

Number of checks must be zero or more.

Test Run 3

Number of checks written this month: 10

Fixed fees            is $ 15.00

Check fees this month is   $ 1.00 (10 Checks @ $0.10 per check)

The bank fee this month is $ 16.00

Test Run 4

Number of checks written this month: 62

Fixed fees            is $ 15.00

Check fees this month is   $ 2.48 (62 Checks @ $0.04 per check)

The bank fee this month is $ 17.48

Make sure that the dollar amount is displayed with 2 places after the decimal point.

Make sure all identifiers are declared.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>
//iomanip for format of float digits
#include<iomanip>

using namespace std;

bool isValid(string str)
{
//trim the string if spaces are present
for(int i = 0; i < str.length()-1; i++)
{
if(str[i] == 32)
{
str[i]=str[i+1];
}
}
for(int i = 0; i < str.length(); i++)
{
if(str[0] == '-')
continue;
if(isdigit(str[i]))
continue;
return false;
}
return true;
}

void print_fee(int checks)
{
const double basic_fee=15;
double fee;

if(checks>=1 && checks < 20)
{
cout << fixed;
   cout<<setprecision(2);
   fee=0.10 *checks;
   cout<<"Check fees this month is $"<<fee<<"("<<checks<<" @ $0.10 per check)"<<endl;
}
else if(checks>=20 && checks < 40)
{
fee=0.08 *checks;
cout<<"Check fees this month is $"<<fee<<"("<<checks<<" @ $0.08 per check)"<<endl;
}
else if(checks>=40 && checks < 60)
{
fee=0.06 *checks;
cout<<"Check fees this month is $"<<fee<<"("<<checks<<" @ $0.06 per check)"<<endl;
}
else
{
fee=0.04*checks;
cout<<"Check fees this month is $"<<fee<<"("<<checks<<" @ $0.04 per check)"<<endl;
}
cout<<"The bank fee this month is $"<<(fee+basic_fee)<<endl;
}


int main() {
   // your code goes here
   string input;
  
   cout<<"Number of checks written this month: ";
   cin>>input;
  
   if(isValid(input) == false)
   {
   cout<<"\nNumber of checks must be numeric."<<endl;
   return -1;
   }
   if(stoi(input) < 0)
   {
   cout<<"\nNumber of checks must be zero or more."<<endl;
   return -1;
   }
   cout<<"\nFixed fees is $15.00 "<<endl;
  
   print_fee(stoi(input));
   return 0;
}

==================

//testrun1

Number of checks written this month: asd

Number of checks must be numeric.

//testrun2

Number of checks written this month: -1

Number of checks must be zero or more.

//testrun3

Number of checks written this month: 10

Fixed fees            is $ 15.00

Check fees this month is   $ 1.00 (10 Checks @ $0.10 per check)

The bank fee this month is $ 16.00

//testrun4

Number of checks written this month: 62
Fixed fees is $15.00
Check fees this month is $2.48(62 @ $0.04 per check)
The bank fee this month is $17.48

Add a comment
Know the answer?
Add Answer to:
Must be written in C++ Bank Charges A bank charges $15 per month plus the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Must be written in C++ Bank Charges A bank charges $15 per month plus the following...

    Must be written in C++ Bank Charges A bank charges $15 per month plus the following check fees for a commercial checking account: $0.10 per check each for fewer than 20 checks (1-19) $0.08 each for 20–39 checks $0.06 each for 40–59 checks $0.04 each for 60 or more checks Write a program that asks for the number of checks written during the past month, then computes and displays the bank’s fees for the month. Input Validation: Display an error...

  • C++ A bank charges $10 per month plus the following check fees for a commercial checking...

    C++ A bank charges $10 per month plus the following check fees for a commercial checking account: $.10 each for fewer than 20 checks $.08 each for 20-39 checks $.06 each for 40-59 checks $.04 each for 60 or more checks The bank also charges an extra $15 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of checks written. Compute and...

  • Java Bank program A bank charges a base fee of $10 per month, plus the following...

    Java Bank program A bank charges a base fee of $10 per month, plus the following check fees for a commercial checking account:     $.10 each for less than 20 checks     $.08 each for 20–39 checks     $.06 each for 40–59 checks     $.04 each for 60 or more checks Write a program that asks for the number of checks written for the month. The program should then calculate and display the bank’s service fees for the month.

  • Im opening a corporate bank account. Bank A charges a fixed monthly fee of $120 plus...

    Im opening a corporate bank account. Bank A charges a fixed monthly fee of $120 plus 10 cents per check written. Bank B charges a fixed monthly fee of $100 plus 14 cents per check written. (a). Sketch the graphs of the functions A(x) and B(x) which represents the monthly cost of banking at the two banks, where x is the number of checks written in the month. Label the y-axis intercepts and find the coordinates of the point where...

  • QUESTION 4 The following information is collected when recording Scofield Company bank statement for the month of June. RM7,328 Balance per books June 30 Balance per bank statement June 30 RM21,800 C...

    QUESTION 4 The following information is collected when recording Scofield Company bank statement for the month of June. RM7,328 Balance per books June 30 Balance per bank statement June 30 RM21,800 Checks written in June but still outstanding RM14,009 Checks written in Maybut still outtanding RM6,200 Deposits of June 29 and 30 not yet recorded by bank RM10.400. . NSF check of customer returned by bank RM2.400, . Check No. 200 for RM1,186 was correctly issued and paid by bank...

  • This program should be written in C Thoroughly following the Code Conventions, write an efficient program,...

    This program should be written in C Thoroughly following the Code Conventions, write an efficient program, which ask the user for their numeric grade, and determines and displays the equivalent letter grade, based on the following information: Use appropriate data types and initialize the variables correctly Use the following grading scale: A: 90 - 100 B: 80 - < 90 C: 70 - < 80 D: 60 - < 70 F: 0 - < 60 If the input is invalid,...

  • Question Help Bank for the month of March E9-17 (similar to) The following information is from...

    Question Help Bank for the month of March E9-17 (similar to) The following information is from the books of Solar Company for the month of March Astro Soler received the following bank statement from YRTS Click the icon to view the bankstament) Read the moment The balance in Sou's h unt on March 31314540 Astro Solar Company Bacon March 31 Requirement Balance March Prepare a concor Astra by deg the combines for both bockandbank Record wil jou antros de correct...

  • orange corporation uses the following items for its bank reconciliation for the month of April balance...

    orange corporation uses the following items for its bank reconciliation for the month of April balance per books april 30 $905 1. Orange Corporation uses the following items for its bank reconciliation for the month of April. Balance per books April 30 $ 905 Balance per bank statement April 30 $11,300 (1) Checks written in April but still outstanding $6,300. (2) Checks written in March but still outstanding $2,800. (3) Deposits of April 30 not yet recorded by bank $4,900....

  • Must be done in C# please! Thanks! In this assignment you will create a program named...

    Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT