COMP102 Prog. Fundamentals, Structures / Slide 2
A Structure is a collection of related data items,
possibly of different types.
A structure type in C+ is called struct.
A struct is heterogeneous in that it can be
The member function is called according to
The static type of pPtr is Person
The static type of sPtr is Student
Develop a function that can draw different
types of geometric shapes from an array
There are three types of inheritance
Use keyword public, private or protected to
specify the type of inheritance
class Child: public Parent cfw_;
Member access in
There are situations where
designer wants to return
reference to current object from
In such cases reference is taken
from this pointer like (*this)
Powerful feature of the C+ language
One of the most difficult to master
Essential for construction of interesting data structures
Addresses and Pointers
C+ allows two ways of accessing variables
Name (C+ keeps track of the addres
Derived class can override the member
functions of its base class
To override a function the derived class simply
provides a function with the same signature as
that of its base class
class Parent cfw_
In the POP approach, the problem is viewed
as a sequence of things to be done such as
reading , calculating and printing.
A number of functions are written to
accomplish these tasks.
The primary focus is on functions.
Association is a simple structural connection or
channel between classes and has a relationship
where all objects have their own lifecycle and
there is no owner.
Associations are connections between peer objects,
which allows objects to call each others
Header / Include Files
The purpose of a header file is to hold declarations for other
files to use.
They do not define how something is implemented, and you
already know that your program wont link if it cant find the
Const and Static
Static Data Member
A variable that is part of a class, yet is not part of an object of
that class, is called static data member
Static Data Member
They are shared by all
instances of the class
They do not belong to any
Classes and Objects
Class is a tool to realize objects
Class is a tool for defining a new type
Lion is an object
Student is an object
Both has some attributes and some behaviors
Type in C+
Mechanism for user defined types are
Classes and Objects
Copy constructor are used when:
Initializing an object at the time of creation
When an object is passed by value to a function
void func1(Student student)cfw_
Lecture # 7
is probably the most powerful
feature of object oriented programming
which is used in achieving software
Inheritance is the process of creating new
classes, called derived classes from
existing or base cl
Lecture # 3
static Class Data
If a data item in a class is defined as static, then
only one such item is created for the entire
class, no matter how many objects there are.
A static data item is useful when all objects of
the same class must share the com
Passing Parameters by
COMP104 Pass by Reference / Slide 2
To have a function with multiple outputs, we have to use
pass by reference.
Reference (address) of parameter is passed to the function,
instead of its value.
If the func
Suppose a set of shape classes such as
circle, triangle, rectangle and square etc
are all derived from base class shape.
In OOP each of these classes can have the
capability to draw itself.
Although each of them can have its
Programming in C+
Note: CIS 601 notes were originally developed by H. Zhu for NJIT DL Program. The notes were subsequently revised by M. Deek.
Goals for the Course
understand Object Oriented
A child inherits characteristics of its parents
Besides inherited characteristics, a child may
have its own unique characteristics
If a class B inherits from class A then it contains
all the characteristics (information structure