Lecture 01
SAHAR ANDALEEB
• Attendance
• Ask questions, participate actively in class
• Visit class folder regularly for course updates, announcements, and for
other course materials
• You are responsible for what is covered in the class even if you don’t
show up
• You will stand responsible for any disturbance caused by your cell phone
• Quizzes would be unannounced, expect a quiz in every lecture
• Assignments should be the outcome of individual work only/unless
announced
Object Oriented Programming in C++ 2
Quizzes 10%
Assignments / Project Activities 10%
Lab 20%
Mid Term 20%
Project Viva 5%
Final Exam 35%
Total 100%
• No makeup quizzes
• No date extensions
• ALL of the quizzes would be counted in your end term
• Cheating/sharing will lead to the cancellation of assignment /quiz
/project
Object Oriented Programming in C++ 3
STRUCTURAL PROGRAMMING:
“Breaking down a complex problem into a set of simpler tasks”
( Divide and Conquer Approach )
EXAMPLE:
Computing average salary of every employ of a company
1. Find out what each person earns
2. Count total number of employs
3. Sum all salaries
4. Divide the total by total number of people
Summing all salaries
1. Get each employee’s record
2. Access salary
Object Oriented Programming in C++ 4
Each Employee Record
1. Open file of the employee
2. Go to correct record
PROBLEMS IN STRUCTURAL PROGRAMMING:
Data and procedures separate from each other
Reinventing the wheel
Object Oriented Programming in C++ 5
World is full of things ( car, dolphins, flower etc.)
Things have characteristics ( fast, friendly, pretty… )
Things have behaviors (move, swim, smell…)
Humans are thing oriented beings
OOP is a thing oriented language
OOP: a programming paradigm that models real world
how a problem is divided into objects
Object Oriented Programming in C++ 6
ENCAPSULATION:
“Capturing all attributes and behaviors of an entity in a single class”
INHERITANCE:
“Deriving a new type from an existing type”
POLYMORPHISM:
“Using operators and functions in different ways”
Object Oriented Programming in C++ 7
CLASS:
“A user defined data type that contains both data and the procedures acting on
that data”
OBJECT:
“An object represents an individual identifiable entity with a well defined role”
“An object is an instance of a class”
Object Oriented Programming in C++ 8
MEMBER ACCESS S SPECIFIERS:
Public
Private
protected
What member is visible to which member of the program
To hide the data from the parts of the program that don’t need it
public:
Accessible from outside the class
Accessible by the members of the derived class
private:
Accessible only to the members of the class and to the members of friend class
Object Oriented Programming in C++ 9
protected:
Accessible by the members in its own class and in any class derived
from it.
SYNTAX:
specifier:
Keyword
Object Oriented Programming in C++ 10
DATA MEMBERS:
“the data items”
MEMBER FUNCTIONS: ( Methods/Procedures )
“ functions within a class”
Member functions can either be declared and defined within a class
( treated as inline functions)
Or can be declared inside a class and defined outside.
Object Oriented Programming in C++ 11
GENERAL SYNTAX:
class classIdentifier
{
specifier:
list of members;
specifier:
list of members;
};
Object Oriented Programming in C++ 12
EXAMPLE:
class myFirstClass void main(void)
{ {
private: myFirstClass obj1;
int someData;
public:
obj1.setData(1);
int setData(int d)
obj1.showData();
{
};
someData = d;
return someData;
• Class declaration does not create any object
}
( No memory is set aside )
void showData()
{
• Member function of a class must always be
cout<<someData; called in connection with an object of that class
}
};
Object Oriented Programming in C++ 13
MEMBER ACCESSS OPERATOR/DOT OPERATOR (.)
Connects object to a member function.
Object Oriented Programming in C++ 14