Question

Should be in C#

Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this back can deposit (i.e. credit) money into their accounts and withdraw (i.e. debit) money from their accounts. More 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.

Create base class Account and derived classes SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include the following private instance variables: Balance, which is of type decimal to represent the account balance; AccountName, which is of type string and represents the account holder’s last name; and AccountNumber, which is an integer type that represents the account’s number. The class should provide a constructor that receives an account’s name, account number, and an initial balance. It should use initialize these instance variables using the appropriate mutator methods (i.e. setAccountName, setAccountNumber, and setBalance). The setBalance method should validate the initial balance to ensure that it’s greater than or equal to 0.0; if not, set the balance to 0.  You should also include the appropriate accessor (i.e. “get”) methods. Also, the class should provide two other public methods:  Method Credit should add an amount to the current balance. Method 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 method should print the message “Insufficient Funds.”  Base class Account should also have a method called PrintAccount that prints the account’s name, number, and balance.

Derived class SavingsAccount should inherit the functionality of an Account, but also include a decimal instance variable indicating the interest rate (double) assigned to the Account.Call this variable InterestRate.  SavingsAccount’s constructor should receive the account’s name, account number, initial balance, and an initial value for the interest rate.  The constructor should call the base class constructor to initialize the account’s name, number, and balance. It should also call a method in its own class, setInterestRate, which should set the InterestRate variable and validate that the rate is a positive number.  If the interest rate passed in is negative, set the interest rate to zero. SavingsAccount should provide public method CalculateInterest that takes no arguments and returns a decimal indicating the amount of interest earned by an account. Method CalculateInterest should determine this amount by multiplying the interest rate by the account balance. [Note: SavingsAccount should inherit methods Credit and Debit without modifying them.]  Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account’s name, number, and balance, and include code in the derived class’s method to print out the information specific to the derived class (i.e. InterestRate).

Derived class CheckingAccount should inherit from base class Account and include a decimal instance variable that represents the fee charged per transaction. Call this variable FeeCharged. CheckingAccount’s constructor should receive the account’s name, account number, initial balance, as well as a parameter indicating a fee amount. Create a mutator method, setFeeAmount, and call it from the constructor. If the fee amount is negative, the setFeeAmount should set it to zero. Class CheckingAccount should redefine methods Credit and Debit so that they subtract the fee from the account balance whenever either transaction is performed successfully. CheckingAccount’s versions of these methods should invoke the base-class Account to perform the updates to an account balance. CheckingAccount’s Debit method 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 method so that it returns a bool indicating whether money was withdrawn. Then use the return value to determine whether a fee should be charged.] Finally, create a method in this derived class that overrides the PrintAccount method in the base class. In it, call the base class method to print out the account’s name, number, and balance, and include code in the derived class’s method to print out the information specific to the derived class (i.e. FeeCharged).

After defining the classes in this hierarchy, write an application that creates one object of each derived class and tests their methods. Add interest to the SavingsAccount object by first invoking its CalculateInterest method, then passing the returned interest amount to the object’s Credit method.  The order of events should be performed as follows:

1. Create a new checking account object. Assign it an initial balance of $1,000. The account name should be your last name concatenated with the word “Checking”, and the account number should be 1. The fee charged should be 3.00. Print a description of this transaction (i.e. "Created checking account with $1,000 balance.")

2. Create a new savings account object. Assign it an initial balance of $2,000. The account name should be your last name concatenated with the work “Savings”, and the account number should be 2.  The interest rate should be 5%. Print a description of this transaction (i.e. "Created savings account with $2,000 balance.")

3. Print the checking account object’s information.

4. Print the savings account object’s information

5. Deposit $100 in the checking account and print a description of this transaction (i.e. "Deposit $100 into checking.") (this should generate a fee charged as well)

6. Print the checking account object’s information

7. Withdraw $50 from the checking account and print a description of this transaction (i.e. "Withdraw $50 from checking.") (this should generate a fee charged as well)

8. Print the checking account object’s information

9. Try to withdraw $6,000 from the checking account and print a description of this transaction (i.e. "Withdraw $6,000 from checking.")(This should not generate a fee but instead produce an error message that the user has Insufficient Funds. The balance should remain unchanged.)

10. Print the savings account object’s information

11. Deposit $3,000 in the savings account and print a description of this transaction (i.e. "Deposit $3,000 into savings.")

12. Print the savings account object’s information

13. Withdraw $200 from the savings account and print a description of this transaction (i.e. "Withdraw $200 from savings.")

14. Print the savings account object’s information

15. Calculate the interest on the savings account and print a description of this transaction (i.e. "Calculate Interest on savings.")

16. Print the savings account object’s information

17. Try to withdraw $10,000 from the savings account (This should produce the Insufficient Funds error message and leave the balance unchanged.)  Print a description of this transaction (i.e. "Withdraw $10,000 from savings.")

18. Print the savings account object’s informationAccount Name: Bolt-Checking Account Numbe r : 1 Balance: Fee charged: $1.000.00 $3.00 Account Name: Bolt-Savings Account Numb

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Account.h

#ifndef ACCOUNT_H
#define ACCOUNT_H

class Account
{
private:
// Declaring variables
double balance;

public:
// parameterized constructor
Account(double balance);
// Function declarations
void credit(double amount);
void debit(double amount);
double getBalance();
};
#endif

______________

Account.cpp

#include <iostream>
using namespace std;
#include "Account.h"


Account::Account(double balance)
{
if (balance > 0.0)
{
this->balance = balance;
}
else
{
this->balance = 0.0;
cout << "* Initial balance was invalid *" << endl;
}
}

/* Function implementation
* which gets current balance
*/
double Account::getBalance()
{
return this->balance;
}


void Account::credit(double amount)
{
balance += amount;
}
void Account::debit(double amount)
{
if (balance >= amount)
{
balance -= amount;
}
else
{
cout << "Debit amount exceded account balance" << endl;
}
}

________________

SavingsAccount.h

#ifndef SAVINGSACCOUNT_H
#define SAVINGSACCOUNT_H
#include "Account.h" // Account class definition

class SavingsAccount : public Account
{
private:
// Declaring variables
double rate;
public:
// parameterized constructor
SavingsAccount(double balance, double rate);
// Function declarations
double calculateInterest();


};
#endif

_______________

SavingsAccount.cpp


#include <iostream>
using namespace std;
#include "SavingsAccount.h"

// parameterized constructor
SavingsAccount::SavingsAccount(double balance, double rate): Account(balance)
{
this->rate = rate;
}

/* Function implementation
* which calculates the interest amount
*/
double SavingsAccount::calculateInterest()
{
return getBalance() * (rate);
}

_________________

CheckingAccount.h

#ifndef CHECKINGACCOUNT_H
#define CHECKINGACCOUNT_H
#include "Account.h" // Account class definition
// Creating a Checking Account class derivied from Account class
class CheckingAccount : public Account
{
public:
// parameterized constructor
CheckingAccount(double balance, double feePerTx);

// Function declarations
void credit(double amount);
void debit(double amount);

private:
// Declaring variables
double feePerTx;
};
#endif

_________________

CheckingAccount.cpp

#include <iostream>
using namespace std;
#include "CheckingAccount.h"

CheckingAccount::CheckingAccount(double balance, double feePerTx): Account(balance)
{
this->feePerTx = feePerTx;
}

/* Function implementation
* which adds money to the current balance
*/
void CheckingAccount::credit(double amount)
{
Account::credit(amount - feePerTx);
}
/* Function implementation
* which subtract money to the current balance
*/
void CheckingAccount::debit(double amount)
{
double amt = (amount + feePerTx);
if (getBalance()<amt)
{
cout << "Debit amount exceeded account balance." << endl;
}
else
{
Account::debit(amt);
}
}

_________________

main.cpp

#include <iostream>
#include <iomanip>
#include "Account.h" // Account class definition
#include "SavingsAccount.h" // SavingsAccount class definition
#include "CheckingAccount.h" // CheckingAccount class definition
using namespace std;

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: $" << account1.getBalance() << endl;
cout << "account2 balance: $" << account2.getBalance() << endl;
cout << "account3 balance: $" << account3.getBalance() << endl;

cout << "\nAttempting to debit $25.00 from account1." << endl;
account1.debit( 25.0 ); // try to debit $25.00 from account1
cout << "\nAttempting to debit $30.00 from account2." << endl;
account2.debit( 30.0 ); // try to debit $30.00 from account2
cout << "\nAttempting to debit $40.00 from account3." << endl;
account3.debit( 40.0 ); // try to debit $40.00 from account3

// display balances
cout << "\naccount1 balance: $" << account1.getBalance() << endl;
cout << "account2 balance: $" << account2.getBalance() << endl;
cout << "account3 balance: $" << account3.getBalance() << endl;

cout << "\nCrediting $40.00 to account1." << endl;
account1.credit( 40.0 ); // credit $40.00 to account1
cout << "\nCrediting $65.00 to account2." << endl;
account2.credit( 65.0 ); // credit $65.00 to account2
cout << "\nCrediting $20.00 to account3." << endl;
account3.credit( 20.0 ); // credit $20.00 to account3


// display balances
cout << "\naccount1 balance: $" << account1.getBalance() << endl;
cout << "account2 balance: $" << account2.getBalance() << endl;
cout << "account3 balance: $" << account3.getBalance() << endl;

// add interest to SavingsAccount object account2
double interestEarned = account2.calculateInterest();
cout << "\nAdding $" << interestEarned << " interest to account2."
<< endl;
account2.credit( interestEarned );

cout << "\nNew account2 balance: $" << account2.getBalance() << endl;

system("PAUSE");
return 0;

}

Output:/AccountSavingsChecking account1 balance:: $50.00 account2 balance: $25.00 account3 balance: $80.00 Attempting to debit $25.0

Add a comment
Know the answer?
Add Answer to:
Should be in C# Create an inheritance hierarchy that a bank might use to represent customers’...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ 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.,...

    In C++ 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 accounts. More 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...

  • For this week's assignment , please create an application following directions in the attached document.(windows form...

    For this week's assignment , please create an application following directions in the attached document.(windows form application) Create a base class named Account and derived classes named SavingsAccount and CheckingAccount that inherit from class Account. Base class Account should include one private instance variable of type decimal to represent the account balance. The class should provide a constructor that receives an initial balance and uses it to initialize the instance variable with a public property. The property should validate the...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-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 baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • I am trying to create a ATM style bank program that accept the customer id ,...

    I am trying to create a ATM style bank program that accept the customer id , in the welcoming panel ,but how do i make when the customer input their id# and click on the ok button then they have 3 or so tries to input the correct id# and if successful then send to the other panel where they choose which transaction to they want to make for example savings , checking account , make and deposit , and...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • (C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account...

    (C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account in the vector, allow the user to specify an amount of money to withdraw from the Bank-Account using member function debit and an amount of money to deposit into the Bank-Account using member function credit. As you process each Bank-Account, determine its type. If a Bank-Account is a Savings, calculate the amount of interest owed to the Bank-Account using member function calculateInterest,...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a...

    This is in C++ (using IDE Visual Studio). I am seeking assistance ASAP. Please include a static member in the class to automatically assign account numbers (used to process up to 10 accounts) and have the user include their first and last name. Thank you! 13. a. Define the class bankAccount to store a bank customer's account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT