Devam Ediyor

493279 Account Inheritance Hierarchy

Create an inheritance hierarchy that a bank might use to represent customers' bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their [url removed, login to view] specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit).

Create an inheritance hierarchy containing base class Account and derived classes Savings-Account and CheckingAccount that inherit from class Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0.0. If not, the balance should be set to 0.0 and the constructor should display an error message, indicating that the initial balance was invalid. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account's balance.

If it does, the balance should be left unchanged and the function should print the message "Debit amount exceeded account balance." Member function getBalance should return the current balance.

Derived class SavingsAccount should inherit the functionality of an Account, but also include a data member of type double indicating the interest rate (percentage) assigned to the [url removed, login to view]'s constructor should receive the initial balance, as well as an initial value for the SavingsAccount's interest rate. SavingsAccount should provide a public member function calculateInterest that returns a double indicating the amount of interest earned by an account.

Member function calculateInterest should determine this amount by multiplying the interest rate by the account balance. [Note: SavingsAccount should inherit member functions credit and debit as is without redefining them.]

Derived class CheckingAccount should inherit from base class Account and include an additional data member of type double that represents the fee charged per transaction. CheckingAccount's constructor should receive the initial balance, as well as a parameter indicating a fee amount. Class CheckingAccount should redefine member functions credit and debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount's versions of these functions should invoke the base-class Account version to perform the updates to an account balance. CheckingAccount's debit function should charge a fee only if money is actually withdrawn (i.e., the debit amount does not exceed the account balance). [Hint: Define Account's debit function so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.]

After defining the classes in this hierarchy, write a program that creates objects of each class and tests their member functions. Add interest to the SavingsAccount object by first invoking its calculateInterest function, then passing the returned interest amount to the object's credit function.

Sample Output:

account1 balance: $50.00

account2 balance: $25.00

account3 balance: $80.00

Attempting to debit $25.00 from account1.

Attempting to debit $13.00 from account2.

Attempting to debit $40.00 from account3.

$1.00 transaction fee charged.

account1 balance: $25.00

account2 balance: $12.00

account3 balance: $39.00

Crediting $40.00 to account1.

Crediting $65.00 to account2.

Crediting $20.00 to account3.

$1.00 transaction fee charged.

account1 balance: $65.00

account2 balance: $77.00

account3 balance: $58.00

Attempting to debit $125.00 from account1.

Debit amount exceeded account balance.

Attempting to debit $113.00 from account2.

Debit amount exceeded account balance.

Attempting to debit $140.00 from account3.

Debit amount exceeded account balance.

account1 balance: $65.00

account2 balance: $77.00

account3 balance: $58.00

Adding $2.31 interest to account2.

New account2 balance: $79.31

Initial balance is invalid.

Initial balance is invalid.

Initial balance is invalid.

account4 balance: $0.00

account5 balance: $0.00

account6 balance: $0.00

Driver Program:

#include <iostream>

#include <iomanip>

using namespace std;

#include "Account.h"

#include "SavingsAccount.h"

#include "CheckingAccount.h"

int main()

{

Account account1( 50.0 ); // create Account object

SavingsAccount account2( 25.0, .03 ); // create SavingsAccount object

CheckingAccount account3( 80.0, 1.0 ); // create CheckingAccount object

cout << fixed << setprecision( 2 );

// display initial balance of each object

cout << "account1 balance: $" << [url removed, login to view]() << endl;

cout << "account2 balance: $" << [url removed, login to view]() << endl;

cout << "account3 balance: $" << [url removed, login to view]() << endl;

cout << endl;

// attempt valid debits

cout << "Attempting to debit $25.00 from account1." << endl;

[url removed, login to view]( 25.0 ); // try to debit $25.00 from account1

cout << "Attempting to debit $13.00 from account2." << endl;

[url removed, login to view]( 13.0 ); // try to debit $13.00 from account2

cout << "Attempting to debit $40.00 from account3." << endl;

[url removed, login to view]( 40.0 ); // try to debit $40.00 from account3

cout << endl;

// display balances

cout << "account1 balance: $" << [url removed, login to view]() << endl;

cout << "account2 balance: $" << [url removed, login to view]() << endl;

cout << "account3 balance: $" << [url removed, login to view]() << endl;

cout << endl;

// attempt valid credits

cout << "Crediting $40.00 to account1." << endl;

[url removed, login to view]( 40.0 ); // credit $40.00 to account1

cout << "Crediting $65.00 to account2." << endl;

[url removed, login to view]( 65.0 ); // credit $65.00 to account2

cout << "Crediting $20.00 to account3." << endl;

[url removed, login to view]( 20.0 ); // credit $20.00 to account3

cout << endl;

// display balances

cout << "account1 balance: $" << [url removed, login to view]() << endl;

cout << "account2 balance: $" << [url removed, login to view]() << endl;

cout << "account3 balance: $" << [url removed, login to view]() << endl;

cout << endl;

// attempt invalid debits

cout << "Attempting to debit $125.00 from account1." << endl;

[url removed, login to view]( 125.0 ); // try to debit $125.00 from account1

cout << "Attempting to debit $113.00 from account2." << endl;

[url removed, login to view]( 113.0 ); // try to debit $113.00 from account2

cout << "Attempting to debit $140.00 from account3." << endl;

[url removed, login to view]( 140.0 ); // try to debit $140.00 from account3

cout << endl;

// display balances

cout << "account1 balance: $" << [url removed, login to view]() << endl;

cout << "account2 balance: $" << [url removed, login to view]() << endl;

cout << "account3 balance: $" << [url removed, login to view]() << endl;

cout << endl;

// add interest to SavingsAccount object account2

double interestEarned = [url removed, login to view]();

cout << "Adding $" << interestEarned << " interest to account2."

<< endl;

[url removed, login to view]( interestEarned );

cout << "New account2 balance: $" << [url removed, login to view]() << endl;

cout << endl;

// create accounts with invalid initial balances

Account account4( -50.0 ); // create Account object

SavingsAccount account5( -25.0, .03 ); // create SavingsAccount object

CheckingAccount account6( -80.0, 1.0 ); // create CheckingAccount object

// display initial balance of each object

cout << "account4 balance: $" << [url removed, login to view]() << endl;

cout << "account5 balance: $" << [url removed, login to view]() << endl;

cout << "account6 balance: $" << [url removed, login to view]() << endl;

cout << endl;

return 0;

} // end main

Beceriler: Her şey Kabul, PHP

Daha fazlasını görün: account inheritance hierarchy, account inheritance hierarchy create inheritance hierarchy, h.s.a. bank, customers bank, credit into account, balance define, std, print hold, endl, bool, earn money fee, savingsaccount class, fee earn money, checking account program, earn base, message passing, account inheritance hierarchy create, php print error, account class, create savingsaccount class, member function php, create bank account using program, write program bank account, account inheritance hierarchy create inheritance, program checking account

İşveren Hakkında:
( 2 değerlendirme )

Proje NO: #2239193

Seçilen:

eperfections

I have already done a similar assignment in C++. Please accept my bid and I can do it in just few hours. Regards ePerfections

0 gün içinde 20$ USD
(347 Değerlendirme)
7.0