Menu

Need Help C Please Answer Thank Objectives Introducing User Defined Classes Data Abstracti Q43906983

Need Help With C++! Please answer this! Thankyou!

Objectives:

  • Introducing user defined classes and data abstraction.
  • Working with separate class header and implementationfiles.
  • Implementing default and parameterized constructors.
  • Working with member variables through get functions and setfunctions.
  • Instantiating a class object and testing its memberfunctions.

Instructions:

Download the following files from Canvas:Bank.h, Bank.cpp, andtestClient.cpp. Create a project in Visual Studiofor Lab03 and add these files to the project. Readand understand the given code. The Bank class holds a customer’sfirst name, last name, account number, and account balance. Theclass provides operations to set and access these member variables,print the data, deposit to the account, and withdraw from theaccount.

The Bank.h header file, where the class isdeclared, is written for you. The testClient.cppfile, where the class objects are instantiated and tested, is alsowritten for you. Please implement the member functions inBank.cpp according to the following TODO commentswritten in the given code.

Below is the codes

1)Bank.h

#ifndef BANK_H
#define BANK_H

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

using namespace std;

class Bank
{
public:
   Bank();
   Bank(string, string, string, double);
   void setFirstName(string);
   void setLastName(string);
   void setAccountNumber(string);
   void setAccountBalance(double);
   string getFirstName() const;
   string getLastName() const;
   string getAccountNumber() const;
   double getAccountBalance() const;

   bool deposit(double);
   bool withdrawal(double);
   void printRecord() const;

private:
   string firstName;
   string lastName;
   string accountNumber;
   double accountBalance;
};

#endif // !BANK_H

#pragma once

2) Need help with this Bank.cpp fileonly……

#include “Bank.h”

Bank::Bank()
{
   // TODO: Implement the default constructor.
   // This is the constructor that creates the objectwhen no
   // parameters are passed in at instantiation.

   // Set the customer’s first name to: unknown
   // Set the customer’s last name to: unknown
   // Set the customer’s account number to:000000000
   // Set the customer’s account balance to: 0.0
}

Bank::Bank(string fName, string lName, string aNumber, doubleaBalance)
{
   // TODO: Implement the parameterizedconstructor.
   // This is the constructor that creates the objectwhen
   // parameters are passed in at instantiation.

   // Set the customer’s first name using thecorresponding parameter.
   // Set the customer’s last name using thecorresponding parameter.
   // Set the customer’s account number using thecorresponding parameter.
   // Set the customer’s account balance using thecorresponding parameter.
}

void Bank::setFirstName(string fName)
{
   // TODO: Implement the setFirstName function.
   // Set the customer’s first name using theparameter.
}

void Bank::setLastName(string lName)
{
   // TODO: Implement the setLastName function.
   // Set the customer’s last name using theparameter.
}

void Bank::setAccountNumber(string aNumber)
{
   // TODO: Implement the setAccountNumberfunction.
   // Set the customer’s account number using theparameter.
}

void Bank::setAccountBalance(double aBalance)
{
   // TODO: Implement the setAccountBalancefunction.
   // If the value passed in the parameter is less thanzero,
   // set the customer’s account balance to zero. If thevalue
   // passed in the parameter is greater than or equal tozero,
   // set the customer’s account balance using theparameter.
}

string Bank::getFirstName() const
{
   // TODO: Implement the getFirstName function.
   // This function returns the customer’s firstname.
}

string Bank::getLastName() const
{
   // TODO: Implement the getLastName function.
   // This function returns the customer’s lastname.
}

string Bank::getAccountNumber() const
{
   // TODO: Implement the getAccountNumberfunction.
   // This function returns the customer’s accountnumber.
}

double Bank::getAccountBalance() const
{
   // TODO: Implement the getAccountBalancefunction.
   // This function returns the customer’s accountbalance.
}

bool Bank::deposit(double amount)
{
   // TODO: Implement the deposit function.
   // If the parameter value is greater than zero,process
   // the deposit by increasing the account balance bythe
   // parameter amount. Then return true to indicatethat
   // the deposit was successful.

   // If the parameter value is less than or equal tozero,
   // do not change the account balance. Just returnfalse
   // to indicate that the deposit was notsuccessful.
}

bool Bank::withdrawal(double amount)
{
   // TODO: Implement the withdrawal function.
   // If the parameter value is greater than zero, andif
   // completing the withdrawal would not result in anegative
   // account balance, process the withdrawal bydecreasing the
   // account balance by the parameter amount. Thenreturn true
   // to indicate that the withdrawal was successful.

   // Otherwise, do not change the account balance.Just return
   // false to indicate that the withdrawal was notsuccessful.
}

void Bank::printRecord() const
{
   cout << fixed << showpoint <<setprecision(2);
   cout << getFirstName() << ” ” <<getLastName() << endl;
   cout << “Account: ” << getAccountNumber()<< endl;
   cout << “Balance: $” <<getAccountBalance() << endl << endl;
}

3) Testclient.cpp

#include <iostream>
#include <string>
#include “Bank.h”

using namespace std;

int main()
{
   // creates an instance of the Bank class using thedefault constructor
   Bank account1;

   // creates an instance of the Bank class using theparameterized constructor
   Bank account2(“Devin”, “Soni”, “987664322”,799.84);

   cout << “Printing the account1 record…”<< endl;
   account1.printRecord();

   cout << “Printing the account2 record…”<< endl;
   account2.printRecord();

   // overwriting default values for account1
   account1.setFirstName(“Raimi”);
   account1.setLastName(“Karim”);
   account1.setAccountNumber(“779964321”);
   account1.setAccountBalance(419.00);

   cout << “The customer name for account1 hasbeen changed to: “;
   cout << account1.getFirstName() << ” “<< account1.getLastName() << endl << endl;

   cout << “Printing the account1 record…”<< endl;
   account1.printRecord();

   // testing deposit
   cout << “Attempting to deposit $200 toaccount1…” << endl;
   if (account1.deposit(200.00))
       cout << “Depositsuccessful.n”;
   else
       cout << “Deposit NOTsuccessful.n”;

   account1.printRecord();

   // testing unsuccessful withdrawal
   cout << “Attempting to withdraw $800 fromaccount2…” << endl;
   if (account2.withdrawal(800.00))
       cout << “Withdrawalsuccessful.n”;
   else
       cout << “Withdrawal NOTsuccessful.n”;

   account2.printRecord();

   // testing successful withdrawal
   cout << “Attempting to withdraw $19 fromaccount2…” << endl;
   if (account2.withdrawal(19.00))
       cout << “Withdrawalsuccessful.n”;
   else
       cout << “Withdrawal NOTsuccessful.n”;

   account2.printRecord();

   return 0;
}

Sample Output: Printing the accounti record... unknown unknown Account: 000000000 Balance: $0.00 Printing the account2 record

Sample Output: Printing the accounti record… unknown unknown Account: 000000000 Balance: $0.00 Printing the account2 record… Devin Soni Account: 987664322 Balance: $799.84 The customer name for account1 has been changed to: Raimi Karim Printing the account1 record… Raimi Karim Account: 779964321 Balance: $419.00 Attempting to deposit $200 to accounti… Deposit successful. Raimi Karim Account: 779964321 Balance: $619.00 Attempting to withdraw $800 from account2… Withdrawal NOT successful. Devin Soni Account: 987664322 Balance: $799.84 Attempting to withdraw $19 from account2… Withdrawal successful. Devin Soni Account: 987664322 Balance: $780.84 Program ended with exit code: Show transcribed image text Sample Output: Printing the accounti record… unknown unknown Account: 000000000 Balance: $0.00 Printing the account2 record… Devin Soni Account: 987664322 Balance: $799.84 The customer name for account1 has been changed to: Raimi Karim Printing the account1 record… Raimi Karim Account: 779964321 Balance: $419.00 Attempting to deposit $200 to accounti… Deposit successful. Raimi Karim Account: 779964321 Balance: $619.00 Attempting to withdraw $800 from account2… Withdrawal NOT successful. Devin Soni Account: 987664322 Balance: $799.84 Attempting to withdraw $19 from account2… Withdrawal successful. Devin Soni Account: 987664322 Balance: $780.84 Program ended with exit code:

Expert Answer


Answer to Need Help With C++! Please answer this! Thank you! Objectives: Introducing user defined classes and data abstraction. Wo…

OR