L23 - inheritance1

L23 - inheritance1 - Inheritance in C+ Remember from last...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Inheritance in C++ Remember from last time: – Classes can be derived from other classes Basic Info about inheritance: – To declare a derived class: class <derived-class>:public <base class> { <derived class member functions> <derived class member data> }; – Derived classes inherit: public and protected methods and data members of the base class – Derived classes do not inherit: private data members and methods of the base class friend functions of the base class constructor(s) and the destructor of the base class base class assignment operator
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example Banking situation: Bank Account Checking Account Savings Account SuperPlus Account things in common to all accounts, such as acct# balance deposit function savings accounts pay interest; checking accounts may and may not This diagram depicts a class hierarchy
Background image of page 2
Banking Example (cont.) The base class is the Bank Account class – it contains member data and methods common to all types of bank accounts methods: a method to make deposits a method to access the account number a method to access the balance a method to identify the customer data members an account number some customer identifier (such as an SSN) an account balance •T h e Checking account class and the Savings account class will be derived from the Bank Account class
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Banking Example (cont.) • The Checking class – has the deposit and access methods of the Bank Account class and the data members account number and balance and customer_id of the base class – it contains its own member data and methods: methods: a constructor to initialize the checking account data members a method to cash a check by receiving a check amount and debit the account balance accordingly data members a minimum balance value that will dictate when a per- check charge is to be made a value that will be charged on each check cashed when the account balance is less than the minimum required balance • It also serves as a base class for SuperPlus accounts
Background image of page 4
Banking Example (cont.) • The Savings class – has the deposit and access methods of the Bank Account class and the data members account number and balance and customer_id of the base class – it contains its own member data and methods: methods: a constructor to initialize the savings account data members a method that will credit interest to the account a method that will debit the account for a withdrawal data members an annual interest rate value that is credited to the account balance on a monthly basis
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Banking Example (cont.) •T h e SuperPlus class – has the check cashing method and the min balance and per- check charge data members of the Checking class – has the deposit and access methods of the Bank Account class and the data members account number and balance
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/08/2008 for the course EE 468 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 22

L23 - inheritance1 - Inheritance in C+ Remember from last...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online