Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Bank Account Class) #include #include using namespace std; /** A bank account whose balance can be changed by deposits and withdrawals. */ class BankAccount {

image text in transcribed

(Bank Account Class)

#include #include using namespace std; /** A bank account whose balance can be changed by deposits and withdrawals. */ class BankAccount { public: /** Constructs a bank account with zero balance. */ BankAccount(); /** Constructs a bank account with a given balance. @param initial_balance the initial balance */ BankAccount(double initial_balance); /** Makes a deposit into this account. @param amount the amount of the deposit */ void deposit(double amount); /** Makes a withdrawal from this account, or charges a penalty if sufficient funds are not available. @param amount the amount of the withdrawal */ void withdraw(double amount); /** Adds interest to this account. @param rate the interest rate in percent */ void add_interest(double rate); /** Gets the current balance of this bank account. @return the current balance */ double get_balance() const; private: double balance; }; BankAccount::BankAccount() { balance = 0; } BankAccount::BankAccount(double initial_balance) { balance = initial_balance; } void BankAccount::deposit(double amount) { balance = balance + amount; } void BankAccount::withdraw(double amount) { const double PENALTY = 10; if (amount > balance) { balance = balance - PENALTY; } else { balance = balance - amount; } } void BankAccount::add_interest(double rate) { double amount = balance * rate / 100; deposit(amount); } double BankAccount::get_balance() const { return balance; } int main() { BankAccount harrys_account(1000); harrys_account.deposit(500); harrys_account.withdraw(2000); harrys_account.add_interest(1); cout O Mik Stocki P9.11 Implement a class Portfolio. This class has two data members, checking and savings, of the type BankAccount that was developed in Worked Example 9.1 (worked example_1/account.cpp in your code files). Implement four member functions: deposit (double amount, string account) withdraw( double amount, string account) transfer(double amount, string account) print balances) Here the account string is "S" or "C. For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is automatically transferred to the other account. P9.18 Define a class ComboLock that works like the combination lock in a gym locker, as shown here. The lock is constructed with a combination-three numbers between 0 and 39. The reset function resets the dial so that it points to 0. The turn left and turn right functions turn the dial by a given number of ticks to the left or right. The open function attempts to open the lock. The lock opens if the user first turned it right to the first number in the combination, then left to the second, and then right to the third. class ComboLock { public: ComboLock (int secreti, int secret2, int secret3); void reset(): void turn left(int ticks); void turn right(int ticks); bool open() const; private: }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions