Exercices On C++
Exercices On C++
2. Control Structures
3. Functions
Define a function that checks if a number is prime. Use this function in main() to find
prime numbers in a given range.
Write a program to calculate the factorial of a number using recursion.
Write a function to calculate the sum of elements in an array, passing the array as an
argument.
5. Object-Oriented Programming
Define a class called Person with attributes name and age, and methods to set and
display the values of these attributes.
Create a program that demonstrates the use of constructors (default, parameterized,
and copy constructors).
Write a program to implement inheritance. Define a base class Animal and a
derived class Dog. Include methods like speak().
6. Templates
Write a program to create a template function for finding the maximum of two values.
Create a class template for a stack data structure and demonstrate its usage for integers
and floats.
Implement a template function for sorting an array of any data type.
7. Pointers
Write a program to demonstrate the use of pointers by printing the address and value
of a variable.
Implement a program that swaps two numbers using pointers.
Create a program that dynamically allocates memory for a 2D array using new and
releases it using delete.
8. File Handling
9. Exception Handling
Write a program to handle division by zero error using try, catch, and throw.
Create a program that demonstrates multiple catch blocks for different exceptions.
Write a program to implement custom exceptions by defining your own exception
class.
Demonstrate the use of map for storing key-value pairs and iterating over them.
Write a program to demonstrate the use of set for storing unique values in ascending
order.
Create a program to use queue and stack from STL, showing enqueue, dequeue,
push, and pop operations.
Implement a program that simulates a simple banking system using classes and
objects, including functionalities like deposit, withdrawal, and checking balance.
Write a program that uses polymorphism to calculate areas of different geometric
shapes (circle, rectangle, triangle).
Create a program to demonstrate operator overloading for adding two complex
numbers.