Download - Lecture 1
![Page 1: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/1.jpg)
LECTURE 1Bushra Riaz
![Page 2: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/2.jpg)
COURSE OUTLINECourse Code: EC-241
Credits: 4 (3,1) Prerequisites: EC-111 Algorithms and
Computing Text Book
C++ How to Program, Deitel and Deitel, 7th Edition, ISBN-10: 0-13-611726-0, Prentice Hall, 2009
References Object Oriented Programming with C++, Robert Lafore,
4th Edition, ISBN-10: 0-672-32308-7, Sams, 2002 The complete Reference C++, Herber Schildt, 3rd Edition The Unified Modeling Language User Guide, Booch,
Rumbaugh, Addison- Wesley, ISBN-10: 0-321-26797-4, 2nd Edition, 2005
![Page 3: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/3.jpg)
COURSE OUTLINEIntroduction: Procedural versus Object Oriented
Programming (OOP), characteristics of OOP, advantages of OOP, Abstract Data Types (ADT), information hiding, encapsulation.
Classes and Objects: Classes, objects, access specifiers, data members, member functions, properties, getters and setters, object aggregation.
Constructors and Destructors: Default constructors, overloaded constructors, copy constructor, conversion constructor, shallow vs. deep copy.
![Page 4: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/4.jpg)
COURSE OUTLINEStatic Members: Static data members and
static member functions. Generic Programming and Overloading:
Function overloading, operator overloading, templates, C++ standard template library (STL).
Dynamic memory management for objects: Pointers to objects, reference variables
![Page 5: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/5.jpg)
COURSE OUTLINEInheritance and Polymorphism:
Inheritance, types of inheritance, derived classes, function overriding, dynamic binding, polymorphism, virtual functions.
Streams and Files: Stream classes, File objects, File operations with streams.
Object-Oriented Design: Introduction to Unified Modeling Language (UML).
![Page 6: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/6.jpg)
Evaluation Methods:AssignmentsQuizzesMidterm exams Final Exam LabProject
![Page 7: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/7.jpg)
PROCEDURAL VS. OBJECT-ORIENTED LANGUAGES
Procedural LanguageViews a program as a series of steps to be
carried outE.g. C, FORTRAN, Pascal
Object Oriented LanguageViews a program as a group of objects that
have certain properties and can perform certain functions
E.g. C++, Java, C#
![Page 8: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/8.jpg)
PROCEDURAL VS. OBJECT-ORIENTED LANGUAGESProblems with Procedural Languages
Cannot cope with very large project sizesExpensive software errors (e.g. air traffic
control)Causes of Problems
Unrestricted Access to Data Global data is allowed Access to data by multiple functions means many
connections between functions Programs become difficult to understand, modify and
maintain
![Page 9: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/9.jpg)
PROCEDURAL VS. OBJECT-ORIENTED LANGUAGES
Poor Modeling of Real World Things Real world things are integral collections of data
and functions e.g. a car: has data (make, model etc.) and
functions (acceleration) Procedural languages do not tie up data with
functions
![Page 10: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/10.jpg)
ExampleProcedural program1. Gather ingredients
Flour, butter, egg, sugar etc2. preheat oven to 350 degree3. beat eggs and butter4. add sugar5. mix6. bake 10 mins
![Page 11: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/11.jpg)
Example Object Oriented programingModel for an Object
Properties List of ingridients, or set of data
Methods List of actions or instructions
![Page 12: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/12.jpg)
ExampleObject Oriented programingBaker {
Properties (ingredients) Flour Butter Eggs Milk Cake pan Oven
Methods (actions) Bake cookies Bake cake Bake pie
}
1. Gather ingredientsFlour, butter, egg, sugar etc
2. preheat oven to 350 degree3. beat eggs and butter4. add sugar5. mix6. bake 10 mins
![Page 13: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/13.jpg)
Global Data
Global Data
Global Data
Function Function Function Function
![Page 14: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/14.jpg)
GOAL OF OOPClearer, more reliable, more easily
maintained programsMore effective way of coping with program
complexity
![Page 15: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/15.jpg)
OBJECT-ORIENTED LANGUAGESC++
Most widely usedLargest programmer base
JavaLacks certain features, e.g. multiple
inheritance, pointers, templatesLess powerful than C++ (but more safe, of
course)C#
Emerging Will be covered later in PLE course
![Page 16: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/16.jpg)
THE OO APPROACHThe fundamental idea is to combine into a
single unit both data and functions that operate on the data.
Such a unit is called an “Object”.An object’s functions are called “member
functions” in C++And its data is called “ data members”.
![Page 17: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/17.jpg)
THE OO APPROACHAn object’s data is typically accessed through
its member functions, i.e. it is hidden from accidental alteration
Data and its function are said to be encapsulated into a single entity
Data encapsulation and data hiding are key elements of object-oriented languages
![Page 18: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/18.jpg)
THE OO APPROACHIf you want to modify data in an object, you
know exactly what functions interact with it (i.e. the member functions of the object).
This simplifies writing, debugging, and maintaining the programs
An OO program consists of a number of objects which communicate with each other’s member functions
![Page 19: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/19.jpg)
object
Data
Member Function
Member Function
Data
Member Function
Member Function
Data
Member Function
Member Function
objectobject
![Page 20: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/20.jpg)
CHARACTERISTICS OF OO LANGUAGESObjectsClasses
EncapsulationInheritance Polymorphism and overloading
![Page 21: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/21.jpg)
CLASSESObjects belong to classesA class and an object of that class has the
same relationship as a data type and a variable
All objects with the same characteristics (data and functions) constitute one class.
A class serves only as a plan, or a template, or sketch- of a number of similar things
It merely specifies what data and what functions will be included in objects of that class.
![Page 22: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/22.jpg)
CLASSESDeclaring a class doesn’t create any objects,
just as mere existence of data type int doesn’t create any variables.
A class is thus a description of a no. of similar objects.
For instance, HUMAN is a class, and JOHN is its instance (object)
![Page 23: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/23.jpg)
EncapsulationInformation hidingEncapsulation is the mechanism that binds
together code and the data it manipulates, and keep both safe from outside inteference and missuse
Data
Member FunctionMember Function
Data
Member FunctionMember Function
objectobject
![Page 24: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/24.jpg)
INHERITANCEDerive other (sub-)classes from an existing
classThe original class is called the BASE CLASS;
the others are DERIVED CLASSESEach class shares common characteristics
with the class from which it was derived, and can also add its own modifications, additions.
For instance, VEHICLE is a class from which CAR, TRUCK, BUS, MOTORCYCLE classes can be derived.
![Page 25: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/25.jpg)
Base class
Derived classes
FFeature A
FFeature B
FFeature A
FFeature B
FFeature C
FFeature A
FFeature B
FFeature D
FFeature E
FFeature A
FFeature B
FFeature F
![Page 26: Lecture 1](https://reader033.vdocument.in/reader033/viewer/2022061106/54481481b1af9fd22e8b4c5e/html5/thumbnails/26.jpg)
POLYMORPHISM AND OVERLOADINGUsing operators or functions in different ways
depending on what they are operating on is called polymorphism (lit. one thing with several distinct forms)
Overloading is a special case of polymorphism, e.g. +, -, /, << etc.