0% found this document useful (0 votes)
12 views8 pages

Object Oriented Programing

The document discusses function overloading in C++ including its concept, rules, and an example. It also discusses constructors with default arguments and provides an example. Finally, it discusses inheritance in C++ including the different types of inheritance like single, multiple, multilevel, hierarchical and hybrid inheritance.

Uploaded by

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

Object Oriented Programing

The document discusses function overloading in C++ including its concept, rules, and an example. It also discusses constructors with default arguments and provides an example. Finally, it discusses inheritance in C++ including the different types of inheritance like single, multiple, multilevel, hierarchical and hybrid inheritance.

Uploaded by

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

1) MAKE DIFFERENCE BETWEEN PROCEDURAL AND OBJECT ORIENTED PROGRAMING?

2A)EXPLAIN THE CONCEPTS OF FUNCTION OVERLOADING WITH EXAMPLE?

Function overloading is a C++ programming feature that allows us to have more than one function
having same name but different parameter list, when I say parameter list, it means the data type and
sequence of the parameters, for example the parameters list of a function myfuncn(int a, float
b) is (int, float) which is different from the function myfuncn(float a, int b) parameter list (float, int).
Function overloading is a compile-time polymorphism.
Now that we know what is parameter list lets see the rules of overloading: we can have following
functions in the same scope.

sum(int num1, int num2)

sum(int num1, int num2, int num3)

sum(int num1, double num2)

the parameters should qualify any one or more of the following conditions, they should have
different type, number or sequence of parameters.

For example:
These two functions have different parameter type:

sum(int num1, int num2)

sum(double num1, double num2)


These two have different number of parameters:

sum(int num1, int num2)

sum(int num1, int num2, int num3)

These two have different sequence of parameters:

sum(int num1, double num2)

sum(double num1, int num2)

All of the above three cases are valid case of overloading. We can have any number of functions, just
remember that the parameter list should be different.

Function overloading Example

#include <iostream>

using namespace std;

class Addition

public:

int sum(int num1,int num2)

return num1+num2;

int sum(int num1,int num2, int num3)

return num1+num2+num3;

};

int main(void) {

Addition obj;

cout<<obj.sum(20, 15)<<endl;

cout<<obj.sum(81, 100, 10);

return 0;

Output:

35
191

Advantages of Function overloading

The main advantage of function overloading is to the improve the code readability and allows code
reusability.

2B)MAKE THE DIFFERENCE BETWEEN CALL BY VALUE,CALL BY REFERNCE AND CALL BY ADDRESS?

DISCUSS THE PROCESS OF OPENING A FILE FOR INPUT?


EXPLAIN THE CONCEPT OF CONSTRUCTOR WITH DEFAULT ARGUMENTS?

Constructors with Default Arguments in C++

Default arguments of the constructor are those which are provided in the constructor declaration. If
the values are not provided when calling the constructor the constructor uses the default arguments
automatically. An example program to demonstrate the concept default arguments in C++ is shown
below.
WHAT IS INHERITANCEIN C++? EXPLAIN ALL TYPE OF INHERITANCE?

The capability of a class to derive properties and characteristics from another class is
called Inheritance. Inheritance is one of the most important features of Object-Oriented
Programming.

Inheritance is a feature or a process in which, new classes are created from the existing classes. The
new class created is called “derived class” or “child class” and the existing class is known as the “base
class” or “parent class”. The derived class now is said to be inherited from the base class.

When we say derived class inherits the base class, it means, the derived class inherits all the
properties of the base class, without changing the properties of base class and may add new
features to its own.

Types Of Inheritance:-

1. Single inheritance

2. Multilevel inheritance

3. Multiple inheritance

4. Hierarchical inheritance

5. Hybrid inheritance

1. Single Inheritance: In single inheritance, a class is allowed to inherit from


only one class. i.e. one subclass is inherited by one base class only.
2. Multiple Inheritance: Multiple Inheritance is a feature of C++ where a
class can inherit from more than one class. i.e one subclass is inherited
from more than one base class.

3. Multilevel Inheritance: In this type of inheritance, a derived class is


created from another derived class.
4. Hierarchical Inheritance: In this type of inheritance, more than one
subclass is inherited from a single base class. i.e. more than one derived
class is created from a single base class.

/* YJ

5. Hybrid (Virtual) Inheritance: Hybrid Inheritance is implemented by


combining more than one type of inheritance. For example: Combining
Hierarchical inheritance and Multiple Inheritance.
Below image shows the combination of hierarchical and multiple
inheritances:

WHAT IS MAIN PURPOSE OF OPERATOR OVERLOADING?WRITE THE


NAMES OF OPERATORS THATCANNOT BE OVERLOADED?
The mechanism of giving special meaning to an operator is known as operator overloading.
For example, we can overload an operator ‘+’ in a class-like string to concatenate two strings
by just using +.

Operations that can be performed:

 Athematic operations: + – * / %
 Logical operations: && and ||
 Relational operations: == != >= <=
 Pointer operators: & and *
 Memory management operator: new, delete []

Some operators cannot be overloaded which include sizeof operator,


typeid, Scope resolution (::), Class member access operator (.), Ternary or
conditional operator (?:). These operators cannot be overloaded because it
can cause serious programming issues or errors and also it is syntactically
not possible.

You might also like