0% found this document useful (0 votes)
254 views64 pages

OOPM UNIT 1 (Cse)

This document provides an overview of object-oriented programming concepts taught in a Computer Science course. It defines object-oriented thinking as representing data and procedures that operate on that data as objects. It then discusses classes and objects, abstraction, encapsulation, inheritance, polymorphism, and other core OOP concepts. Benefits of the object-oriented approach include ease of design, reusability, and secure data handling through features like abstraction and encapsulation.

Uploaded by

Anji
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)
254 views64 pages

OOPM UNIT 1 (Cse)

This document provides an overview of object-oriented programming concepts taught in a Computer Science course. It defines object-oriented thinking as representing data and procedures that operate on that data as objects. It then discusses classes and objects, abstraction, encapsulation, inheritance, polymorphism, and other core OOP concepts. Benefits of the object-oriented approach include ease of design, reusability, and secure data handling through features like abstraction and encapsulation.

Uploaded by

Anji
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/ 64

TRUBA GROUP OF INSTITUTES

Institute: Truba College of Science & Technology, Bhopal


Department: Computer Science & Engineering

Subject : OOPM (CS 305)


Semester : CSE III SEM
Topic : Basics & Introduction of Object Oriented
Faculty : Prof. Akrati Shrivastava
Object Oriented Thinking:-
 A programming problem is attacked by coming up with some kinds
of data representations, and procedures that operate on that data.
data is inert, passive, and helpless; it sits at the complete mercy of a
large procedural body, which is active, logical, and all-powerful.
 The problem with this approach is that programs are written by
programmers, who are only human and can only keep so much de-
tail clear in their heads at any one time
 .Complex and unintended interactions begin to emerge within the
procedural core, and maintaining
 . There are guidelines for programming that can help to minimize
and localize bugs within this traditional paradigm, but there is a bet-
ter solution that involves fundamentally changing the way we work
What is abstract interaction?
If we want to change the television channel from our seat,
we use a remote control. That remote control is an object
with a number of attributes and behaviours hidden inside of
it.
Without an understanding of those hidden attributes—the
microchips, wiring, etc.—we still know and expect that
pressing a button will perform that particular function.

we’ve interacted with the remote control in the abstract,


skipping the steps the remote was designed to carry out.

That’s the beauty of OOP—the focus is on how the objects


behave, not the code required to tell them how to behave.
OOP-
⚫Object Oriented Programming(OOP) is
an Engineering approach for building
software systems.
⚫Based on the concepts of classes and
object that are used for modeling
the real world entities.
⚫ Object-Oriented Programs
- Consists of group of co-operating ob-
jects.
- Object exchange messages, for the pur-
pose of achieving a common objective.
Characteristics of Object-Oriented
Programming
⚫Importance is on data.
⚫Programs are divided into objects.
⚫Functions that operate on the data of
an object are tied together in the
data structure.
⚫Data is hidden and can not be ac-
cessed by external functions.
⚫Objects may communicate with each
other through functions.
Organization of data and functions in OOP

Object A Object B

Data Data

Communication
Functions Functions

Object C

Data

Functions
Benefits of object-oriented techno-
logy include:
 Ease of software design
 Productivity
 Easy testing, debugging, and maintenance
 It’s reusable
 More thorough data analysis, less development time,
and more accurate coding, thanks to OOP’s inheritance
method
 Data is safe and secure, with less data corruption,
thanks to hiding and abstraction.
 It’s sharable (classes are reusable and can be distributed
to other networks).
Procedure Oriented Programming (Pop) & Object-Oriented
Programming (Oop)

In OOP, program is In POP, program is


divided into parts divided into small
called objects Divided Into parts
Importance is given called functions.
to the data rather Importance is not
than procedures or given to data but to
functions because it functions as well as
works as a real sequence of actions
world. to be done.
OOP follows Bottom POP follows Top
Up approach. Down approach
OOP has access spe- POP does not have
cifies named Public any access specifier
Private, Protected, In POP, Data can
etc move freely from
In OOP, objects can function to function
move and commu- in the system.
nicate with each To add new data and
other through mem- function in POP is
ber functions. Expansion not so
OOP provides an easy.
easy way to add new
data and function.
 data cannot move easily Most function uses
from function to func- Global data Data Access
tion, it can be kept pub- for sharing that can be
lic or private so we can accessed freely from
control the access of function to function in
data. the system.
 OOP provides Data Hid- POP does not have any
ing so provides more se- proper way for Data Hid-
curity. ing, hiding data so it is
 Overloading is possible less secure.
in the form of Function In POP, Overloading is
Overloading and Oper- not possible.
ator Overloading Example of POP is: C,
 Example of OOP is: C++, VB, FORTRAN and
JAVA, VB.NET, C#.NET. Pascal.
Object-Oriented Programming &
Back-End Development
 OOP defines most modern server-side scripting languages, which
are the languages back-end developers use to write software and
database technology. This behind-the-scenes, server-side techno-
logy tells a website or web application how to behave, and also
builds the architecture for a site to interact with its database. That
scaffolding is how data is delivered and processed, effectively mak-
ing it the brain of a website. And that’s where object-oriented logic
comes into play.
 If a website’s brain uses object-oriented logic, it’s designed to think
of data as objects. It affects how a site is built from the ground up,
how data is organized, how later growth and maintenance of the site
will occur, and more
Benefits of object-oriented techno-
logy include:
 Ease of software design
 Productivity
 Easy testing, debugging, and maintenance
 It’s reusable
 More thorough data analysis, less development time, and more ac-
curate coding, thanks to OOP’s
 inheritance method
 Data is safe and secure, with less data corruption, thanks to hiding
and abstraction.
 It’s sharable (classes are reusable and can be distributed to other
networks).
Basic Concepts of Object-Oriented
Programming
⚫Objects
⚫Classes
⚫Data Abstraction and Encapsulation
⚫Inheritance
⚫Polymorphism
⚫Dynamic Binding
⚫Message Passing
Classes and Objects
 Object- This is the basic unit of object oriented programming. That
is both data and function that operate on data are bundled as a unit
called as an object.
⚫ Object are the basic run-time entities in an object- oriented system.

⚫ Object is a thing anything .


 Example: Sun,moon,ball,cricket bat file in ur computer, facebook
profile ,person, a place,a bank account, a table of data or any item
that the program has to handle.
 Any thing as object as long as it is ur solution to the problem
statement.
 Objects take up space in the memory and have an associated ad-
dress like a structure in C.
Classes :
⚫ A class contains data members and member functions to
operate on those data Members.
⚫ Class are just like the blueprints of objects that model real
world things.
⚫ Once a class has been defined, we can create any number of
objects belonging to that class.
⚫ Thus a class is collection of objects of similar type.
⚫ Classes are user defined data types & behaves like the built
in type of a programming language.
⚫ Objects are actually variable of the type class.
⚫ Classes create objects and objects use methods to commu-
nicate between them
⚫ one of advantage of using classes is that once you have cre-
ated a class for a certain type of object, you can reuse that
class in any project
A class Is defined by 3 element
1. A unique class name
2. Data members or at-
tributes
⚫AMember
3. class is a functions or fields
collection of meth-(data)
odsmethods (procedure or function)
and
that operate on that data.
Circle

centre radius

circumference()
area()
A class describes an
object

OBJECT

HAS DOES

color bounce
diameter roll
brand

properties behav-
ior
Prof.Deepak Gaikar
a class describes an
Class ball object
String color; Float
diameter; String
brand;
OBJECT
void bounce(float h)
void roll (float d)

HAS DOES

color diam- bounce


eter brand roll

properties behavior
Prof.Deepak Gaikar
Circle ball

String color; Float


Data members
diameter; String
brand;

void bounce(float h) Members methods


void roll (float d)
 Abstraction Data abstraction refers to, providing only
essential information to the outside world and hiding
their background details, i.e., to represent the needed in-
formation in program without presenting the details. For
example, a database system hides certain details of how
data is stored and created and maintained. Similar way,
C++ classes provide different methods to the outside
world without giving internal detail about those methods
and data.
 Encapsulation- Encapsulation is placing the data and
the functions that work on that data in the same place.
While working with procedural languages, it is not al-
ways clear which functions work on which variables but
object-oriented programming provides you a framework
to place the data and the relevant functions together in
the same object.
 Inheritance One of the most useful aspects of object-
oriented programming is code reusability. As the name
suggests Inheritance is the process of forming a new
class from an existing class that is from the existing
class called as a base class, a new class is formed called
as derived class. This is a very important concept of ob-
ject-oriented programming since this feature helps to re-
duce the code size.
 Polymorphism - The ability to use an operator or func-
tion in different ways in other words giving different
meaning or functions to the operators or functions is
called polymorphism. Poly refers to many. That is a
single function or an operator functioning in many ways
different upon the usage is called polymorphism.
 Overloading -The concept of overloading is also a
branch of polymorphism. When the exiting operator or
function is made to operate on new data type, it is said
to be overloaded.
Shape
Circle area{
}
Box
Triangle
Sphere
square
Draw()
TO DESIGN S/W
COMMUNICATION OF CUSTOMERS
VISUALIZATION
REDUCE OF COMPLEXITY
3 MODELS
OBJECT MODEL-
DYNAMIC MODEL-
FUNCTIONAL MODEL-
Principles Of Object-Oriented System
The conceptual framework of object–oriented systems is based
upon the object model.
There are two categories of elements in an object-oriented system

Major Elements − By major, it is meant that if a model does not
have any one of these elements, it ceases to be object oriented.
The four major elements are −
 Abstraction 520 MB
 Encapsulation
 Modularity
 Hierarchy

Minor Elements − By minor, it is meant that these elements are


useful, but not indispensable part of the object model. The three
minor elements are −
 Typing
 Concurrency
 Persistence
Object Model
An object model is a logical interface, software
or system that is modelled through the use of ob-
ject-oriented techniques. It enables the creation
of an architectural software or system model
prior to development or programming. An object
model is part of the object-oriented program-
ming (OOP) lifecycle. An object model helps
describe or define a software/system in terms of
objects and classes. It defines the interfaces or
interactions between different models, inherit-
ance, encapsulation and other object-oriented in-
terfaces and features.
Object model examples include:
Document Object Model (DOM): A set of
objects that provides a modelled repres-
entation of dynamic HTML and XHTML-
based Web pages
 Component Object Model (COM): A
proprietary Microsoft software architec-
ture used to create software components
Primitive Built-In Types
 C++ offers the programmer a rich assortment of built-in
as well as user defined data types. Following table lists
down seven basic C++ data types:
 Keyword Type
 Bool Boolean
 Char Character
 Int Integer
 Float Floating point
 Double Double floating point
 Void Valueless
 wchar_t Wide character
Types of Modifier:
Several of the basic types can be modified
using one or more of these type modifiers:
● signed +2 -2
● unsigned 3
● short CHAR 1 BYTE
● long DOUBLE 8 BYTE
Basic Input / Output in C++

 C++ comes with libraries that provide us with many


ways for performing input and output. In C++ input and
output are performed in the form of a sequence of bytes
or more commonly known as streams.
 Input Stream: If the direction of flow of bytes is from
the device(for example, Keyboard) to the main memory
then this process is called input.
 Output Stream: If the direction of flow of bytes is op-
posite, i.e. from main memory to device( display
screen ) then this process is called output
 1 byte= 8bit
Header files available in C++ for In-
put/Output operations are: 
 iostream: iostream stands for standard input-output
stream. This header file contains definitions of objects
like cin, cout, cerr, etc.
 iomanip: iomanip stands for input-output manipulators.
The methods declared in these files are used for manipu-
lating streams. This file contains definitions of setw, set-
precision, etc.
 fstream: This header file mainly describes the file
stream. This header file is used to handle the data being
read from a file as input or data being written into the
file as output.
Classphysical entity
Object logical entity

Teacher (specialization,exp,qualification)
Teach(),read(),write() explain()
 Class teacher

 {
 Char name[20];
 Int exp;
 Void display()
 { name=“hasnain”;
 Exp=6;
 }
 };
 Void main()
 {
 Teacher t1;
 t1.display();
The two keywords cout in C++ and cin
in C++ are used very often for printing
outputs and taking inputs respectively.
These two are the most basic methods of
taking input and printing output in C++.
To use cin and cout in C++ one must in-
clude the header file iostream in the pro-
gram.
Standard output stream (cout):
Usually the standard output device is the
display screen. The C++ cout statement is
the instance of the ostream class. It is used
to produce output on the standard output
device which is usually the display screen.
The data needed to be displayed on the
screen is inserted in the standard output
stream (cout) using the insertion
operator(<<).
Standard input stream (cin):
Usually the input device in a computer is
the keyboard. C++ cin statement is the in-
stance of the class istream and is used to
read input from the standard input device
which is usually a keyboard. 
The extraction operator(>>) is used along
with the object cin for reading inputs. The
extraction operator extracts the data from
the object cin which is entered using the
keyboard.
Un-buffered standard error
stream (cerr):
 The C++ cerr is the standard error stream that is used to
output the errors. This is also an instance of the ostream
class. As cerr in C++ is un-buffered so it is used when
one needs to display the error message immediately. It
does not have any buffer to store the error message and
display it later.
 The main difference between cerr and cout comes when
we would like to redirect output using “cout” that gets
redirected to file if you use “cerr” the error doesn’t get
stored in file.(This is what un-buffered means ..It cant
store the message)
Variable Declaration in C++

Variable Declaration in C++ A variable


declaration provides assurance to the
compiler that there is one variable exist-
ing with the given type and name so that
compiler proceed for further compilation
without needing complete detail about the
variable. A variable declaration has its
meaning at the time of compilation only,
compiler needs actual variable definition
at the time of linking of the program.
BASIC STRUCTURE OF C++
 LANGUAGE : The program written in C++ language
follows this basic structure. The sequence of sections
should be as they are in the basic structure. A C program
should have one or more sections but the sequence of
sections is to be followed.
 1. Documentation section
 2. Linking section
 3. Definition section
 4. Global declaration section & class declarations
 5.Member function definition
 6. Main function
section main()
{
Declaration section
Executable section
}
1. DOCUMENTATION SECTION :
comes first and is used to document the
use of logic or reasons in your program. It
can be used to write the program's object-
ive, developer and logic details. The doc-
umentation is done in language with /*
and */ . Whatever is written between these
two are called comments.
2. LINKING SECTION :
 displayed on the screen. This section tells the compiler to link the certain
occurrences of keywords or functions in your program to the header files
specified in this section.
 e.g. #include using namespace std;
 directive causes the preprocessor to add the contents of the iostream file to
the program. It contains declarations for cout and cin.
 cout is a predefined object that represents the standard output stream. The
operator << is an insertion operator, causes the string in double quotes to be
 The statement cin>>n; is an input statement and causes the program to wait
for the user to type in a number. The number keyed is placed on the vari-
able “n”. The identifier cin is a predefined object in C++ that corresponds
to the standard input stream. The operator >> is known as extraction oper-
ator. It extracts the value from the keyboard and assigns it to the value
variable on its right
DEFINITION SECTION :
It is used to declare some constants and
assign them some value.
e.g. #define MAX 25
Here #define is a compiler directive
which tells the compiler whenever MAX
is found in the program replace it with 25.
GLOBAL DECLARATION SEC-
TION :
Here the variables and class definitions which
are used through out the program (including
main and other functions) are declared so as to
make them global(i.e accessible to all parts of
program). A CLASS is a collection of data and
functions that act or manipulate the data. The
data components of a class are called data mem-
bers and function components of a class are
called member functions A class ca also termed
as a blue print or prototype that defines the vari-
able or functions common to all objects of cer-
tain kind. It is a user defined data type
SUB PROGRAM OR FUNCTION
This has all the sub programs or the func-
tions which our program needs.
void display()
{
cout<<”C++ is better that C”;
}
SIMPLE C++‟ PROGRAM:
#include
using namespace std;
void display()
{
cout<<”C++ is better that C”;
}
int main()
{
display()
return 0;
}
MAIN FUNCTION SECTION
It tells the compiler where to start the execution from
main()
{
point from execution starts
}
main function has two sections
1 declaration section : In this the variables and their data
types are declared.
2. Executable section or instruction section : This has the
part of program which actually performs the task we
need.
Namespace:
namespace is used to define a scope that could hold global
identifiers. ex:-namespace scope for c++ standard li-
brary.
A classes ,functions and templates are declared within the
namespace named std using namespace std;-->directive
can be used.
 
user defined name space:
syntax for defining name space is
namespace namespace_name
{
//declarations of variables.functions,classes etc...
}
ex: #include<iostream> using namespace
std; namespace sample
{
int m;
void display(int n)
{
cout<<"in namespace N="<<n<<endl;
}
}
 using namespace sample; int main()
{
 int a=5; m=100;
 display(200);
 cout<<"M in sample name space:"<<sample::m; return
0;}
 #include<iostream>
 This directive causes the preprocessor to add content of
iostream file to the program. some old versions of C++
used iostream.h .if complier does not support ANSI
(american nation standard institute) C++ then use header
file iostream.h
DATA TYPES:
A data type is used to indicate the type of data
value stored in a variable. All C compilers sup-
port a variety of data types. This variety of data
types allows the programmer to select the type
appropriate to the needs of the application as
well as the machine. ANSI C supports the fol-
lowing classes of data types:
Primary (fundamental) data types.
Derived data types.
User-defined data types
Primary data types:
1.Integer data type
2.Character data type
3.Float point data type
4.Boolean data type
5.void data type
Integer data type:-
This data type is used to store whole numbers. These numbers do not contain
the decimal part. The size of the integer depends upon the world length of a
machine (16-bit or 32-bit). On a 16-bit machine, the range of integer values
is - 32,768 to +32,767.integer variables are declared by keyword int. C
provides control over range of integer values and storage space occupied
by these values through the data types: short int, int, long int in both signed
and unsigned forms.
Character data type: (char)

A single character can be defined as a


character data type. Character data type
occupies one byte of memory for storage
of character. The qualifiers signed or un-
signed can be applied on char data type.
char is the key word used for declaring
variables
size and range of character data type on
16 bit or 32 bit machine
Floating Point Types:

 Floating point number represents a real number with 6


digits precision occupies 4 bytes of memory. Floating
point variables are declared by the keyword float.
 Double floating point data type occupies 8 bytes of
memory giving 14 digits of precision. These are also
known as double precision numbers. Variables are de-
clared by keyword double
 long double refers to a floating point data type that is
often more precise than double precision.
Boolean or logical data type is a data type, having two values (usually denoted
true and false), intended to represent the truth values of logic and Boolean
algebra. It is named after George Boole, who first defined an algebraic sys-
tem of logic in the mid 19th century. The Boolean data type is the primary
result of conditional statements, which allow different actions and change
control flow depending on whether a programmer-specified Boolean condi-
tion evaluates to true or false.
C99 added a Boolean (true/false) type which is defined in the <stdbool.h>
header Boolean variable is defined by kkey word bool; Ex:
 
bool b;
where b is a variable which can store true(1) of false (0)
 
Void type
The void type has no values. This is usually used to specify the return type of
functions. The type of the function said to be void when it does not return
any value to the calling function. This is also used for declaring general
purpose pointer called void pointer.
Derived data types.
Derived datatypes are Arrays , pointer and
references are examples for derived data
types.
User-defined data types:
they The data types defined by the user are
known as the user-defined data types.
They are structure,union,class and enu-
meration
OPERATORS AND EXPRES-
SIONS
 An operator is a symbol which represents a particular operation that can be
performed on data. An operand is the object on which an operation is per-
formed.
 By combining the operators and operands we form an expression. An ex-
pression is a sequence of operands and operators that reduces to a single
value. 
 C operators can be classified as
◦ Arithmetic operators
◦ Relational operators
◦ Logical operators
◦ Assignment operators
◦ Increment or Decrement operators
◦ Conditional operator
◦ Bit wise operators
◦ unary operator
◦ Special operators 10.Additional operators in c++
ARITHMETIC OPERATORS :
All basic arithmetic operators are present in C++.
operator meaning
+ add
- subtract
* Multiplication
/ division
%modulo division(remainder)
An arithmetic operation involving only real operands(or
integer operands) is called real arithmetic(or integer
arithmetic). If a combination of arithmetic and real is
called mixed mode arithmetic.
/*C++ program on Integer Arith-
metic Expressions*/
 #include<iostream.h>
 void main()
 {
 int a, b;
 cout<"Enter any two integers"; cin>>a>>b;
 cout<<"a+b"<< a+b;
 cout<<"a-b"<< a-b;
 cout<<"a*b"<< a*b;
 cout<<"a/b"<< a/b;
 cout<<"a%b"<< a%b;
 }
 OUTPUT:
 a+b=23 a-b=17 a*b=60 a/b=6 a% b=2
RELATIONAL OPERATORS :
We often compare two quantities and depending on their
relation take certain decisions for that comparison we
use relational operators.
operator meaning
 < is less than
> is greater than
<= is less than or equal to
>= is greater than or equal to
== is equal to
!=is not equal to
/* C++ program on relational op-
erators*/
#include<iostream.h> void main()
{
int a,b; clrscr();
cout<<"Enter a, b values:";
cin>>a>>b;
cout<<"a>b"<< a>b;
cout<<"a>=b"<< a>=b;
cout<<"a<b"<< a<b;
cout<<"a<=b"<< a<=b;
cout<<"a==b"<< a==b;
cout<<"a!=b"<< a!=b;
}
OUTPUT:
Enter a, b values: 5 9
a>b: 0 //false
a<b: 1 //true
a>=a: 1 //true
a<=b: 1 //true
a==b: 0 //false
a!=b: 1 //true

You might also like