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

Format and specifications:

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

Make sure all identifiers are declared.

Variables contain values. Variable names should follow these standards:

  • Variable names must start with a lower case alphabet.

  • Variable names in the program should always be nouns, and not verbs.

    • For example, numberOfClasses is a valid variable name, displayName is not, since it sounds like an action, and not a container.

  • Variable names must be at least 5 characters long.

    • For example, naming a variable dist does not meet my programming standard, since it is only 4 characters long. Instead name it dist_from_home.

  • Variable names must be self-documenting. This means that the name of the variable should provide an indication of what it is being used for in a program.

    • For example, naming a variable _name does not meet my programming standard. Instead, use something like student_name or product_name

  • 1-character variable names are only permitted when used as a subscript variable to access an element in a list (in Python) or in an array (in C++).

  • Do NOT use global variables!

  • Do not write infinite loops with break statements.

Functions perform actions. Function names should follow these standards:

  • Function names must start with a lower case alphabet.

  • Function names in the program should always be verbs, and not nouns.

    • For example, displayName or disp_name is a valid function name, numberOfClasses is not, since it sounds like a container/variable.

  • Function names must be at least 5 characters long.

    • For example, naming a function disp does not meet my programming standard, since it is only 4 characters long. Instead name it something like disp_student_info.

  • Function names must be self-descriptive or self-documenting. This means that the name of the function should provide an indication of what it is being used for in a program.

    • For example, naming a function display does not meet programming standard. Instead, use display_student_name or display_instuct_name

  • Functions should not contain multiple return statements. Use decision structures to set up the value in a variable and return that variable from the function instead of using multiple return statements in a decision structure. (This standard does not apply to recursive functions)

  • The function definition for the main function should be before all other function definitions in the program.

Object names must be nouns, since they hold information about a business entity. Accessor and Mutator functions in a class must follow the following standards:

  • Mutator functions must be written as follows:

    • Mutator functions do not return a value

    • Mutator functions must start with the word set.

    • Mutator functions are invoked with 1 argument

  • Accessor functions must be written as follows:

    • Accessor functions always return a value

    • Accessor functions must start with the word get.

    • Accessor functions are invoked without any arguments

  • Do not use goto statements.

  • Statements inside a block should be indented.

  • Statements that execute as part of an if-block, should be on separate lines.

Functions in C++

Programs that contain functions must follow these guidelines:

  • The int main function must be the first function definition the the program

  • All other functions must be defined after int main.

  • Place function prototypes for all functions (except int main) before the int main function definition.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <iomanip>

using namespace std;

double getCheckFeesRate(int numberOfChecks);
void displayBankFees(int numberOfChecks, double fixedBankFees, double checkFeesRate, double checkFees, double totalBankFees);

int main(){
    int numberOfChecks;
    const double fixedBankFees = 15;
    double checkFeesRate, checkFees, totalBankFees;
    cout << "Number of checks written this month: ";
    if(cin >> numberOfChecks){
        if(numberOfChecks >= 0){
            //Get check fees rate
            checkFeesRate = getCheckFeesRate(numberOfChecks);
            //Calculate bank fees
            checkFees = numberOfChecks * checkFeesRate;
            totalBankFees = fixedBankFees + checkFees;
            //Display bank fees
            displayBankFees(numberOfChecks, fixedBankFees, checkFeesRate, checkFees, totalBankFees);
        }
        else{
            cout << "Number of checks must be zero or more.";
        }
    }
    else{
        cout << "Number of checks must be numeric";
    }
    return 0;
}

//Function to get check fees rate
double getCheckFeesRate(int numberOfChecks){
    double checkFeesRate;
    if (numberOfChecks >= 60)
        checkFeesRate = 0.04;
    else if (numberOfChecks >= 40)
        checkFeesRate = 0.06;
    else if (numberOfChecks >= 20)
        checkFeesRate = 0.08;
    else
        checkFeesRate = 0.10;
    return checkFeesRate;
}

//Function to display bank fees
void displayBankFees(int numberOfChecks, double fixedBankFees, double checkFeesRate, double checkFees, double totalBankFees){
    cout << "Fixed fees is $ " << setprecision(2) << fixed << fixedBankFees << endl;
    cout << "Check fees this month is $ " << setprecision(2) << fixed << checkFees << " ("
         << numberOfChecks << " Checks @ $" << checkFeesRate << " per check)" << endl;
    cout << "The bank fees this month is $ " << setprecision(2) << fixed << totalBankFees << endl;
}

OUTPUT FOR TEST RUN 1:

CAUsers Shubham\Desktop\Main.exe Number of checks written this month: asd Number of checks must be numeric Process exited aft

OUTPUT FOR TEST RUN 2:

CAUsers\Shubham\Desktop\Main.exe Number of checks written this month: -1 Number of checks must be zero or more. Process exite

OUTPUT FOR TEST RUN 3:

C:AUsers Shubham\Desktop Main.exe Number of checks written this month: 10 Fixed fees is $ 15.00 Check fees this month is $ 1.

OUTPUT FOR TEST RUN 4:

C:AUsers\Shubham\Desktop\Main.exe Number of checks written this month: 62 Fixed fees is $ 15.00 Check fees this month is $ 2.

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

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

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

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

  • (Must be written in Python) You've been asked to write several functions. Here they are: yourName()...

    (Must be written in Python) You've been asked to write several functions. Here they are: yourName() -- this function takes no parameters. It returns a string containing YOUR name. For example, if Homer Simpson wrote this function it would return "Homer Simpson" quadster(m) -- this function takes a value m that you pass it then returns m times 4. For example, if you passed quadster the value 7, it would return 28. isRratedMovieOK(age) -- this function takes a value age...

  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • Must be written in C++ Display results and comments Write a program that sorts a vector...

    Must be written in C++ Display results and comments Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions: 1. void selSort (vector <string> & v): sorts the vector using selection sort 2. void display (const vector <string> & v): displays the vector contents 3. int binSearch (const vector <string> & v, string key): searches...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did...

    c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did the program Except this time we modularize our program by writing functions, instead of writing the entire code in main. The program must have the following functions (names and purposes given below). Fot o tentoutefill datere nedefremfite You will have to decide as to what arguments must be passed to the functions and whether such passing must be by value or by reference or...

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