0% found this document useful (0 votes)
19 views68 pages

Lecture Intro

The document provides information on the CS212 Object Oriented Programming course. It outlines the course objectives which are to familiarize students with basic OOP concepts and techniques, and enable students to use OOP constructs to solve problems. The learning outcomes are listed as understanding differences between OOP and procedural programming, demonstrating ability to create and use OOP constructs, and developing programs using OOP techniques. The document also includes the course outline, grading breakdown, textbooks, and other course details.

Uploaded by

Ali Subhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views68 pages

Lecture Intro

The document provides information on the CS212 Object Oriented Programming course. It outlines the course objectives which are to familiarize students with basic OOP concepts and techniques, and enable students to use OOP constructs to solve problems. The learning outcomes are listed as understanding differences between OOP and procedural programming, demonstrating ability to create and use OOP constructs, and developing programs using OOP techniques. The document also includes the course outline, grading breakdown, textbooks, and other course details.

Uploaded by

Ali Subhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 68

CS212 – Object Oriented

Programming

Introduction

Dr Khuram Shazhad
[email protected]
Office: A-308
Outline

• Course Objectives
• Learning Outcomes
• Course Outline
• Labs
• Grading
• Books
Course Objectives

• To familiarize the students with the basic


concepts and techniques forming the
Object Oriented Programming Paradigm.
• To enable students to identify, analyze and use
the different object oriented constructs to
solve real world problems.
Learning Outcomes
• Understand the difference between

• Demonstrate the ability to create and use OOP


constructs to map real world scenarios

• Develop programs using object oriented


techniques

• Use the latest IDEs to enable quick


development, testing, documentation, and
packaging of programs
Difference OOP Vs POP?
Object Oriented Procedure Oriented
Programming Programming
1. Deal with Data 1. Deal with algorithms
2. Programs divided 2. Programs divided
into objects into functions
3. Need more memory 3. Need less memory
4. Bottom up approach 4. Top down approach
5. Access specifier 5. Does not have access
1. Public, private, protected, default
specifier
6. Overloading
1. Function and operator overloading 6. No Overloading
7. Highly Secure 7. Less Secure
1. Encapsulation & Abstraction
8. C, VB, Basic
8. C++, Java, Python
Course Outline
Week Topic(s)
1-2 Programming Basics, Introduction to Object Oriented Programming
3 Introduction to Object Oriented Programming using Classes and Objects
4 Member Functions, Setter and Getter Methods
5 Copy Constructor, Revision
6 OHT 1
7 Friend Functions and Classes, Static Class Members
8-9 Operator Overloading, Inheritance, Case Study
10 - 11 Virtual Functions, Polymorphism, Dynamic Conversion
12 OHT 2
13 Abstract Classes, Destructors
14 Template Functions, Exception Handling
15 Standard Template Library (STL)
16-17 Case Studies
18 End Semester Exam
Grading

Theory - 75%
40% OHTS - 02
10% Quizzes - 06
10% Assignments - 03
40% Final Exam
Labs - 25 %
70% Lab Tasks
30% Project
Books

• C++ How To Program, Deitel& Deitel, Edition: 9/10


• C++, The Complete Reference, Herbert Schildt
Class Etiquettes

• Respect each others


• Keep your mobiles switched off
• Be careful of class timing
• Late comer may be not allowed
• Delay talks with colleagues
• Try to avoid questions during a lecture
• Ask questions at the end of a lecture
• Avoid interruption in class
SEECS/NUST Etiquettes

• It is far better to fail than to Cheat

• Plagiarism is strictly Prohibited

• Required Class attendance is 75%


Consultation Hours/Location

Thursday: 11 am – 01pm
(Any other day – By appointment only)

Office: Room A308, 2nd Floor


SEECS Faculty Block
CS212 – Object Oriented
Programming

Intro. to Objects
At the end of the day…
Computers just manipulate 0’s and 1’s

But binary is hard (for humans)


to work with
Towards a higher level of abstraction
Declarative languages (Haskell, Prolog...)

OO languages (C++, Java, Python...)

Procedural languages (C, Fortran, COBOL...)

Assembly languages

Binary code
There are always trade-offs

• High-level languages
– Simpler to write & understand
– More library support, data structures

• Low-level languages
– Closer to hardware
– More efficient

• What about C++?


Programming Paradigm

Programming Programming
provides paradigm is a
solution(program) to mental view of the
a real-world
problem and its
problem using
computational solution
models
Procedural Programming

f()

f()
Procedural Programming

f() x

f()
x
Procedural Programming
Procedural Programming
SPAGHETTI CODE
OOP Approach
• The fundamental idea behind object-oriented
language is to combine into a single unit both
– data and
– the functions that operate on that data.
• Such a unit is called an object
Object Oriented Programming (OOP)

f() x

f()
x
OOP Approach
Object Oriented Programming (OOP)
Paradigm
• “Object Oriented programming is an approach
of problem solving where all computations
are carried out using objects”

Object?
Object?
Object
Attributes & Behaviors in OOP

• Almost any noun can be reasonably


represented as a software object in terms
of
– attributes (e.g., name, color and size)
– and behaviors (e.g., calculating, moving and
communicating).
Static Properties
Dynamic properties
Example (Person as an Object)

Attributes Behavior
age Walk()
Name Run()
address Teach(
)
Class
• Close your eyes for a minute and think about what do
you understand when you hear the word “chair”

• We know that chairs have properties like :


– seating capacities,
– back,
– number legs
– shape
– color
– a degree of softness and so on so forth
Example (Chair as an Object)
• The idea of the chair allows you to recognize a chair. However,
the definition does not exist

• However, if you look around the room, there are several chairs are
in the room, and each chair is an object. Each of these objects is an
example of that thing called the Chair (class)

• A class is a description of a kind of thing.


• An object is an actual thing
Class
Class
Class in OOP
Class
Concept of a “Class” in OOP

A key aspect of Object Oriented Programming


is
the use of Classes
• A class is a specification/model of an object
• You can “think of a class as a concept” and
an object as “Realization of that concept”
Class
• A class is like a cookie cutter; it defines the
shape of objects
• Objects are like cookies; they are instances
of the class

Photograph courtesy of Guillaume Brialon on Flickr


Class
• The world is full of objects
• Many objects have always existed. New objects come to existence
and others cease to exist

• Mankind chose to classify objects i.e. name groups of objects based


on their attributes and their relationships
• For example:
– All things have been classed as either living things or non-living things
– Some living things are classed as vertebrae's and others as non-vertebrae’s
– A group of things like TVs, computers, phones etc are classified as electronics
– PCs, laptops, tablets and servers can be classified as computers as a subgroup of
electronics

• In the real world, only objects interact with


objects
Class

Remember: A CLASS is ONLY a definition. It describes a


set of qualifiers that describe what the objects that
belong to that class look like

The things that are tangible and exist are the Objects.
Objects may belong to a classification.
What is an Object in OOP ?

• Objects have properties also called


as
attributes
• Tasks performed by an object are expressed
as methods
Class: Summary
A class defines the abstract characteristics of a
group of similar objects
• Attributes(fields or properties)
• Behaviors(methods or functions).
• A class is a user-defined type.
• A class is a blueprint or template to build
a specific type of object
• Every object is built from a class.
• Can be used to create objects: Variables of
the class type
What is a “Microwave”?
• An oven that uses
microwaves
to heat food

• It has a door

• It has a rotating trey inside

• It is a keypad based HMI

• It has a light in the oven

• Has a power rating


Object or Class?

These are two objects. Call them Microwave 1 and Microwave 2


You can call them My microwave and Ali’s microwave so on and so forth

Both belong to the CLASS microwave, which does not exist


OOP: Real World Modeling
• In physical world we deal with objects such as
cars and people
• Such kind of objects are not like the data and
are not like the functions
• Complex real world objects have
both attributes and behavior
OOP Approach
• Identify objects that the problem is concerned
with,
– e.g. Sports Application (Sportsman would be the
object),
• Produce a detailed design for each new
data type (Objects) including the operations
that can be performed on each object
• Express logic of your program in terms of
objects and kinds of operations they allow
OOP Approach
Online Booking: Tennis Court
• Court
• User
• Booking
Online Booking: Tennis Court

COLOR,
Attribute(Variables) SURFACE,
DIMENSION
Court
DO COURT BOOKING(),
Functionality(Functions) COURT CLEANING
Student Management
System
Roll number

Attributes Name

Marks
Student

Curricular
performan
ce
Behavior:
E
xtra curricular
performance
Basic Structure C and C++
Class
• A class is a programmer-defined data type. It consists
of data members and functions which operate on that
data.
– Data Members define Object attributes
– Member Functions define Object Behavior

• “Class” is an Object-Oriented Programming Concept


C++ Class – Declaration
• To declare a class
– The class keyword is used
• The declaration is enclosed in braces {};
• The class definition ends with a semicolon
• Every piece of code inside the braces is
called ‘class body’
• The class body thus contains class members
C++ Class – Declaration
Class classname
{
………….
…………
…………….

};
C++ Class – Example
class Time {
private: Private:and Public:
are member-access
int hour; // 0 - 23 specifiers.

int minute; // 0 - 59

int second; // 0 - 59 hour, minute, and


second are data
public: members.

Time();
setTime, printMilitary,
void setTime( int, int, int ); and printStandard are
member functions.
void printMilitary(); Time is the constructor.
void printStandard();

};
C++ Class – Body
• Every piece of code inside the braces is
called
‘class body’
• The class body thus contains class members
C++ Class – Body
• Every piece of code inside the braces is
called
‘class body’
• The class body thus contains class members
C++ Class – Body
• Every piece of code inside the braces is
called
‘class body’
• The class body thus contains class members
C++ Class – Body
• Every piece of code inside the braces is
called
‘class body’
• The class body thus contains class members
Class
Class Student
{
– Attributes
• Roll number
• Name
• Marks
– Behavior:
• Curricular performance
• Extra curricular performance
};

57
C++ Class – Body
C++ Class – Class

Members
A class’s declaration declares the class’s
members,
which may consist of
• The data members
• The constructor & destructor functions
• Specialized member functions
• Other member functions
• Include the functionality that can be invoked on the object
of
this class (or type)
C++ Class – Data
• Members
A data member can be of any valid C++ data
type. For example
– Ordinary variable – primitive type
– An instance variable of another class –
programmer defined type
– A pointer or reference variable
C++ Access Modifiers
• Three types of Access Modifiers:
private:
public:
protected
:
• The scope of an access modifier continues until
another access modifier is mentioned explicitly
• There is a colon after every access modifier
C++ Access Modifiers
class Base {
public:
//
public
mem
bers
go
here
prote
cted:
public:
• Public members can be accessed by
member functions as well as by functions that
declare the objects of that class.
• Normally, for classes, those member functions are
made public which must interact with the outside
world.
private:
• Private members can only be accessed by member
functions.
– This means they can only be accessed in the member
function body.
• Remember the ‘members’ mean both variables
and functions.
• By default all class members are private, unless
declared otherwise.
public: OR private:
• It is not compulsory for all members functions to be
public and all data members to be private.
• Some member functions can also be private.
• Similarly, data members can also be public.
– Violation of Encapsulation principle

You might also like