You are on page 1of 13

C++ Program List

Sr No. List Of Program Page No. Sig.

1 Write a program to
implement array
strings.

2 Write a program to
implement recursion.

3 Program to
implement class
using Access
Modifier public
private protected.

4 Program to
implement
parameterized
constructor

5 Program to
implement copy
constructor

6 Program to
implement destructor

7 Program to
implement multilevel
inheritance

8 Program to
implement
Polymorphism

9 Program to
implement Binary
Operator Overloading

10 Program to
implement Overriding

11 Program to
implement Exception
Handling
C++ Strings
Strings are used for storing text.

A string variable contains a collection of characters surrounded by double


quotes:

For eg :-

Create a variable of type string and assign it a value:

C++ Recursion
Recursion is a process in which the function calls it self
For eg :-
PrintCustomNum() is a function which can be uses to print numbers without calling loop from 0
to 6.
C++ Access Specifiers
In C++, there are three access specifiers:

● public - members are accessible from outside the class


● private - members cannot be accessed (or viewed) from outside
the class
● protected - members cannot be accessed from outside the
class, however, they can be accessed in inherited classes.
C++ Constructors
A constructor in C++ is a special method that is automatically called when an
object of a class is created.

To create a constructor, use the same name as the class, followed by


parentheses ():
Copy Constructor in C++
A copy constructor is a member function that initializes an object using
another object of the same class. A copy constructor has the following general
function prototype.
Destructors in C++
Destructor is an instance member function which is invoked automatically
whenever an object is going to destroy. Means, a destructor is the last function
that is going to be called before an object is destroyed.
Multiple Inheritance in C++
Multiple Inheritance is a feature of C++ where a class can inherit from more than
one classes . i.e one sub class is inherited from more than one base classes.
Polymorphism in C++
Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance.
For example, think of a base class called Animal that has a method called
animalSound(). Derived classes of Animals could be Pigs, Cats, Dogs, Birds -
And they also have their own implementation of an animal sound (the pig oinks,
and the cat meows, etc.):
Virtual Function in C++
A virtual function is a member function which is declared within a base class and
is re-defined(Overriden) by a derived class. When you refer to a derived class
object using a pointer or a reference to the base class, you can call a virtual
function for that object and execute the derived class’s version of the function.
Overloading Binary Operator in C++
In binary operator overloading function, there should be one argument to be
passed. It is overloading of an operator operating on two operands.
Let’s take the same example of class Distance, but this time, add two distance
objects.
Function Overloading in C++
Function overloading is a feature of object oriented programming where two or
more functions can have the same name but different parameters.
Exception Handling in C++
When an error occurs, C++ will normally stop and generate an error message.
The technical term for this is: C++ will throw an exception (throw an error).
C++ try and catch:
Exception handling in C++ consists of three keywords: try, throw and catch:
The try statement allows you to define a block of code to be tested for errors
while it is being executed.
The throw keyword throws an exception when a problem is detected, which lets
us create a custom error.
The catch statement allows you to define a block of code to be executed, if an
error occurs in the try block.
#1nc1ude ‹ iDstream›
us1ng namespa ce std ;

int main()

int x = -1;

// Some code
cout ‹ ‹ " Before I ry \n" ;
try (
cout << ”Inside try
\n”; if (x < B)

I hrov x;
cout ‹ < ”After thraw (NeVer executed) \n ” j

catch (Int x ) {
cout ‹ ‹ " Exception Ca ught \ n " ;

cout ‹ < "ATten catch (b/ill be executed) \n" ;


return B;

Before try
Inside try
Exception Caught
After catch ( Will be executed)

You might also like