Question
Need Help With C++! Please answer this! Thank you! Objectives: Introducing user defined classes and data abstraction. Working with separate class header and implementation files.
Need Help With C++! Please answer this! Thank you!
Objectives:
- Introducing user defined classes and data abstraction.
- Working with separate class header and implementation files.
- Implementing default and parameterized constructors.
- Working with member variables through get functions and set functions.
- Instantiating a class object and testing its member functions.
Instructions:
Download the following files from Canvas: Bank.h, Bank.cpp, and testClient.cpp. Create a project in Visual Studio for Lab03 and add these files to the project. Read and understand the given code. The Bank class holds a customers first name, last name, account number, and account balance. The class provides operations to set and access these member variables, print the data, deposit to the account, and withdraw from the account.
The Bank.h header file, where the class is declared, is written for you. The testClient.cpp file, where the class objects are instantiated and tested, is also written for you. Please implement the member functions in Bank.cpp according to the following TODO comments written in the given code.
Below is the codes
1)Bank.h
#ifndef BANK_H #define BANK_H
#include
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 file only......
#include "Bank.h"
Bank::Bank() { // TODO: Implement the default constructor. // This is the constructor that creates the object when 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, double aBalance) { // TODO: Implement the parameterized constructor. // This is the constructor that creates the object when // parameters are passed in at instantiation.
// Set the customer's first name using the corresponding parameter. // Set the customer's last name using the corresponding parameter. // Set the customer's account number using the corresponding parameter. // Set the customer's account balance using the corresponding parameter. }
void Bank::setFirstName(string fName) { // TODO: Implement the setFirstName function. // Set the customer's first name using the parameter. }
void Bank::setLastName(string lName) { // TODO: Implement the setLastName function. // Set the customer's last name using the parameter. }
void Bank::setAccountNumber(string aNumber) { // TODO: Implement the setAccountNumber function. // Set the customer's account number using the parameter. }
void Bank::setAccountBalance(double aBalance) { // TODO: Implement the setAccountBalance function. // If the value passed in the parameter is less than zero, // set the customer's account balance to zero. If the value // passed in the parameter is greater than or equal to zero, // set the customer's account balance using the parameter. }
string Bank::getFirstName() const { // TODO: Implement the getFirstName function. // This function returns the customer's first name. }
string Bank::getLastName() const { // TODO: Implement the getLastName function. // This function returns the customer's last name. }
string Bank::getAccountNumber() const { // TODO: Implement the getAccountNumber function. // This function returns the customer's account number. }
double Bank::getAccountBalance() const { // TODO: Implement the getAccountBalance function. // This function returns the customer's account balance. }
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 by the // parameter amount. Then return true to indicate that // the deposit was successful.
// If the parameter value is less than or equal to zero, // do not change the account balance. Just return false // to indicate that the deposit was not successful. }
bool Bank::withdrawal(double amount) { // TODO: Implement the withdrawal function. // If the parameter value is greater than zero, and if // completing the withdrawal would not result in a negative // account balance, process the withdrawal by decreasing the // account balance by the parameter amount. Then return true // to indicate that the withdrawal was successful.
// Otherwise, do not change the account balance. Just return // false to indicate that the withdrawal was not successful. }
void Bank::printRecord() const { cout
3) Testclient.cpp
#include
using namespace std;
int main() { // creates an instance of the Bank class using the default constructor Bank account1;
// creates an instance of the Bank class using the parameterized constructor Bank account2("Devin", "Soni", "987664322", 799.84);
cout
cout
// overwriting default values for account1 account1.setFirstName("Raimi"); account1.setLastName("Karim"); account1.setAccountNumber("779964321"); account1.setAccountBalance(419.00);
cout
cout
// testing deposit cout
account1.printRecord();
// testing unsuccessful withdrawal cout
account2.printRecord();
// testing successful withdrawal cout
account2.printRecord();
return 0; }
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started