Lab and Homework Details for CSPP51050

Each lab will consist of a small problem and details of  how to proceed. You need to submit you weekly homework to the TA for grading.  Grading for homework will be done on a pass/fail basis.  Turning in homework assignments is required.  Homework will be graded on an 8-point basis.  If you fail a homework assignment, you will be required to re-submit it until you pass the homework assignment.  Submit your assignments as a tarball to the TA.

You will also need to submit the 3 lab deliverables  which comprise part of your grade. For the deliverables, you will typically need to extend or build around the corresponding lab assignment(s).  A working lab assignment ensures an easier deliverable.

Homework 1

Problem 1 (Singleton Pattern): Consider a rudimentary college registration system. A student will need to approach the registrar when he/she needs to register for a course. Since seating is limited in courses and the registrar is in charge of checking if seats on a course are still available, only one registrar should be allowed to exist in the system (to avoid write errors and make our life simpler).

What you need to implement:
You need to create a class called 'Registrar' in such a way that only one instance of the class can be created. If a second instance of the class is asked to be instantiated, your program should print an error message like " Sorry, I already exist" and return the existing instance. Test your code by trying to instantiate the Registrar class more than once.
 

Problem 2 (Template Pattern):  A new bank in your neighborhood offers two kinds of accounts: Savings accounts and Checking accounts.  The savings account offers an annual interest rate of y (> 0 defined by you) where as there is no interest offered in the checking account.

What you need to implement:
Create an abstract class called  'Account'.  This class will have a template method called get_account_summary( ). This method in turn calls 3 other methods:  calc_interest( ), update_balance( ) and print_summary( ). (note that calc_interest( ) does nothing in the base class and is overridden by subclasses).

Create two more classes SavingsAccount and CheckingAccount, that are derived from Account. Both the derived classes implement their own calc_interest( ) method (which returns any interest that might have accrued) . The methods update_balance( ) and print_summary( ) are generic and are thus to be implemented in the base class 'Account'. Implement any other variables, methods that you feel are needed for these classes to function e.g. you may need a private variable called 'balance'.

Test your implementation by creating the two kinds of accounts with an initial balance and asking both of them for account summaries. (to simplify the problem you can assume that interest is compounded on the first of January every year). You can also assume that the user inputs the current date, or you can use the system date.