Lab 15A: Inheritance

  < Previous  Next >

Objectives:

In this lab, we will practice:

Background

There are a couple of different types of bank accounts. For the purposes of this lab, there are generic accounts that have a balance and take deposits and withdrawals. Additionally, there are checking accounts that have a balance and can have checks drafted against the balance and take deposits and withdrawals.

Assignment:

Write an Account (base) class and CheckingAccount derived class such that the driver code compiles and produces the following output:
Generic account:
Account has a balance of $1234.56

Checking account:
Account has a balance of $78.90

Generic account: (after transactions)
Account has a balance of $222.21

Checking account: (after transactions)
Account has a balance of $35.69
Last check number processed: 234

Use the benefits of inheritance as much as possible. For example, there's no need to specify nor implement deposit() or withdraw() in the CheckingAccount class. For the display() method in the CheckingAccount class do make a call to Account's display() (i.e., Account::display()). Additionally, do not have a "balance" data member in the derived class. Note, for the parameterized constructor in the derived class, you'll need to use an initialization list to call Account's parameterized constructor.

Submission

Submit your source code using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  lab15A  Account.h  Accout.cpp  CheckingAccount.h  CheckingAccount.cpp
To verify your submission, type the following in a terminal window:
handin  lab15A

Rubric:

Points  Item
------  --------------------------------------------------------------
10      Documentation
        Header comment block at the beginning of each file with:
        + Your full name
        + Date(s) code was written
        + Description
        Comments explaining the role of each variable and major section of code

40      Correctness
        Program solves the assigned problem using methods described in program description
	+ Account class (has all common members)
        + CheckingAccount class (has only members specific to CheckingAccount)
        Program compiles without errors
        Program executes without crashing
        Program produces the correct output
------  --------------------------------------------------------------
50      Total

Notes

  1. If you want to match my output exactly, then run the following on ranger:
    g++  lab15A-driver.cpp  Account.cpp  CheckingAccount.cpp  -o accounts
    ./accounts  &>  output.txt
    diff /nfshome/hcarroll/public_html/2170/private/closedLab/lab15A-answerKey.txt  output.txt
    If the two files match exactly (which is what you want) then there should be NO output from diff. If diff shows one or more differences, fix them and run it again. To get side-by-side output (with the answer key on the left and your output on the right), replace the last line with:
    diff  --side-by-side  /nfshome/hcarroll/public_html/2170/private/closedLab/lab15A-answerKey.txt  output.txt
    For details about interpreting the output of diff, see the Using diff section on the Misc. webpage.