Professional Documents
Culture Documents
Object Oriented Programming: Evaluation
Object Oriented Programming: Evaluation
Assistant Professor
Department of Computer Science
Office E – 12
Evaluation
Evaluation Criteria
Total Marks 100% (100)
Final Term Exam 50%
Mid Term Exam 30%
Assignments + Presentations + Quizzes 20%
Recommended Readings
Object Oriented Programming in C++
By Robert Lafore
C++ By Aikman Series
C++ How to Program
By Deitel & Deitel
The C++ Programming Language By Bjarne Stroustrup
Miscellaneous i.e. Internet etc…
Object Oriented Programming
2
1
6/27/2018
Evaluation (Cont…)
Policies
Late assignments may be accepted with marks reduction.
There will be a 10% reduction for assignments submitted up
to 24 hours late
Students who have copied assignments or whose
assignments have been copied will both be given a zero
Plagiarism is not acceptable. Anyone found to be guilty of
plagiarism in an assignment will be given a zero in that
assignment
Quizzes may be unannounced or announced (depends on
your response!)
At least one “Major Assignment”
Project
Object Oriented Programming
3
Chapter 1
Introduction
Object Oriented Programming
(OOP)
2
6/27/2018
You Know !
Basics of C and C++ Programs
Basic Terminologies of C and C++
Different operators
Conditional statements
Loops statements
Arrays
Structures
Functions
Library functions
User defined functions
Pointers
Etc . . .
Object Oriented Programming
5
Course Objective
3
6/27/2018
Course Contents
Object Orientation
Object Orientation Model
Objects and Classes
Overloading
Inheritance
Polymorphism
Brief about Filing
Brief about (Depends on time)
Generic Programming
Exception Handling
Introduction to Design Patterns
4
6/27/2018
Object Orientation
What is Object-Orientation?
What is a Model?
Examples – Model
Includes
Highway maps
Architectural models
Mechanical models
Etc...
5
6/27/2018
Example – OO Model
Lives-in
Objects
Ali
Drives In the
House
Car
Tree
Object Interactions
Ali lives in the house
Ali drives the car
Tree in the house
6
6/27/2018
Object
An Object is
Something tangible / real
For example
Ali,
Car etc…
Something that can be apprehended intellectually
For example
Time, Date
An Object has
State (attributes)
Well-defined behaviour (operations)
Unique identity
Object Oriented Programming
13
7
6/27/2018
8
6/27/2018
Or
Abstraction
Abstraction is a way to cope with complexity
Principle of abstraction
“Capture only those details about an object that are relevant
to current perspective”
Example – Scenario
Ali is student of PhD and also Teaches BS students
related Attributes
Name - Employee ID
Student Roll No - Designation
Year of Study - Salary
CGPA - Age
Object Oriented Programming
18
9
6/27/2018
Example - Abstraction
related Behaviour
Study - DevelopExam
GiveExam - TakeExam
PlaySports - Eat
DeliverLecture - Walk
Example - Abstraction
Student’s Perspective
Attributes
Name - Employee ID
Student Roll No - Designation
Year of Study - Salary
CGPA - Age
Behaviour
Study - DevelopExam
GiveExam - TakeExam
PlaySports - Eat
DeliverLecture - Walk
Object Oriented Programming
20
10
6/27/2018
Example - Abstraction
Teacher’s Perspective
Attributes
Name - Employee ID
Student Roll No - Designation
Year of Study - Salary
CGPA - Age
Behaviour
Study - DevelopExam
GiveExam - TakeExam
PlaySports - Eat
DeliverLecture - Walk
Object Oriented Programming
21
Example - Abstraction
A cat can be viewed with different perspectives
Engineer’s Perspective
Driver’s Perspective
11
6/27/2018
Abstraction – Advantages
Class
In an OO model, some of the objects exhibit identical
characteristics
Such as
Information structure and
Behaviours
We say that they belong to the same class
For Example
Ali studies mathematics
Anam studies physics
Sohail studies chemistry
12
6/27/2018
Class (Cont...)
Graphical Representation of Classes
(Class Name)
(Class Name)
(attributes)
Suppressed
(operations)
Form
Normal Form
Object Oriented Programming
25
Class (Cont...)
Example
Person
name Person
age
gender Suppressed Form
eat
walk
Normal Form
13
6/27/2018
Class (Cont...)
In C++ or in OOP Class is
Collection of Data and function
About an object
Data and functions are define within the class
The functions is written to work upon the data
Classes are define to create user-define data types
Similar to built-in data types provided by C++ (concepts)
Defining class does not create any space in computer
memory
But define the data items and functions
When its object is declared memory space is reserved
Class (Cont...)
Classes and structure are
Similar in concept
Similar in syntax
Structures are used to hold data items only while
Classes are used to hold data items as well as functions
14
6/27/2018
Defining a Class
Class is define in similar way as structure
The general syntax is
class <class_name>{
body of the class
};
class
Is keyword to define a class
class_name
Represent name of the class
The object is created using this name
Object Oriented Programming
29
Semicolon
Body of the class ends with “ ; ”
15
6/27/2018
Members of a Class
Class consists
Data items &
Functions
These are called members of the class
Data Items
Data items of the class called data members of the class
Functions
Functions of the class called member functions of the class
Define to work on the data items
Member functions
Can be define inside or outside of the class
Example – Class
Class xyz {
private:
int a, b, c;
public:
void get(void){
cout<<“Enter values for a, b & c”;
cin>>a>>b>>c;
}
void put(void){
cout<<“a = ”<<a<<endl;
cout<<“b = ”<<b<<endl;
cout<<“c = ”<<c<<endl;
}
};
16
6/27/2018
Example – Class
Data items
Class xyz {
private:
int a, b, c;
public:
void get(void){
cout<<“Enter values for a, b & c”;
cin>>a>>b>>c;
}
void put(void){
cout<<“a = ”<<a<<endl;
cout<<“b = ”<<b<<endl;
cout<<“c = ”<<c<<endl;
}
};
Object Oriented Programming
33
Example – Class
Functions
Class xyz {
private:
int a, b, c;
public:
void get(void){
cout<<“Enter values for a, b & c”;
cin>>a>>b>>c;
}
void put(void){
cout<<“a = ”<<a<<endl;
cout<<“b = ”<<b<<endl;
cout<<“c = ”<<c<<endl;
}
};
Object Oriented Programming
34
17
6/27/2018
Private Specifier
Private members
Members that can be accessed only from within the class
And cannot access outside the class
Normally
Data members are declared as private
Member functions can also declared as private
Class member that come after private specifier
Upto the next specifier are declared as private
The default specifier is private specifier
If no specifier is mention then it means
The members are private
Declaring data as private means “hiding it from out side”
Object Oriented Programming
36
18
6/27/2018
Public Specifiers
Public members
Members that can be accessed from within the class
And can be access outside the class
Normally
Member functions are declared as public
Data members can also declared as public (not so)
Object
Data type is used to declare a variable
Variable is also called
Instance
Case
19
6/27/2018
Object (Cont...)
Class can be used as to
Declared variable, i.e. instance or case
Class variable is called OBJECT
Can declare more then one object for a class
Each object has unique name
Object (Cont...)
Values of data members in objects are
Different or
Same
The values in the object is called
State of the object
The member functions are also called
Methods
The data hiding or data encapsulation is main feature of
OOP
Provided by Class concept
20
6/27/2018
Declaring Objects
Object of a class is declare in the same way as
Variable of any data type Or
Variable of a structure
When class is define
Reserve no space
Just show how the object will look like
When object is declared memory space is reserved
Syntax
class_name object_name;
class_name object_names; (separated by commas)
Syntax
object_name.member_function;
Dot operator is also called class member access operator
21
6/27/2018
#include<iostream.h>
#include<conio.h> void main (){
class edate{ clrscr();
private: edate obj;
int year, month, day; obj.getDate();
public: obj.printDate();
void getDate(void){ getch();
cout<<“Enter Year”; }
cin>>year;
cout<<“Enter Month”;
cin>>month; Output
cout<<“Enter Day”; Enter Year 2013
cin>>day; Enter Month 3
} Enter Day 28
void printDate(void){ Date Today is: 28/3/2013
cout<<“Date Today is: ”;
cout<<day<<“/”<<month<<“/”<<year;
}
};
43
Example – Program
22
6/27/2018
Constructors
Is a member function
23
6/27/2018
Constructor Types
Three types of constructors
1. Default Constructor
2. Copy Constructor
3. Parametric Constructor
Constructors Overloading
Defining more then one constructors with
Same name, but
Different return data type and parameters
In simple word
Defining more then one constructors with
Different signatures
Signatures means return data type and parameters
24
6/27/2018
Destructors
It is a member function of a class
Destructors
Do not have or need any arguments &
It cannot Return any values
End of Chapter
Homework
Write programs to practice the concepts of this chapter
Quiz
You may have quiz next week
25