Write the program that utilizes the checking object. It should be menu driven wi
ID: 3911079 • Letter: W
Question
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.
*************************checking object listed here *************************************************
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;
}
}
***************************please explain as in depth as possible and with //comments*******************************
Thanks for helping me learn c++, I picked a unique hobby to learn this summer :)
Explanation / Answer
checking.cpp
------------
#include "checking.h"
#include <iostream>
// header file includede for input output stream
#include <iomanip>
using namespace std; //namespace to differentiate same names of classes,functions,etc
checking::checking()
// way to define constructor checking() of checking class,to initialise default values to data members
{
Name = "unassigned";
// default values initialised
Type = 'D';
AcctNum = 0;
CurrBalance = 0;
OverDraftBalance = 0;
OverDraftLimit = 0;
}
void checking::input() // void input() function of checking class is defined here with its body
{
char t;
double amt;
cout << "Enter name: ";
//cout is used to display to console
cin >> Name; //cin is used to take input from console typed by user
cout << "Account type (D/S/P): ";
cin >> t;
if(t == 'D' || t == 'S' || t == 'P') // == is relational operator used to check whether t is equal to 'D' , 'S' , 'P' types or not
// when condition inside if braces () is true ,if block executes otherwise else
// pipe symbol || is OR operator. gives false when both conditions are false, otherwise true
Type = t;
else
{
cout << "Invalid account type! " << endl;
}
cout << "Enter current balance(0-9999): ";
cin >> amt;
if(amt < 0 || amt > 9999) // >,>=,<,<=,==,!= are six relational operators in C++
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) // deposit function with a parameter amount that can be used inside function
{ // function opening braces, function body(statements inside function) starts here
if(amount < 0 || amount > 9999)
cout << "Invalid deposit amount! Should be in range 0-9999." << endl;
else
CurrBalance += amount; // amount added to balance in bank account
} // function ends here
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; //inside withdraw function, amount withdrawn is deducted from balance.
// -= is the shorthand operator. Expression used means the same as CurrBalance = CurrBalance - amount.
if(CurrBalance < 0)
{
OverDraftBalance += (-CurrBalance); // OverDraftBalance = 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) //updatelimit function with lim parameter of type double.Various data types are in C++.Int,double,float,etc
{
if(lim < 0 || lim > 2000)
cout << "Invalid overdraft limit! Should be in range 0-2000." << endl;
else
{
OverDraftLimit = lim;
}
}
void checking::updatetype (char type) // function updatetype(char type) with parameter type having data type char
{
if(type == 'D' || type == 'S' || type == 'P')
Type = type;
else
{
cout << "Invalid account type! " << endl;
}
}
void checking::output () // function 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); // DOR formula. * multiplication operator and / is division
cout << "Deposit Overdraft Ratio DOR: " << DOR << "%" << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.