Question

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 allow a balance < 0.

Write a method called Printit() that prints all of the attribute values.

Inside of main() create one instance of the BankAccount class. Make sure you call Deposit and Withdraw. Finally, print out the values on the instance you created.

Derive a new class called SavingsAccount from the BankAccount class.(Savings inherits from BankAccount)

SavingsAccount should store the following new attribute: interest.

Write get/set methods for all attributes.

Write a constructor that takes three parameters. Make sure to call the base class constructor.

Write a default constructor.

Write a method called ApplyInterest() that will apply the interest amount to the balance.

Inside of main() create one instance of the SavingsAccount class. Make sure you call Deposit, Withdraw, ApplyInterest. Finally, print out the values on the instance you created.

Derive a new class - Customer Class (Inherits from Savings – savings inherits from bank account)

Write a customer class. Customer Class has the following new attribute

Customer Name

Write get/set methods for the Name attribute.

Create WithdrawSavings and DepositSavings methods. These methods should call methods on the Savings account and the Bank account members.

Create an instance of the Customer class in main. Make sure you set values on that instance. Print the values of the Customer on standard output.

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

Code:

#include
using namespace std;
class BankAccount
{
string name;
double balance;
public:
//default constructor
BankAccount()
{
name="";
balance=0;
}
BankAccount(string s, double bal)
{
name=s;
balance=bal;
}
string getname()
{
return name;
}
double getbalance()
{
return balance;
}
void setname(string s)
{
name=s;
}
void setbalance(double bal)
{
balance=bal;
}
void Deposit(double bal)
{
cout<<"\nDepositing "< balance=balance+bal;
}
void Withdraw(double wd)
{
if(balance -wd <=0 )
{
cout<<"Sorry no sufficient balance ";
}
else

{cout<<"\nWithdrawing "< balance=balance-wd;}
}
void Printit()
{
cout<<"\nAccount name is "< cout<<"\nbalance is "< }

};


class SavingsAccount : public BankAccount
{
double interest;
public:

SavingsAccount():BankAccount()
{
interest=0;
}
SavingsAccount(string s, double bal, double itr):BankAccount(s,bal)
{
interest=itr;
}
double getinterest()
{
return interest;
}
void setinterest(double itr)
{
interest=itr;
}
void ApplyInterest()
{
double t=getbalance();
t=t+t*getinterest()/100;
setbalance(t);
}
void Printit()
{
BankAccount::Printit();
cout<<"\nInterest is "< }

};

class Customer:public SavingsAccount
{
string custname;
public:
Customer(string s):SavingsAccount("Saving",0,0)
{
custname=s;
}
Customer():SavingsAccount("Saving",0,0)
{

custname="Default";
}
Printit()
{
cout<<"\nCustomer name is:"< SavingsAccount::Printit();
}
string getname()
{
return custname;
}
void setname(string n)
{
custname=n;
}
void Withdraw(double wd)
{
SavingsAccount::Withdraw(wd);
}
void Deposit(double bal)
{
BankAccount::Deposit(bal);
}
};
int main()
{
BankAccount b;
b.setname("xyz");
b.setbalance(100);
b.Deposit(10);
b.Withdraw(20);
b.Printit();

SavingsAccount s;
s.setname("abc");
s.setbalance(200);
s.setinterest(6);
s.Deposit(300);
s.Withdraw(200);
s.ApplyInterest();
s.Printit();

Customer c;
c.setname("ga_cust");
c.setbalance(200);
c.setinterest(7);
c.Withdraw(100);
c.Deposit(300);
c.Printit();

return 1;
}

Output:

Add a comment
Know the answer?
Add Answer to:
In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...
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
  • The program needs to be in python : First, create a BankAccount class. Your class should...

    The program needs to be in python : First, create a BankAccount class. Your class should support the following methods: class BankAccount (object): """Bank Account protected by a pin number.""" def (self, pin) : init "n"Initial account balance is 0 and pin is 'pin'."" self.balance - 0 self.pin pin def deposit (self, pin, amount): """Increment account balance by amount and return new balance.""" def withdraw (self, pin, amount): """Decrement account balance by amount and return amount withdrawn.""" def get balance...

  • 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...

  • Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...

    Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement a constructor that takes the balance (float). –Provide abstract methods deposit(amount) and withdraw(amount) •Design a class called SavingsAccount which extends BankAccount. –Implement a constructor that takes the balance as input. –It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0. –If...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • Write a Java class called BankAccount (Parts of the code is given below), which has two...

    Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • C++ Simple code please Thank you in advance B. Write a C++ program as per the...

    C++ Simple code please Thank you in advance B. Write a C++ program as per the following specifications: 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 the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank...

  • In python: Make a BankAccount class. The class should have the initial balance be set to...

    In python: Make a BankAccount class. The class should have the initial balance be set to a parameter passed into the constructor, but should be 0 if no such parameter is passed in. It should have a method called "withdraw" that withdraws an amount that's supplied as a parameter and returns the new balance. It should also have a method called "deposit" that deposits an amount that's supplied as a parameter and returns the new balance. Both "withdraw" and "deposit"...

  • Bank Accounts Look at the Account class Account.java and write a main method in a different...

    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...

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
Active Questions
ADVERTISEMENT