0% found this document useful (0 votes)
22 views2 pages

Exercices On C++

The document contains a comprehensive set of exercises on C++ programming, covering various topics such as basics, control structures, functions, arrays, object-oriented programming, templates, pointers, file handling, exception handling, and the Standard Template Library (STL). Each section includes specific tasks like writing programs for outputting text, calculating areas, using control statements, defining classes, and implementing templates. Additionally, there are challenges that involve creating a banking system, using polymorphism, and operator overloading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Exercices On C++

The document contains a comprehensive set of exercises on C++ programming, covering various topics such as basics, control structures, functions, arrays, object-oriented programming, templates, pointers, file handling, exception handling, and the Standard Template Library (STL). Each section includes specific tasks like writing programs for outputting text, calculating areas, using control statements, defining classes, and implementing templates. Additionally, there are challenges that involve creating a banking system, using polymorphism, and operator overloading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXERCICES ON C++ PROGRAMMING LANGUAGE

Exercises on C++ Programming

1. Basics of C++ Programming

 Write a program that outputs "Hello, World!" to the console.


 Create a program that demonstrates the use of variables and data types (e.g., int,
float, char, bool) and prints their values.
 Write a program to calculate the area and perimeter of a rectangle using variables.

2. Control Structures

 Write a program to check if a given number is odd or even using an if-else


statement.
 Use a switch statement to implement a simple menu-driven program for basic
arithmetic operations (addition, subtraction, multiplication, division).
 Write a program to display all even numbers between two integers entered by the user
using a while loop.

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.

4. Arrays and Vectors

 Write a program to initialize and print a 2D array (matrix).


 Create a program to find the largest and smallest elements in a 1D array.
 Write a program to demonstrate the use of the STL vector class (e.g., initializing,
adding elements, and displaying them).

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

 Write a program to read and write text to a file using fstream.


 Create a program to count the number of lines and words in a text file.
 Write a program to copy the content of one file into another.

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.

10. Standard Template Library (STL)

 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.

11. Additional Challenges

 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.

You might also like