Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a C++ class in a file checking.h with the following declaration: class ch

ID: 3917403 • Letter: D

Question

Define a C++ class in a file checking.h with the following declaration:

class checking

{

      private:

         string Name;

         int AcctNum;

         char Type

         double CurrBalance;

         double OverDraftBalance;

         double OverDraftLimit;

      public:

         checking();

         void input ();

         void deposit (double amount);

         void withdraw (double amount);

         void updatelimit (double lim);

         void updatetype (char type);

         void output ();

};

The private data represents checking account information for a bank customer. It contains the customer’s name, account type, account number, current balance, overdraft balance and overdraft limit.

The public methods (functions) are:

checking : Constructor that sets name to “unassigned”, type to ‘D’ the other values to zero.

input: Prompts the user for name, account type, account number, current balance, overdraft balance and overdraft limit and sets the private data values to these user entered values. Checks for a valid type (‘D’, ‘S’, ‘P’) and valid value for current balance. The current balance cannot be negative nor over 9,999. If any of these error conditions occurs, an error message should be outputted and no values should be set.

deposit: Increases the checking account’s current balance by the given amount. The amount cannot be negative nor over 9,999. If the deposit amount is negative or over 9,999, an error message should be outputted and the current balance not changed.

withdraw : Decreases the checking account’s current balance by the given amount. If the decrease causes the checking account’s current balance to become negative, then add the absolute amount below zero to the overdraft balance. If the overdraft balance is greater than the overdraft limit, output an error message and reset the current balance and the overdraft balance to their original values. If the inputted withdrawal amount is negative or over 9,999, an error message should be outputted and the current balance not changed.

Example 1 :

Before :                                                   After:

Withdrawal amount = $150

Current balance = $100                    Current balance = $0

Overdraft balance = $50                   Overdraft balance = $100

Overdraft limit = $250                      Overdraft limit = $250

Example 2 :

Before :                                                   After:

Withdrawal amount = $300

Current balance = $100                    Current balance = $100

Overdraft balance = $150                 Overdraft balance = $150

Overdraft limit = $250                      Overdraft limit = $250

In this case, the message “Overdraft Limit exceeded” appears and the values do not change.

updatelimit: Replace the overdraft limit with the given amount. If the given amount is negative or over 2000, an error message should be outputted and the values not changed.

updatetype: Replace the type with the given value. If the given value is not equal to D or S or P, an error message should be outputted and the values not changed.

output: Output the checking account information in the format shown below.

It also computes and outputs the deposit overdraft ratio (DOR) using the following formula :

DOR = OverDraftBalance/CurrBalance X                  

                          (OverDraftBalance/OverDraftLimit)

     

The DOR should be outputted with two places after the decimal followed by the % sign. See the example for the format the output should follow.

Write the program that utilizes the checking object. It should be menu driven with choices for inputting a checking account’s data, deposits, withdrawals, updating the overdraft limit, updating the account type, outputting the account’s information

and quitting. Your program should follow the formatting given by the following example (input shown in bold). Note: there are a number of choices and error conditions not shown in this example. You should test all of these before handing in your program.

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: o

Acct number : 0000       Name:   unassigned        

Acct Type : D           

Curr Bal :      $    0.00

Overdraft Limit $    0.00

Overdraft Bal : $    0.00

Deposit/OD ratio : 0.00 %

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: e

Enter name: Meyers

Enter Account Number : 4812

Enter Account Type   :    S

Enter Balance    $ : 1500.00

Enter OD Limit   $ :    500.00

Enter OD Balance $ :   303.00

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: o

Acct number : 4812       Name:   Meyers        

Acct Type : S           

Curr Bal :      $ 1500.00

Overdraft Limit $   500.00

Overdraft Bal : $   303.00

Deposit/OD ratio : 0.12 %

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: d

Enter deposit amount $ : 250

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: w

Enter withdrawal amount $ : 100

Enter one of the following:

  e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: l

Invalid entry, please try again!

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: o

Acct number : 4812       Name:   Meyers        

Acct Type : S           

Curr Bal :      $ 1650.00

Overdraft Limit $   500.00

Overdraft Bal : $   303.00

Deposit/OD ratio : 0.11 %

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: d

Enter deposit amount $ : -750

Deposit amount must be positive!

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: e

Enter name: Wilson

Enter Account Number : 1125

Enter Account Type   :    P

Enter Balance    $ :   -123.00

Enter OD Limit   $ :    200.00

Enter OD Balance $ :      3.00

Illegal data entry! You'll need to try again!

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: o

Acct number : 4812       Name:   Meyers        

Acct Type : S           

Curr Bal :      $ 1650.00

Overdraft Limit $   500.00

Overdraft Bal : $   303.00

Deposit/OD ratio : 0.11 %

Enter one of the following:

e: Enter checking account information

d: Make deposit

w: Make withdrawal

l: Update overdraft limit

t: Update account type

o: Output account information

q: Quit the program

Command: q

Program ended.

Explanation / Answer


#include "checking.h"
#include <iostream>
#include <iomanip>
using namespace std;
checking::checking()
{
Name = "unassigned";
Type = 'D';
AcctNum = 0;
CurrBalance = 0;
OverDraftBalance = 0;
OverDraftLimit = 0;

}

void checking::input ()
{
char t;
double amt;

cout << "Enter name: ";
cin >> Name;

cout << "Account type (D/S/P): ";
cin >> t;
if(t == 'D' || t == 'S' || t == 'P')
Type = t;
else
{
cout << "Invalid account type! " << endl;
}

cout << "Enter current balance(0-9999): ";
cin >> amt;
if(amt < 0 || amt > 9999)
cout << "Invalid current balance!" << endl;
else
CurrBalance = amt;

cout << "Enter overdraft balance: ";
cin >> OverDraftBalance;

cout << "Enter overdraft limit: ";
cin >> OverDraftLimit;

}

void checking::deposit (double amount){
if(amount < 0 || amount > 9999)
cout << "Invalid deposit amount! Should be in range 0-9999." << endl;
else
CurrBalance += amount;
}

void checking::withdraw (double amount){
if(amount < 0 || amount > 9999)
cout << "Invalid withdrawal amount! Should be in range 0-9999." << endl;
else {
double oldCurBal = CurrBalance, oldOverdraftBal = OverDraftBalance;
CurrBalance -= amount;
if(CurrBalance < 0)
{
OverDraftBalance += (-CurrBalance);
if(OverDraftBalance > OverDraftLimit) //more than overdraft limit , reset to old values
{
cout << "Overdraft Limit exceeded" << endl;
CurrBalance = oldCurBal;
OverDraftBalance = oldOverdraftBal;
}
}

}

}

void checking::updatelimit (double lim){
if(lim < 0 || lim > 2000)
cout << "Invalid overdraft limit! Should be in range 0-2000." << endl;
else {
OverDraftLimit = lim;
}

}

void checking::updatetype (char type){
if(type == 'D' || type == 'S' || type == 'P')
Type = type;
else
{
cout << "Invalid account type! " << endl;
}
}

void checking::output (){
cout << setprecision(2); //show 2 decimal places
cout << "Current balance: $" << CurrBalance << endl;
cout << "Overdraft balance: $" << OverDraftBalance << endl;
cout << "Overdraft limit: $" << OverDraftLimit << endl;

if(CurrBalance != 0 && OverDraftLimit != 0){
double DOR = OverDraftBalance/CurrBalance * (OverDraftBalance/OverDraftLimit);
cout << "Deposit Overdraft Ratio DOR: " << DOR << "%" << endl;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote