Classes and Objects
- Create a class
Rectangle
with attributes length and width. Include methods to calculate area and perimeter of the rectangle.
- Expected Output:
Area: 20 square units Perimeter: 18 units
- Create a class
Employee
with attributes name, id, and salary. Implement methods to set and get employee details.
- Expected Output:
Employee Name: John Doe Employee ID: 101 Employee Salary: $50000
- Create a class
Complex
to perform addition and subtraction of two complex numbers.
- Expected Output:
Sum: 3 + 4i Difference: 1 - 2i
- Create a class
Date
with attributes day, month, and year. Implement methods to validate and display the date.
- Expected Output:
Date: 10/07/2024
Inheritance
- Create a base class
Shape
with methodsarea()
anddisplay()
and derive classesRectangle
andCircle
. Override the base class methods in derived classes.
- Expected Output:
Area of Rectangle: 20 square units Area of Circle: 78.54 square units
- Create a base class
Person
with attributes name and age. Derive classesEmployee
andStudent
fromPerson
.
- Expected Output:
Employee Name: John Doe, Age: 30 Student Name: Alice Smith, Age: 20
Polymorphism
- Create a base class
Animal
with methodssound()
and derive classesDog
,Cat
, andCow
. Overridesound()
in each derived class.
- Expected Output:
Dog says: Woof Cat says: Meow Cow says: Moo
- Create a base class
Shape
with a pure virtual functionarea()
. Derive classesRectangle
andCircle
implementingarea()
.
- Expected Output:
Area of Rectangle: 20 square units Area of Circle: 78.54 square units
Operator Overloading
- Create a class
Matrix
with overloaded operators+
,-
, and*
to perform matrix addition, subtraction, and multiplication.
- Expected Output:
Sum of Matrices: 4 6 8 10 Difference of Matrices: 0 0 0 0 Product of Matrices: 7 10 15 22
- Create a class
String
with overloaded operator+
for string concatenation.- Expected Output:
Concatenated String: Hello, World!
- Expected Output:
File Handling
- Create a C++ program to read data from a file
input.txt
and write it to another fileoutput.txt
.- Input File (
input.txt
):
Hello, this is input.txt file.
- Output File (
output.txt
):
Data copied successfully.
- Input File (
- Create a program to count the number of words, lines, and characters in a text file.
- Input File (
input.txt
):Hello, this is a text file. This is the second line.
- Expected Output:
Words: 10 Lines: 2 Characters: 51
- Input File (
Exception Handling
- Create a C++ program to handle division by zero exception using try-catch block.
- Expected Output:
Error: Division by zero is not allowed.
- Create a program to handle file opening and closing exceptions using try-catch block.
- Expected Output:
Error: Could not open file.
- Expected Output:
Templates
- Create a template function
maximum()
to find the maximum of two numbers of any data type (int, float, double).- Expected Output:
Maximum of 5 and 10: 10 Maximum of 3.5 and 2.8: 3.5
- Create a template class
Stack
to implement stack operations (push, pop, display) for any data type.- Expected Output:
Stack: [5, 10, 15]
- Expected Output:
Standard Template Library (STL)
- Create a program to demonstrate the use of
vector
to store and display a list of integers.- Expected Output:
Elements: 1 2 3 4 5
- Create a program to demonstrate the use of
map
to store and display student names and their marks.- Expected Output:
Student Marks: John: 85 Alice: 90
- Expected Output:
String Handling
- Create a program to find the length of a string without using the standard library function
strlen()
.- Expected Output:
Length of String: 12
- Create a program to reverse a string without using the standard library function
strrev()
.- Expected Output:
Reversed String: olleH
- Expected Output:
Input and Output Manipulation
- Create a program to read and display integer and float values using
cin
andcout
.- Input:
Enter an integer: 5 Enter a float value: 3.14
- Expected Output:
Integer: 5 Float: 3.14
- Create a program to format output using manipulators like
setw
,setprecision
, andfixed
.- Expected Output:
Formatted Output: ID Name Salary 101 John Doe $50000.50 102 Alice Smith $60000.25
- Expected Output:
Algorithms
- Create a program to implement bubble sort to sort an array of integers.
- Input: Array:
[5, 1, 4, 2, 8]
- Expected Output:
Sorted Array: 1 2 4 5 8
- Input: Array:
- Create a program to implement binary search to find an element in a sorted array of integers.
- Input: Array:
[1, 2, 3, 4, 5, 6, 7]
, Search Element:4
- Expected Output:
Element found at index 3
- Input: Array:
Miscellaneous
- Create a program to calculate the factorial of a number using recursion.
- Input: Number:
5
- Expected Output:
Factorial of 5: 120
- Input: Number:
Latest posts by Mahesh Wabale (see all)
- AnchorSetup using Docker-Compose - October 18, 2024
- Devops assignment - October 17, 2024
- Deployment of vault HA using MySQL - September 18, 2024