#include <iostream>
using namespace std;
// Creating base class Account
class Account
{
private:
// Declaring variables
double balance;
public:
// parameterized constructor
Account(double balance)
{
if (balance > 0.0)
{
this->balance = balance;
}
else
{
this->balance = 0.0;
cout << "** Initial balance was invalid **" << endl;
}
}
// Function declarations
void credit(double amount);
bool debit(double amount);
double getBalance();
void setBalance(double amt);
};
/* Function implementation
* which gets current balance
*/
double Account::getBalance()
{
return this->balance;
}
void Account::setBalance(double amt)
{
this->balance = amt;
}
void Account::credit(double amount)
{
balance+=amount;
}
bool Account::debit(double amount)
{
if(balance>=amount)
{
balance-=amount;
return true;
}
else
{
return false;
}
}
// Creating the sub class derived from Base class Account
class SavingsAccount : public Account
{
private:
// Declaring variables
double rate;
public:
// parameterized constructor
SavingsAccount(double balance, double rate)
: Account(balance)
{
this->rate = rate;
}
// Function declarations
double calculateInterest();
// Function declarations
void credit(double amount);
bool debit(double amount);
};
/* Function implementation
* which calculates the interest amount
*/
double SavingsAccount::calculateInterest()
{
return getBalance() * (rate / 100);
}
/* Function implementation
* which adds money to the current balance
*/
void SavingsAccount::credit(double amt)
{
double interest = calculateInterest();
setBalance(getBalance() + amt + interest);
cout << "Account Balance after credit :$" << getBalance() << endl;
}
/* Function implementation
* which subtract money to the current balance
*/
bool SavingsAccount::debit(double amount)
{
if (amount > getBalance())
{
cout << "Debit amount exceeded account balance." << endl;
return false;
}
else
{
setBalance(getBalance() - amount);
return true;
}
}
// Creating a Checking Account class derivied from Account class
class CheckingAccount : public Account
{
private:
double feePerTx;
public:
// parameterized constructor
CheckingAccount(double balance, double feePerTx)
: Account(balance)
{
this->feePerTx = feePerTx;
}
// Function declarations
void credit(double amount);
bool debit(double amount);
};
/* Function implementation
* which adds money to the current balance
*/
void CheckingAccount::credit(double amount)
{
setBalance(amount - feePerTx);
}
/* Function implementation
* which subtract money to the current balance
*/
bool CheckingAccount::debit(double amount)
{
double amt = (amount + feePerTx);
if (!Account::debit(amt))
{
cout << "Debit amount exceeded account balance." << endl;
return false;
}
else
{
Account::debit(amt);
return true;
}
}
int main()
{
//Declaring variables
double damt,camt;
//Creating Instances of SavingsAccount class and CheckingAccount class
SavingsAccount sa1(50000, 7);
CheckingAccount ca1(65000, 2);
damt=20000;
camt=45000;
//Performing transactions on SavingsAccount
cout<<"__Savings Account__"<<endl;
cout<<"Account Balance :$"<<sa1.getBalance()<<endl;
sa1.debit(damt);
cout << "Account Balance After Debit $"<<damt<<" is :$"<< sa1.getBalance() << endl;
sa1.credit(camt);
cout << "Account Balance After Credit $"<<camt<<" is :$"<< sa1.getBalance() << endl;
cout<<"-----------------"<<endl;
//Performing transactions on CheckingAccount
cout<<"__Checking Account__"<<endl;
cout<<"Account Balance :$"<<ca1.getBalance()<<endl;
ca1.debit(damt);
cout << "Account Balance After Debit $"<<damt<<" is :$"<< ca1.getBalance() << endl;
ca1.credit(camt);
cout << "Account Balance After Credit $"<<camt<<" is :$"<< ca1.getBalance() << endl;
cout<<"-----------------"<<endl;
return 0;
}
__________________
Output:
________________Thank You
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.,...
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...
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...
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...
: Implement the following given scenario in C++ a. Create an inheritance hierarchy by writing the source code, containing base class BankAccount and derived classes SavingsAccount and CheckingAccount that inherit from class BankAccount. b. Implement Polymorphism where required to achieve the polymorphic behavior. c. Multiple constructors be defined for initializing the account of a user. d. The class should provide four member functions. i. Member function Credit should add an amount to the current balance. ii. Member function Debit should...
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...
MAIN OBJECTIVE Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...
(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 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...
Bank Accounts Look at the Account class Account.java and write a main method in a different class to briefly experiment with some instances of the Account class. • Using the Account class as a base class, write two derived classes called SavingsAccount and CheckingAccount. A SavingsAccount object, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. A CheckingAccount object, in addition to the attributes of an...
In C++: Define a class named Account that stores a balance (monetary amount). The class should have a private double variable balance. Add one accessor getBalance function that returns the balance and one deposit function that increases the balance by a given double amount. Then subclass Account with a SavingsAccount class. This class should have a private double variable interest. Add an addInterest function that increases the balance (from the superclass Account) according to the interest. Demonstrate the use in...