OOP Homework 4
OOP Homework 4
Homework 4
Instructions
1. Write clean and well-structured code with proper indentation.
2. Comment your code to explain key logic.
3. Ensure the code compiles and runs correctly before submission.
4. Upload your work before the deadline.
5. Submission will be Online on Google Classroom with Screenshots of running code in a word file.
6. Ask questions before the deadline if you have doubts.
🚀 Happy Coding!
------------------------------------------------------------------------------------------------------------------------------------------
1. Requirement:
Create a base class Account with data members:
accountNumber, balance.
Create a derived class SavingsAccount that adds an interest rate
and a function to apply interest. Use constructor for initialization.
-----------------------------------------------------------------------------------------------------------------------------------------
2. Requirement:
Create a base class Vehicle with brand and speed.
Create a derived class Car that adds model, and a function to
display full details.
Make sure:
------------------------------------------------------------------------------------------------------------------------------------------
3. Task:
1. Create a base class Person with:
o name (string), age (int)
2. Inherit Student from Person, and add:
o rollNo (int), degreeProgram (string)
3. Inherit GraduateStudent from Student, and add:
o researchTopic (string)
4. Input values for all fields using a GraduateStudent object and
display all details.
------------------------------------------------------------------------------------------------------------------------------------------
4. Task:
Create class Person with:
o salary (float)
Create class Teacher that inherits from both Person and Employee.
5. Task:
1. Create a base class Publication with:
o title (string), price (float)
2. Inherit class Book from Publication and add:
o pageCount (int)
3. Inherit class Magazine from Publication and add:
o issueNumber (int)
4. Input and display data for both Book and Magazine objects.
------------------------------------------------------------------------------------------------------------------------------------------
6. Task:
1. Create base class Person with name and age.
2. Inherit class Student and class Employee from Person.
3. Create class TeachingAssistant that inherits from both Student
and Employee.
4. Use virtual inheritance to avoid duplication of Person.
5. Input all values and display them using a TeachingAssistant
object.
------------------------------------------------------------------------------------------------------------------------------------------
7. Scenario:
You are designing a library system that keeps track of books,
DVDs, and the users who borrow them.
Requirements:
------------------------------------------------------------------------------------------------------------------------------------------
8. Scenario:
The university wants a system to store basic details of people, and
extended information for students and faculty.
Requirements:
Tasks:
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Classes:
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Requirements:
Constraints:
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
13. In a travel booking system:
BusInfo: routeNo, capacity
DriverInfo: driverName, licenseNo
BusDriver inherits both
Add constructor for all and a single display() method in derived class to show everything.
------------------------------------------------------------------------------------------------------------------------------------------
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Tasks:
Instructions:
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Instructions:
------------------------------------------------------------------------------------------------------------------------------------------
19. You are designing a system for a university to manage all types of people involved. Create the
following hierarchy:
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
1. Create an array of base class pointers (Account*) and store both types.
2. Take input for each, call calculateInterest() polymorphically.
3. Add a withdraw(double amount) method in base class. Override in derived classes with
conditions.
4. Demonstrate the use of delete with virtual destructors
------------------------------------------------------------------------------------------------------------------------------------------
22. Scenario:
A university portal handles both administrative and academic data.
Tasks:
1. Create User* array to hold all types and call virtual functions polymorphically.
2. Input data for each object dynamically.
3. Use proper destructor chaining (make base class destructors virtual).
4. Demonstrate how virtual inheritance helps avoid ambiguity of User.
------------------------------------------------------------------------------------------------------------------------------------------
Tasks:
------------------------------------------------------------------------------------------------------------------------------------------
24. Task:
Create a function template add() that can accept two parameters of any type and return their
sum. Demonstrate this for:
Two integers
Two floats
Two characters (use ASCII logic)
------------------------------------------------------------------------------------------------------------------------------------------
25. Task:
Create a class template Pair<T1, T2> that holds two values of potentially different types.
Add constructor
Add a method void displayPair() to print them
Create 3 objects:
o Pair<int, int>
o Pair<string, double>
o Pair<char, bool>
Demonstrate its working in main().
------------------------------------------------------------------------------------------------------------------------------------------
26. Task:
Write a function template findMinMax() that takes an array of any numeric type and:
Returns both minimum and maximum elements (use Pair<T, T> from Q2 if desired)
Works with int, float, and double
Use template specialization for char[] to return highest and lowest alphabet.
------------------------------------------------------------------------------------------------------------------------------------------
27. Task:
Build a reporting system with the following:
Requirements:
1. Use a base class pointer array Report<T>* and store both StudentReport and SalesReport
2. Call generate() polymorphically
3. Demonstrate inheritance + template usage cleanly
------------------------------------------------------------------------------------------------------------------------------------------
28. Task:
Write a program that asks the user to input two integers and divides the first by the second. If the
second number is zero, throw an exception and catch it to display "Division by zero is not
allowed!".
------------------------------------------------------------------------------------------------------------------------------------------
29. Task:
Write a program that takes a user's age and name.
------------------------------------------------------------------------------------------------------------------------------------------
30. Task:
Create a class NegativeBalanceException to handle banking errors.
Be a separate class
Contain a what() or getMessage() function to describe the issue
------------------------------------------------------------------------------------------------------------------------------------------
31. Task:
Create a class ResourceHandler that:
------------------------------------------------------------------------------------------------------------------------------------------
32. Scenario:
You are tasked with building a University Grading Portal where students from different departments
can log in and check their grades.
Instructions:
Also implement:
Proper destructors
Base class pointer usage
Exception handling
------------------------------------------------------------------------------------------------------------------------------------------
33. Scenario:
You’re developing an e-commerce platform backend. Each product has a stock level and price.
Instructions:
------------------------------------------------------------------------------------------------------------------------------------------
34.Scenario:
You're developing a Smart Traffic Light Control System with different modes for Day, Night,
and Emergency.
The system must use dynamic dispatch to determine how long each light stays ON.
Based on real-time traffic data (could be float, int, etc.), use a template function or
class.
If the data received is invalid (e.g., negative traffic count), throw an exception.
Requirements:
------------------------------------------------------------------------------------------------------------------------------------------
35. Scenario:
You are developing a Hospital Patient Management System that handles in-patient, out-
patient, and emergency cases.
System Requirements:
------------------------------------------------------------------------------------------------------------------------------------------
36.
Scenario:
Design a University Attendance Tracker.
37. Design a system for managing software license keys. A base class License should store
licenseID, type, and expiryDate.
Derive TrialLicense and PremiumLicense.
Add a function validate() that throws a LicenseExpiredException if the current date is past
expiry. Demonstrate exception catching in main() using base class pointers.
------------------------------------------------------------------------------------------------------------------------------------------
38.
Build a templated class Vector3D<T> to represent a 3D point. Derive PhysicsVector<T> that
adds magnitude and direction. Overload +, - operators. Create an array of base pointers to
manipulate both Vector3D and PhysicsVector objects.
------------------------------------------------------------------------------------------------------------------------------------------
39.
Create a function template safeDivide(T a, T b) that divides two numbers and throws a
DivisionByZeroException if b is zero. Use it to divide values of various types (int, float, double) and
demonstrate catching the exception in main().
------------------------------------------------------------------------------------------------------------------------------------------
40.
Create a class template Account<T> to hold account numbers and balance. Derive
SavingsAccount<T> and CurrentAccount<T>. Add a withdraw(T amount) method that throws
InsufficientBalanceException. In main(), simulate withdrawal attempts for both account types.
------------------------------------------------------------------------------------------------------------------------------------------
41.
Create classes Person and ContactInfo, both with a method displayInfo(). Derive Customer
from both. Resolve ambiguity using virtual inheritance. Call displayInfo() polymorphically
using a base pointer and show full customer info.
------------------------------------------------------------------------------------------------------------------------------------------
42.
Create a hierarchy: Device → SmartDevice → SmartWatch. Use templates in SmartDevice to
handle battery type. Override a function diagnose() at each level. Call diagnose() using a
Device* pointer for a SmartWatch object.
------------------------------------------------------------------------------------------------------------------------------------------
43. Scenario:
You’re designing a type-generic Online Wallet System for different currencies.
------------------------------------------------------------------------------------------------------------------------------------------
44. Scenario:
Build a Smart Home Controller System.
Create base classes Sensor and Appliance (both have a virtual function status()).
Create a derived class SmartAirConditioner inheriting from both, resolving function
ambiguity.
If sensor reports an invalid reading (e.g., negative temperature), throw
SensorFailureException.
Use polymorphism to show the status() of multiple smart devices.
------------------------------------------------------------------------------------------------------------------------------------------
45. Scenario:
You’re tasked with creating a Student Feedback System.
Base class: Feedback<T> where T is the type of feedback rating (int, float, etc.).
Derived classes: CourseFeedback, FacultyFeedback, EventFeedback.
All classes should override displayFeedback() and store both numeric and written
feedback.
Use a template function to calculate average feedback scores and print per category.
------------------------------------------------------------------------------------------------------------------------------------------
46.
Scenario:
Create a Parcel Delivery Simulator.
------------------------------------------------------------------------------------------------------------------------------------------
47.
You are required to develop a basic version of a Library Membership and Book Management System
using C++. The system will manage books, members, and their borrowing activity. The goal is to
demonstrate your understanding of object-oriented principles including inheritance, polymorphism,
templates, and exception handling.
Requirements:
Create a class template Book<T> where T is the type of the book ID (can be int, string, etc.).
The class should contain:
o T bookID, string title, string author, bool isIssued
o Member functions: issueBook(), returnBook(), displayDetails()
Derive two classes:
o TextBook<T> – includes an extra attribute string subject
o Magazine<T> – includes an extra attribute string issueMonth
Use virtual functions to override displayDetails() in derived classes.
Use a base class pointer to manage and display details for books and members polymorphically.
Create a function template calculateFine(T daysLate) that returns fine based on days
late.
Use this function to calculate fines for different member types in returnBook().
4. Exception Handling
In main():
Create at least 2 books and 2 members (one student and one faculty)
Demonstrate issuing, returning, and displaying book/member information using base class
pointers
Demonstrate template usage and exception handling
------------------------------------------------------------------------------------------------------------------------------------------
Abstract base class Result with pure virtual calculateGrade() and exportToFile().
Derived: InternalResult, FinalResult.
Grades are calculated differently in each.
If marks are missing or invalid (negative), throw InvalidMarkException.
Store multiple Result* pointers and loop through them to display grades and simulate
export.
------------------------------------------------------------------------------------------------------------------------------------------
49. Scenario:
A tech company is developing a system to handle employee performance across various
departments.
Each department evaluates performance differently, and some use monthly metrics, while
others rely on quarterly reviews.
If an evaluation score is negative or missing, the system must throw an exception.
The company wants to use a unified interface to trigger performance evaluations for all
departments.
Task:
Design a class structure that models this system. Use inheritance to represent different
departments and polymorphism to handle evaluation calls dynamically. Implement exception
handling for invalid evaluation scores. Demonstrate your system by evaluating at least 3
employees from different departments.
------------------------------------------------------------------------------------------------------------------------------------------
50. Scenario:
You're hired to build a generic system for managing product inventories in a warehouse.
Task:
Implement a flexible class design using templates and multiple inheritance where required.
Ensure the system handles category-specific logic correctly and demonstrates extensibility. Use
virtual functions where appropriate to allow dynamic summary generation across product types.
------------------------------------------------------------------------------------------------------------------------------------------