0% found this document useful (0 votes)
11 views

Object Orintated Program

The document contains details about three experiments on object-oriented programming concepts in C++: 1. Function overloading, where the same function name can be used for functions with different parameters. 2. Classes and objects, where a class defines data members and member functions, and objects are instances of a class. 3. Static members, which are shared by all objects of a class and can be accessed via the class name.

Uploaded by

rohansahu02
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Object Orintated Program

The document contains details about three experiments on object-oriented programming concepts in C++: 1. Function overloading, where the same function name can be used for functions with different parameters. 2. Classes and objects, where a class defines data members and member functions, and objects are instances of a class. 3. Static members, which are shared by all objects of a class and can be accessed via the class name.

Uploaded by

rohansahu02
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

OBJECT ORINTATED PROGRAM

SUBJECT CODE:SE203
LAB FILE
SUBMITTED BY
ROHAN SAHU(2K22/SE/139)
BATCH:SE A2 (IIIRD SEMESTER)
SUBMITTED TO:
MR.RAM MURTI RAWAT

DEPARTMENT OF SOFTWARE
ENGINEERING
DELHI TECHNOLOGICAL UNIVERSITY
SHAHBAD DAULATPUR
(FORMERLY DELHI COLLEGE OF
ENGINEERING)
MAIN BAWANA ROAD DELHI-110042
INDEX
S.NO TITLE DATE SIGNATURE

1 Write a Program to Implement Function 10/8/2023


Overloading

2 Write a Program to Implement Classes and Objects 16/8/2023

3 Write A Program to Implement Static Members 16/8/2023

10

11

12

13

14

15

EXPERIMENT -1
AIM: Write a Program to Implement Function Overloading.
DESCRIPTION:
Overloading: It refers to the use of the same thing for different purposes.

C++ also permits the overloading of functions. This means that we can use the
same function name to create functions that perform a variety of different tasks.
This is known as function polymorphism in OOP.
Using the concept of function overloading, we can design a family of function
with one function name but with different argument lists. The function would
perform different operations depending on the argument list in the function call.
The correct function to be invoked is determined by checking the number and
type of the arguments but not by the function type. For example, an overloaded
add () function handles different types of data as follows- Declaration:
Int add (int a, int b)
Int add (int a, int b, int c)
Double add (double x, double y)
Double add (int p, double q) Double add (double p, int q)

ALGORITHM:
1. Start
2. Create a function to perform the same task.
3. Overload the function by creating more function with the same
name.
4. The function declarations should have parameters of different data
types.
5. Create the main function.
6. Call the function by passing different types of parameters.
7. Stop.

Source code:
Output:

EXPERIMENT: -2
Aim: Write a Program to Implement Classes and Objects
DESCRIPTION:
The building block of C++ that leads to Object Orientated Programming is a
Class. It is a user-defined data type, which holds its own data members and
member function, which can be accessed and used by creating an instance of
that class. A class is like a blueprint for an object.
A Class is a user-defined data type which has data members and member
function.
Data members are the data variables and member function are the function used
to manipulate these variables together these data members and member function
define behaviour of the objects in a Class.
An Object is an instance of a Class. When a class is defined, no memory is
allocated but when it is instant (i.e., an object is created) memory is allocated.

ALGORITHM:
1.Start
2.Declare a class with its private data members and member function.
3.Define all the member function i.e., to accept values and to display values.
4.Define the member function which adds two members i.e., the real part and
imaginary part of both objects get added separately.
5.Create the main function.
6.Create two objects and accept the values for them using set ().
7.Compute their sum by calling the add () function in which the two ini alized
objects are passed as parameters.
8.Display the sum using display ()
9.Stop

CODE:
OUTPUT:
FINDINGS AND LEARNINGS:
Two numbers can be added using classes and objects. Various other tasks can
also be performed using the same concept.
An Object is an instance of the class which can access only the public members
and not the private members of the class directly.
So in order to access private members, member function are created in public,
as they can access the private members along with public members.
EXPERMIENT: -3
AIM: Write a Program to Implement Static Members.
DESCRIPTION:
A static member is shared by all objects of the class, all static data is initialized
to zero when the first object is created, if no other initialized on is present.
A static member function can only access static data members, other static
member function and any other function from outside the class.
By declaring a function member as static, we make it independent of any
particular object of the class. A static member function can be called even if no
objects of the class exist and the static function are accessed using only the class
name and the scope resolution operator.
We can’t put it in the class definition but it can be initialized outside the class as
done in the following example by re-declaring the static variable, using the
scope resolution operator: to identify which class it belongs to.

ALGORITHM:
1. Start
2. Declare a class with its private members and member function.
3. Declare a static member in public.
4. Increment the value of this static variable in the constructor.
5. Initialize the value of this static member to 0, outside the class.
6. Create the main function.
7. Create two objects of the class.
8. Display the Value of the static member using class name.
9. Stop
CODE:
OUTPUT:

FINDINGS AND LEARNINGS:


The value of the static member displayed the number of objects.
This is because only one copy of the static member is created and shared by all
the objects, thus with the creation of each object the constructor was called and
eventually value to the static variable was incremented.
It can be used in programs where local variables whose value don’t change are
required to be created.

You might also like