Lecture 2-Week2 - OOP, Data Member, Function, Const
Lecture 2-Week2 - OOP, Data Member, Function, Const
(CS1143)
Week 2
2
What is OOP?
3
Types and Instances
4
Attributes and Behaviors
5
Attributes
6
Behaviors
7
Classes and Objects
8
9
Data Members
10
Member Functions
11
Object Oriented Programming
12
13
Class Definition
14
Class Definition
16
Declaring Data Members
17
Declaring Member Functions
The second part of the class definition declares the
member functions of the class; that is, it declares all
functions that are used to simulate the behavior of
the class.
Some functions have the const qualifier at the end
and some do not.
Constant member functions are
those functions which are denied permission to
change the values of the data members of their
class.
18
19
Member Functions
Definition
20
Member Functions Definition
21
22
23
24
Application
25
Application
26
Applying operations on objects
The first line sets the radius of circle1. The second line gets the value
of the circle’s radius.
The next two lines calculate and print the area and perimeter of the
object named circle1
27
Member Selection
We are using a dot between the object name and the member
function that is supposed to operate on the object.
This is called the member select operator
In other words, we can apply the same function on different objects
using this operator
28
Complete Program
29
30
Separating Class Definition
from Implementation
31
Benefits
32
How to do it?
33
Making project in Dev-C++
34
Circle.h
35
Circle.cpp
36
main.cpp
37
That is all for Week 2
38