1. Engineering
  2. Computer Science
  3. objectives understanding data abstraction with user defined classes...

Question: objectives understanding data abstraction with user defined classes...

Question details

Objectives:

. Understanding data abstraction with user defined classes

. Practice using and writing user define class header files and implementation files

Instructions:

Download the supplemental files from Canvas. You are given a header file, implementation file,

and a main file. The header files and main files are written for you;

do not make any changes

.

Write the implementation of the functions below.

The class “debitAccountType” has the following functions:

debitAccountType(string, double);

A constructor that initializes customerName and availableBalance

void deposit(double);

increases availableBalance by the deposit amount

void withdrawal(double);

decreases availableBalance by the withdrawal amount only if there are enough funds. This

function is written for you.

void setName(string);

sets customerName

string getName() const;

returns customerName

double getBalance() const;

returns availableBalance

2 | P a g e

Your task is to complete the

debitAccountType.cpp

file.

Output:

Account name is First Tester.

Account Balance is $999.99

Balance after deposit is $1099.99

Balance after withdrawal is $599.99

After an attempted overdraft: Insufficient Funds.

Balance is still $599.99

Changing account name to Second Tester

Header file

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class debitAccountType
{
public:
   debitAccountType(string, double);
   void deposit(double);
   void withdraw(double);
   void setName(string);
   string getName() const;
   double getBalance() const;

private:
   string customerName;
   double accountBalance;
};

detbit account .......

#include <iostream>
#include <iomanip>
#include <string>
#include <"debitAccountType.h">

using namespace std;

debitAccountType::debitAccountType(string name, double openingBalance)
{
   // tip: use setName
}

void debitAccountType::deposit(double depositAmount)
{
   // tip: update accountBalance
}

//Given
void debitAccountType::withdraw(double withdrawAmount)
{
   if (accountBalance - withdrawAmount >= 0)
       accountBalance -= withdrawAmount;
   else
       cout << "Insufficient Funds." << endl;
}

void debitAccountType::setName(string name)
{

}

string debitAccountType::getName() const
{

}

double debitAccountType::getBalance() const
{

}

main....

#include <iostream>
#include <iomanip>
#include <string>
#include <"debitAccountType.h">

using namespace std;

int main()
{
   debitAccountType account1("First Tester", 999.99);

   cout << fixed << showpoint << setprecision(2);
   cout << "Account name is " << account1.getName() << "." << endl;
   cout << "Account Balance is $" << account1.getBalance() << endl;

   account1.deposit(100.00);
   cout << "Balance after deposit is $" << account1.getBalance() << endl;

   account1.withdraw(500.00);
   cout << "Balance after withdrawal is $" << account1.getBalance() << endl;

   cout << "After an attempted overdraft: ";
   account1.withdraw(800.00);
   cout << "Balance is still $" << account1.getBalance() << endl;

   account1.setName("Second Tester");
   cout << "Changing account name to " << account1.getName() << "." << endl;
  
   return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution