0% found this document useful (0 votes)
6 views23 pages

Preview File1

The document outlines the course objectives and topics for a programming course focused on object-oriented design and programming principles. It covers key concepts such as classes, encapsulation, inheritance, and abstraction, along with their applications in C++. The course aims to equip students with the ability to model solutions using object-oriented principles and analyze various programming constructs.

Uploaded by

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

Preview File1

The document outlines the course objectives and topics for a programming course focused on object-oriented design and programming principles. It covers key concepts such as classes, encapsulation, inheritance, and abstraction, along with their applications in C++. The course aims to equip students with the ability to model solutions using object-oriented principles and analyze various programming constructs.

Uploaded by

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

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 1

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 2


Course Objectives

To describe programming, algorithm and its structure, sequences, loops and control flow structure.
To illustrate the structured and objective oriented programming, pointer declaration and initialization.
To demonstrate the applications of encapsulation and data hiding, specifies, constructors and inheritance.
To analyze various types of aggregation, composition, overriding, latch and C++
Course Topics / Major Contents

Introduction to object oriented design, history and advantages of object oriented design, introduction to object oriented
programming
concepts, classes, objects, data encapsulation, constructors, destructors, access modifiers, const vs non-const functions, static
data
members & functions, function overloading, operator overloading, identification of classes and their relationships, composition,
aggregation, inheritance, multiple inheritance, polymorphism, abstract classes and interfaces, generic programming concepts,
function & class templates, standard template library, object streams, data and object serialization using object streams,
exception
handling.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Course Learning Outcomes (CLOs)

CLO’s CLO Description PLOs


PLO-1 (C2 -
CLO-1 Understand principles of object oriented paradigm.
Understand)
Identify the objects & their relationships to build object
CLO-2 PLO-3 (C3 - Apply)
oriented solution
Model a solution for a given problem using object oriented
CLO-3 PLO-3 (C3 - Apply)
principles
PLO-2 (C4 -
CLO-4 Examine an object oriented solution
Analyzing)

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


RECOMMENDED BOOKS

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY


Week fourteen weeksTopics
▶ Abstraction
▶ Abstract Class
▶ Interfaces

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 6


Abstraction

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 7


Abstraction

Abstract class: abstract class does not create instance or object.


Abstract class can be create through pure virtual function.
Pure virtual function : it is also called abstract function .
The pure virtual function does not have any body
Perform the inheritance and through method overriding we can
access the pure virtual function

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 8


Abstraction

Abstraction means displaying only essential information and hiding the details.
Data abstraction refers to providing only essential information about the data to the
outside world, hiding the background details or implementation

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 9


Abstraction

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 10


Abstraction

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 11


Abstraction

Explanation:

•In this example, abstraction is achieved using classes and access specifiers
.
•TestAbstraction class is declared with string x, y as its private members, which means we could
not access these strings outside the class.

•void set(string a, string b) and void print() are declared public members' functions.

•TestAbstraction t1 creates the object of TestAbstraction class.

•t1.set("Scaler", "Academy"); sets the private member's string x as Scaler, y as Academy. These
implementation details are hidden from the user.

•t1.print() prints the members of t1 object.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 12


Abstraction

Ways of Achieving Data Abstraction in C++

There are two ways of achieving data abstraction in C++:

1. Abstraction In Header Files


Abstraction can also be achieved using header files as we hide the function's
implementation in header files. We could use that same function in our program
without knowing its inside workings. Sort(), for example, is used to sort an array, a
list, or a collection of items, and we know that if we give a container to sort, it will sort
it, but we don't know which sorting algorithm it uses to sort that container.
2. Abstraction Using Classes
Classes can be used to implement Abstraction in C++. We may group data members
and member functions into classes using the available access specifiers. A Class can
choose which data members are visible to the outside world and which are hidden.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 13


Abstraction

Ways of Achieving Data Abstraction in C++

Abstraction Using Access Specifiers


In this section, we will know in detail how abstraction is achieved using classes. Access specifiers of
class can be used to impose limits on class members. There are the following types of specifiers:
Public Specifier
The public specifier means that members can be accessed from anywhere in the program when they
are declared as public.
Private Specifier
The private specifier means that when members are declared private, they can only be accessed by the
class's member functions.
Protected Specifier
The protected specifier means only their friend and derived classes can access data members and
member functions.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 14


Abstraction

Ways of Achieving Data Abstraction in C++

Abstraction Using Access Specifiers


In this section, we will know in detail how abstraction is achieved using classes. Access specifiers of
class can be used to impose limits on class members. There are the following types of specifiers:
Public Specifier
The public specifier means that members can be accessed from anywhere in the program when they
are declared as public.
Private Specifier
The private specifier means that when members are declared private, they can only be accessed by the
class's member functions.
Protected Specifier
The protected specifier means only their friend and derived classes can access data members and
member functions.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 15


Abstraction

What Is an Abstract Class?


An abstract class is used to provide a suitable base class from which additional classes can be derived, or
we can say that we could form a blueprint to derive more classes. Abstract classes only provide a user
interface; they cannot be used to construct objects. When an object of abstract classes is attempted to
be instantiated, a compilation error occurs. In C++, data abstraction is also implemented using abstract
classes.
Why Do We Need Abstraction?
Abstraction is one of the most fundamental concepts in OOP, and it is thoroughly implemented in C++.
We can hide the program's implementation specifics behind abstraction and only reveal the details we
wish to show to the outside world. This will make over program simple to use and easy to understand. It
has many advantages, which have been listed below.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 16


Abstraction

Advantages of Data Abstraction in C++


•It makes it impossible for the user to write low-level code.
•It reduces program duplication and enhances reusability.
•The implementation of the internal class can be changed without affecting the user.
•It aids in the improvement of an application's or program's privacy by only presenting the user with
pertinent information.
•Inadvertent user-level mistakes that could alter the object's state are protected from class internals.
•Without requiring changes to user-level code, the class implementation may vary over time in
response to new requirements or problem reports.
Design Strategy
Abstraction divides code into two categories: interface and implementation. So, when creating your
component, keep the interface separate from the implementation so that if the underlying
implementation changes, the interface stays the same.
In this instance, any program that uses these interfaces would remain unaffected and would require
recompilation with the most recent implementation.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 17


Abstraction with interface

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 18


Abstraction with interface

Execution of program
Above class adds numbers together, and returns the sum. The public members -
addNum and getTotal are the interfaces to the outside world and a user needs to know them
to use the class. The private member total is something that the user doesn't need to know
about, but is needed for the class to operate properly.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 19


Abstract class

In the program above, you can see that we are not allowed to
directly access the variables x and y. But you can call the set()
function to set the values x and y. The display() function is
called to display the values x and y.

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 20


Abstract class

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 21


Reference Books
C++ How To Program 10th Edition Deitel & Deitel
Objet oriented Programming in C++ 3rd Edition By Robert Lafore

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 22


Thanks

DEPARTMENT OF COMPUTING, FCIT, INDUS UNIVERSITY 23

You might also like