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.

  • Using Python write a code for Function 1: A bank charges $10 per month plus the...

    Using Python write a code for Function 1: A bank charges $10 per month plus the following check fees for a commercial checking account: a. $0.10 each for 1-19 checks b. $0.08 each for 20-39 checks c. $0.06 each for 40-59 checks d. $0.04 each for 60 or more checks. (Note that the same fee is charged for all checks. If the customer writes 21 checks, all 21 checks are billed at the $0.08 rate.) The bank also charges an...

  • Python Question A bank charges a base fee of $10 per month plus the following check...

    Python Question 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 to 29 checks $.06 each for 40 to 59 checks $.04 each for 60 or more checks Write a program that asks for the number of checks per month (integer) and displays the fee 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,...

  • Write a menu driven program to demonstrate the use of array and switch. It must be...

    Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...

  • 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...

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