CS201 – Spring 2001

Prof. Hartman - Homework #11

Due Friday, May 4th by 4:00 pm

 

 

Homework to be turned in: (remember that all programs must follow the guidelines from handout #3.)

 

1.      (5 pts)  Written: Can a correct Bar class definition include both of the following constructors? If not, why not?

Bar(int a = 0, int b = 0, int c = 0);
Bar(void);

2.      (5 pts) Written: What is special about static data members and static member functions?

3.      (5 pts) Written: What must you be very careful about when using dynamic memory and the new operator?

4.  (5 pts) Written: Write the line of code that you would include in your definition for class Foo to give class Bar access to Foo’s public and private members.

5.      (30 pts) Programming: Savings Account Class

Create a class that will allow you to instantiate individual "savings account" objects, along with a C++ program that uses this class, as described below.

·         Use a static data member to contain the annualInterestRate for all of the accounts (all accounts have the same interest rate, compounded monthly).

·         Each member of the class should contain a private data member balance that holds the current amount a saver has in the bank.

·         Provide a calculateMonthlyInterest member function that calculates the monthly interest by multiplying the balance by the annualInterestRate divided by twelve, then adds this interest to the balance.

·         Provide a static member function modifyInterestRate that sets static annualInterestRate to a new value.

·         You also need to have deposit and withdraw functions that will allow additions or subtractions from the balance.

In your test runs that you hand in, instantiate 2 objects, saver1 and saver2, with $10,000 and $15,000, respectively. Set annualInterestRate to 3%, then calculate the monthly interest and print the new balances, after one month has passed, for each of the savers. Then set the annualInterestRate to 4%, calculate the next month’s interest, and again print the balances. Follow this with tests showing that your deposit and withdraw functions work correctly.

Note: I have not explicitly described many of the details of this class (the data types of the private or static members, any mention of some required functions you will need to implement to get the class and the test run working, etc.). You need to decide these implementation details yourself. Welcome to the real world of programming.