0% found this document useful (0 votes)
2 views5 pages

Reservation

The document outlines various programming exercises focused on object-oriented programming (OOP) concepts, including class creation, encapsulation, inheritance, polymorphism, abstraction, and composition. It also covers logic-based problems such as number manipulation, sorting algorithms, recursive functions, and searching algorithms, along with practical applications like file handling and game logic. Additionally, it includes advanced topics like dynamic programming, pathfinding algorithms, and optimization problems.

Uploaded by

chakrounahmad648
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Reservation

The document outlines various programming exercises focused on object-oriented programming (OOP) concepts, including class creation, encapsulation, inheritance, polymorphism, abstraction, and composition. It also covers logic-based problems such as number manipulation, sorting algorithms, recursive functions, and searching algorithms, along with practical applications like file handling and game logic. Additionally, it includes advanced topics like dynamic programming, pathfinding algorithms, and optimization problems.

Uploaded by

chakrounahmad648
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Basic Class and Object Creation

 Create a class Car with attributes make, model, and year.


 Add a method display_info() that prints out the car's details.
 Create an object of the class and call the method.

2. Encapsulation

 Create a class BankAccount with attributes account_holder and _balance (protected).


 Add methods deposit(amount), withdraw(amount), and get_balance() to interact
with the balance.
 Ensure the balance can’t go negative and test it with different scenarios.

3. Inheritance

 Create a parent class Animal with attributes name and species and a method speak().
 Create two child classes Dog and Cat. Override the speak() method for each subclass
with appropriate sounds.
 Test the functionality by creating objects of both subclasses.

4. Polymorphism

 Create a function describe(animal) that takes an object of type Animal and calls its
speak() method.
 Pass instances of Dog and Cat (from the previous exercise) to describe() and observe
how polymorphism works.

5. Abstraction

 Create an abstract class Shape with an abstract method calculate_area().


 Implement concrete subclasses Rectangle and Circle that override calculate_area()
based on their respective formulas.
 Create instances and calculate areas for given dimensions.

6. Composition
 Create a class Engine with attributes horsepower and type.
 Create a class Car that has an Engine object as an attribute.
 Write methods to display details of the car and its engine.

7. File Handling with OOP

 Create a class FileManager to read from and write to a file.


 Add methods write_to_file(data) and read_from_file().
 Test the class by writing some text to a file and then reading it.

8. Real-World Simulation

 Design a simple Library Management System:


o Classes: Book, Member, and Library.
o Library contains a collection of Book objects and methods to add, remove, and
lend books to Member objects.
o Each Book has attributes like title, author, and availability.

logic

1. Number Manipulation

 Write a program that checks whether a given number is:


o Prime
o Palindrome
o Armstrong (e.g., 153 = 13+53+331^3 + 5^3 + 3^313+53+33)
 Combine all three checks into a single program.

2. Sorting Algorithms

 Implement the following sorting algorithms from scratch:


o Bubble Sort
o Selection Sort
o Insertion Sort
 Test each algorithm with an unsorted array and print the sorted array.
3. Recursive Problems

 Write a recursive function to:


o Calculate the factorial of a number.
o Compute the nth Fibonacci number.
o Solve the Tower of Hanoi problem for n disks.

4. String Problems

 Write a program to:


o Check if a string is a palindrome.
o Count the frequency of each character in a string.
o Reverse the words in a sentence while keeping the order of the words intact.

5. Searching Algorithms

 Implement Linear Search and Binary Search.


 Write a program that prompts the user to input a number and finds it in a sorted list using
both methods. Compare their performance.

6. Logical Puzzles

 Write a program to solve the FizzBuzz problem:


o Print numbers from 1 to 100.
o For multiples of 3, print "Fizz" instead of the number.
o For multiples of 5, print "Buzz".
o For multiples of both 3 and 5, print "FizzBuzz".

7. Matrix Operations

 Write a program to:


o Add and multiply two matrices.
o Transpose a matrix.
o Find the determinant of a 2x2 matrix.
8. Pathfinding Algorithm

 Implement the Euclidean Distance algorithm:


o Given a list of points (x,y)(x, y)(x,y), find the two points closest to each other.

9. Dynamic Programming

 Solve the following using dynamic programming:


o Knapsack Problem: Given weights and values of items, maximize the total value
in a bag of fixed capacity.
o Longest Common Subsequence: Find the longest subsequence common to two
strings.
o Coin Change Problem: Find the minimum number of coins required to make a
certain amount.

10. Game Logic

 Write a program to:


o Simulate a Tic-Tac-Toe game between two players.
o Implement the logic to check for a win, lose, or draw.
o Make it interactive!

11. Pattern Printing

 Print the following patterns using loops:

markdown
CopierModifier
* 1 A
** 12 AB
*** 123 ABC
**** 1234 ABCD

o Extend to include more complex patterns.

12. Optimization Problem

 Write a program to solve the Traveling Salesman Problem (brute force for small inputs).
 Optimize it using heuristic methods if possible.

You might also like