Aadi OOP SnippetsA collection of beginner-friendly C++ and Java snippets for OOP, inheritance, operator overloading, templates, exception handling, and revision assignments. Available SnippetsC++ Snippets
Java Snippets
How to Use
B-Series Snippets (Exam Questions)B1 — Book Records SystemWrite a C++ program to implement a class named Book with the following data members: Private: bookId, bookName, author, price. Public: getDetails(), printDetails(). The program should accept details of multiple books, display them in tabular form, and calculate the total price. Shortcut: B2 — Student Records SystemWrite a C++ program to implement a class named Student with the following data members: Private: studentId, studentName, department, marks. Public: getDetails(), displayDetails(). Accept details of multiple students, display in tabular format, and calculate average marks. Shortcut: B3 — Employee Payroll SystemWrite a C++ program to implement a class named Employee with the following data members: Private: empId, empName, designation, salary. Public: acceptData(), showData(). Accept details of multiple employees, display in table format, and calculate total salary expenditure. Shortcut: B4 — Book Constructor & DestructorWrite a C++/JAVA program to implement a class Book with suitable data members. Use constructors to initialize book details and a destructor to indicate object destruction, demonstrating objects, classes, constructors, and destructors. Shortcut: B5 — Student Constructor & DestructorWrite a C++ program to implement a class named Student with suitable data members (roll number, name, marks). Use a parameterized constructor to initialize student details and a destructor to display a message when an object is destroyed. Shortcut: B6 — Employee Constructor & DestructorWrite a C++/JAVA program to implement a class named Employee with suitable data members (employee ID, name, salary). Use a constructor to initialize employee information and a destructor to indicate when an object is removed from memory. Shortcut: B7 — BankAccount Static MembersDesign and implement a C++ program to model a banking system where the class BankAccount keeps track of total accounts and total balance using static data members and static member functions. Also implement a member function to display two balances in ascending order. Shortcut: B8 — Student Friend FunctionWrite a C++ program to create a Student class with private data members: Roll Number, Name, Marks of five subjects, Percentage, Division. Implement a friend function comparePercentage() that takes two Student objects and displays the one with the higher percentage. Shortcut: B9 — ParkingTicket Dynamic AllocationDesign and implement a C++ program for a ParkingTicket class with private data members (ticketNumber, vehicleNumber, parkingFee) and static members (totalTickets, totalCollection). Dynamically allocate objects using new, define a friend function compareFees() and release memory using delete. Shortcut: B10 — Complex Number (+, -, *)Design a C++ class Complex with data members for real and imaginary parts. Provide default and parameterized constructors. Implement operator overloading for +, -, and * to perform arithmetic operations on complex numbers. Shortcut: B11 — Number Unary MinusCreate a class Number that stores an integer value. Provide member functions to input and display the value. Overload the unary minus operator (-) so that it returns a new object whose value is the negative of the original. Shortcut: B12 — Integer Pre/Post IncrementDesign a class Integer that stores an integer value. Overload both increment operators: Pre-increment (++obj) to increase the value and return the updated object, and Post-increment (obj++) to return the original value before incrementing. Shortcut: B13 — Employee Hierarchy PayslipDesign and implement a C++ program to demonstrate inheritance using an employee hierarchy. Base Class: Employee. Derived Classes: Programmer, TeamLead, AssistantProjectManager, ProjectManager. Each derived class calculates DA (52%), HRA (27%), PF (12%), Staff Club Fund (0.1%) of Basic Pay and generates a pay slip. Shortcut: B14 — Employee-Manager Single InheritanceDesign a C++ program using single inheritance. Base class Employee contains ID, name, basic salary. Derived class Manager adds a monthly bonus and calculates total salary (basic salary + bonus). Shortcut: B15 — Shape Triangle/Rectangle (Virtual)Write a C++ program using a base class Shape with a protected data members x and y. Derive Triangle and Rectangle classes that override compute_area() as a pure virtual function. Demonstrate dynamic binding using a base class pointer. Shortcut: B16 — Salary Calculation (Abstract)Design a C++ program with a base class Employee having a pure virtual function calculate_salary(). Derive PermanentEmployee (salary = basicPay + allowance) and ContractEmployee (salary = basicPay only). Demonstrate runtime polymorphism. Shortcut: B17 — Electricity Bill SystemWrite a C++ program with a base class ElectricityBill having a pure virtual function calculate_bill(). Derive Domestic and Commercial classes. Commercial bill adds 10% surcharge. Demonstrate runtime polymorphism using a base class pointer. Shortcut: B18 — Vehicle InterfaceWrite a C++ program using an abstract base class Vehicle as an interface with pure virtual functions: gearChange(), speedUp(), applyBrakes(). Implement these in derived classes Bicycle, Bike, and Car. Shortcut: B19 — Student Result Exception HandlingWrite a C++ program to process student results. Accept marks for n subjects and calculate percentage and grade. Use exception handling: throw if number of subjects is 0 (division by zero) or if any marks are invalid (< 0 or > 100). Shortcut: B20 — Employee Age VerificationWrite a C++ program to register an employee. Accept name, age, and years of experience. Use exception handling to validate: age must be between 18 and 60, and experience must be non-negative. Shortcut: B21 — AreaCalculator OverloadingCreate a class AreaCalculator with overloaded methods area() to: Calculate area of a Square (int side), Rectangle (int length, int breadth), and Circle (float radius). Demonstrate compile-time polymorphism. Shortcut: B22 — Calculator multiply OverloadingCreate a class Calculator with overloaded methods multiply() to: Multiply two integers, multiply three integers, and multiply two double values. Demonstrate compile-time polymorphism by calling different versions. Shortcut: B23 — Shape Perimeter (Java)Design and implement a Java application to calculate the perimeter of Circle, Rectangle, and Triangle using hierarchical inheritance. Base class Shape defines perimeter(). Each derived class overrides it. Demonstrate runtime polymorphism using a base class reference. Shortcut: B24 — Threads Even/Odd (Java)Write a Java program to create two threads. One thread displays even numbers from 1 to 20 (using Thread class), and the other displays odd numbers from 1 to 20 (using Runnable interface). Shortcut: B25 — Threads Even/Div-by-5 (Java)Write a Java program to create two threads. One thread displays even numbers between 1 and 50, and the other displays numbers divisible by 5 between 1 and 50. Both use the Thread class. Shortcut: B26 — Shape Area (Java)Design and implement a Java application to calculate the area of Circle, Rectangle, and Triangle using hierarchical inheritance. Base class Shape defines area(). Each derived class overrides it. Demonstrate runtime polymorphism using a base class reference. Shortcut: |