Skip to content

Commit

Permalink
Added medium level Practise Problems in cpp (#412)
Browse files Browse the repository at this point in the history
* c++ reference documentation added

* added practice questions in cpp

* Added medium level problems in cpp

---------

Co-authored-by: Shubhadip Bhowmik <[email protected]>
  • Loading branch information
dhairyagothi and subhadipbhowmik authored Jun 25, 2024
1 parent 9858405 commit 7a15b33
Show file tree
Hide file tree
Showing 3 changed files with 940 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/day-25/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "Day 25",
"position": 25,
"link": {
"type": "generated-index"
}
}
143 changes: 143 additions & 0 deletions docs/day-25/medium-level-questions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
sidebar_position: 1
title: "Medium Level Questions in C++"
description: "In this tutorial, we will practise medium level practise problems in C++ with the help of examples."
sidebar_label: "medium Practise questions"
slug: medium-practise-question-cpp
---


## Here are 20 medium level C++ questions along with their solutions:

1. Write a program to find the factorial of a number.

**Input:** 5

**Output:** The factorial of 5 is 120.

2. Implement a binary search algorithm.

**Input:** Sorted array: [1, 3, 5, 7, 9], Target element: 7

**Output:** Element 7 found at index 3.

3. Create a class to represent a bank account with deposit and withdrawal methods.

**Input:** Account balance: $100, Deposit amount: $50

**Output:** Account balance after deposit: $150

4. Write a program to reverse a string.

**Input:** "Hello, World!"

**Output:** "!dlroW ,olleH"

5. Implement a stack using a linked list.

**Input:** Push elements: 10, 20, 30

**Output:** Stack: 30 -> 20 -> 10

6. Create a class to represent a rectangle with methods to calculate area and perimeter.

**Input:** Length: 5, Width: 3

**Output:** Area: 15, Perimeter: 16

7. Write a program to check if a number is prime.

**Input:** 7

**Output:** 7 is a prime number.

8. Implement a queue using an array.

**Input:** Enqueue elements: 10, 20, 30

**Output:** Queue: 10 -> 20 -> 30

9. Create a class to represent a student with methods to calculate average marks.

**Input:** Marks: [80, 90, 70, 85]

**Output:** Average marks: 81.25

10. Write a program to find the largest element in an array.

**Input:** Array: [5, 10, 3, 8, 2]

**Output:** The largest element is 10.

11. Implement a binary tree data structure.

**Input:** Insert elements: 10, 5, 15, 3, 7, 12, 20

**Output:** Tree:
10
/ \
5 15
/ \ / \
3 7 12 20

12. Create a class to represent a car with methods to start and stop the engine.

**Input:** None

**Output:** Car engine started. Car engine stopped.

13. Write a program to check if a string is a palindrome.

**Input:** "racecar"

**Output:** "racecar" is a palindrome.

14. Implement a hash table data structure.

**Input:** Insert key-value pairs: ("John", 25), ("Alice", 30), ("Bob", 35)

**Output:** Hash table:
Index 0: ("John", 25)
Index 1: ("Alice", 30)
Index 2: ("Bob", 35)

15. Create a class to represent a circle with methods to calculate area and circumference.

**Input:** Radius: 5

**Output:** Area: 78.54, Circumference: 31.42

16. Write a program to sort an array using bubble sort.

**Input:** Array: [5, 2, 8, 1, 9]

**Output:** Sorted array: [1, 2, 5, 8, 9]

17. Implement a linked list data structure.

**Input:** Insert elements: 10, 20, 30

**Output:** Linked list: 10 -> 20 -> 30

18. Create a class to represent a book with methods to get and set the author and title.

**Input:** Author: "John Doe", Title: "The Book"

**Output:** Book details: Author: "John Doe", Title: "The Book"

19. Write a program to find the sum of all elements in an array.

**Input:** Array: [1, 2, 3, 4, 5]

**Output:** The sum of all elements is 15.

20. Implement a merge sort algorithm.

**Input:** Array: [5, 2, 8, 1, 9]

**Output:** Sorted array: [1, 2, 5, 8, 9]



## **[check solution here](./solution.md "check solution")**

Loading

0 comments on commit 7a15b33

Please sign in to comment.