MSI JANHVI 2023-2026
INDEX
No. Practical Question Date Teacher’s
Sign
1. WAP for Adding two numbers in C++. 02/09/24
2. WAP to check if a number is even or odd. 02/09/24
3. WAP to swap two numbers in C++. 02/09/24
4. WAP to find the largest number among 02/09/24
three numbers.
5. WAP to find the sum of all the natural 02/09/24
numbers from 1 to n.
6. WAP to check whether a number is prime 02/09/24
or not.
7. WAP to compute a power of a given 02/09/24
number to a given power.
8. WAP to calculate the average of all the 02/09/24
elements present in an array.
MSI JANHVI 2023-2026
9. WAP to find the GCD of two numbers in 02/09/24
C++.
10. WAF to find the length of a string. 02/09/24
11. WAP to illustrate the working of objectsand 09/09/24
classes in C++.
12. WAP To Demonstrate The Use Of References 17/09/24
In C++
. C++ PROGRAM TO DEMONSTRATE
13. PASSING OF REFERENCES AS PARAMETERS 17/09/24
C++ PROGRAM TO DEMONSTRATE
14. REFERENCES AND POINTERS 17/09/24
. C++ PROGRAM TO IMPLEMENT
15. PASS-BY-REFERENCE 19/09/24
16. C++ PROGRAM TO DEMONSTRATE HOW TO 19/09/24
CREATE DYNAMIC VARIABLE USING NEW
. C++ PROGRAM TO ILLUSTRATE HOW TO
17. INITIALIZE A DYNAMIC VARIABLE WITH 23/09/24
ALLOCATION
. C++ PROGRAM TO ILLUSTRATE DYNAMIC
18. ALLOCATION AND DEALLOCATION OF MEMORY 23/09/24
USING NEW AND DELETE
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
1. WAP FOR ADDING TWO NUMBERS.
MSI JANHVI 2023-2026
2. WAP TO CHECK IF A NO. IS EVEN OR NOT.
MSI JANHVI 2023-2026
3. WAP TO SWAP TWO NUMBERS.
MSI JANHVI 2023-2026
4. WAP TO FIND THE LARGEST NUMBER AMONG THREE
NUMBERS.
MSI JANHVI 2023-2026
5. WAP TO FIND THE SUM OF ALL THE NATURAL NUMBERS
FROM 1 TO N.
MSI JANHVI 2023-2026
6. WAP TO CHECK WHETHER A NUMBER IS PRIME OR NOT.
MSI JANHVI 2023-2026
7. WAP TO COMPUTER THE POWER OF A GIVEN NUMBER TO A
GIVEN POWER.
MSI JANHVI 2023-2026
8. WAP TO CALCULATE THE AVERAGE OF ALL THE ELEMENTS.
MSI JANHVI 2023-2026
9. WAP TO FIND THE GCD OF TWO NUMBERS.
MSI JANHVI 2023-2026
10. WAP TO FIND THE LENGTH OF A STRING.
MSI JANHVI 2023-2026
11. WAP TO ILLUSTRATE THE WORKING OF OBJECTS AND
CLASSES.
CLASS: A class is a user-defined data type, which holds its own data
members and member functions, which can be accessed and used by
creating an instance of that class. A C++ class is like a blueprint for an
object.
OBJECTS: When a class is defined, only the specification for the object
is defined; no memory or storage is allocated. To use the data and
access functions defined in the class, you need to create objects.
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
12. WAP TO DEMONSTRATE THE USE OF REFERENCES IN C++.
MSI JANHVI 2023-2026
13. C++ PROGRAM TO DEMONSTRATE
PASSING OF REFERENCES AS PARAMETERS
MSI JANHVI 2023-2026
13. C++ PROGRAM TO DEMONSTRATE
REFERENCES AND POINTERS
When a variable is declared as a reference, it becomes an alternative
name for an existing variable. A variable can be declared as a reference by
putting ‘&’ in the declaration.
Both references and pointers can be used to change the local variables of
one function inside another function. Both of them can also be used to
save copying of big objects when passed as arguments to functions or
returned from functions, to get efficiency gain.
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
15. C++ PROGRAM TO IMPLEMENT
PASS-BY-REFERENCE
When a variable is passed as a reference to a function, the address of the
variable is stored in a pointer variable inside the function. Hence, the variable
inside the function is an alias for the passed variable. Therefore, any operations
performed on the variable inside the function will also be reflected in the calling
function.
• This ability to reflect changes could return more than one value by a
function.
• Also, a void function could technically return value/s using this method.
The & (address of) operator denotes values passed by pass-by-reference in a
function.
MSI JANHVI 2023-2026
16. C++ PROGRAM TO DEMONSTRATE HOW TO CREATE DYNAMIC
VARIABLE USING NEW
17. C++ PROGRAM TO ILLUSTRATE HOW TO INITIALIZE A DYNAMIC
VARIABLE WITH ALLOCATION
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
18. C++ PROGRAM TO ILLUSTRATE DYNAMIC ALLOCATION
AND DEALLOCATION OF MEMORY USING NEW AND DELETE
In C++, dynamic memory allocation allows us to allocate memory during runtime. Dynamic
allocation in an array is particularly useful when the size of an array is not known at compile
time and needs to be specified during runtime.
In C++, we use the new operator for dynamic memory allocation .
NEW OPERATOR :
The new operator denotes a request for memory allocation on the Free Store. If sufficient
memory is available, a new operator initializes the memory and returns the address of the
newly allocated and initialized memory to the pointer variable.
Syntax to use new operator
pointer-variable = new data-type;
DELETE OPERATOR :
Since it is the programmer’s responsibility to deallocate dynamically allocated memory,
programmers are provided delete operator in C++ language.
Syntax:
Release memory pointed by pointer-variable
delete pointer-variable;
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
PRACTICAL 19:
Write a Programm to show dynamic memory allocation using array
MSI JANHVI 2023-2026
Output:
PRACTICAL 20:
WAP to store data of 50 employees using arrays and arrays of object.
MSI JANHVI 2023-2026
Practical 21: Write a program showing “this pointer” with suitable example.
MSI JANHVI 2023-2026
OUTPUT:
PRACTICAL 22: WAP to implement friend function by taking some real-life
example
MSI JANHVI 2023-2026
OUTPUT:
PRACTICAL 23:
MSI JANHVI 2023-2026
JANHVI
JANHVI
PRACTICAL 24: C++ program to show passing of objects to a function
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
PRACTICAL 25: Write a program to demonstrate the concept of passing an
object as a function argument
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
PRACTICAL 26: Write a program to demonstrate constructor overloading
MSI JANHVI 2023-2026
PRACTICAL 27: WAP to show hybrid inheritance .
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
OUTPUT :
JANHVI
JANHVI
PRACTICAL 28: Write a program to subtract two complex numbers using
Classes
MSI JANHVI 2023-2026
OUTPUT :
MSI JANHVI 2023-2026
PRACTICAL 29: Write a program to overload binary + to add two similar
types
of objects. (Both with and without using friend functions )
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
OUTPUT:
PRACTICAL 30 : Write a program to implement = and += operator.
MSI JANHVI 2023-2026
PRACTICAL 31: Write a program to implement template Array class
MSI JANHVI 2023-2026
OUTPUT:
MSI JANHVI 2023-2026
PRACTICAL 32: Write a program to demonstrate function overloading
MSI JANHVI 2023-2026
OUTPUT:
PRACTICAL 33: Write a program to illustrate overloading of a template
function using an explicit function
MSI JANHVI 2023-2026
OUTPUT :
PRACTICAL 34: Write a program to illustrate the use of try, catch and
throw statements.
MSI JANHVI 2023-2026
PRACTICAL 35 : Write a program to illustrate using multiple catch blocks
MSI JANHVI 2023-2026
PRACTICAL 36: Write a program to demonstrate exception handling in C++
MSI JANHVI 2023-2026
OUTPUT:
PRACTICAL 37: Write a Program to demonstrate rethrowing an exception
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
OUTPUT :
PRACTICAL 38: Write a program to demonstrate file handling in C++
MSI JANHVI 2023-2026
MSI JANHVI 2023-2026
PRACTICAL 39: Write a program to demonstrate the opening and closing
of a file in C++
OUTPUT:
MSI JANHVI 2023-2026
PRACTICAL 40: Write a program to demonstrate the use of command line
arguments
OUTPUT: