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

**please explain as in depth as possible and with //comments**

Thanks for helping me learn c++, I picked a unique hobby to learm this summer :)

Explanation / Answer


Given below is the implementation of the class in checking.cpp file. You may test with your driver program.
Please do rate if it helped.

checking.cpp
------------
#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