EX NO 6 : OOPS LAB - VIRTUAL FUNCTIONS AND PURE VIRTUAL FUNCTIONS
EX NO 6 : Virtual Functions and Pure Virtual
Functions
Set 1: Abstract Shape Hierarchy ( ROLL NUM - 1 TO 5)
Design a C++ program to represent geometric shapes using an abstract class Shape with a pure virtual function area(). Derive classes such as Circle, Rectangle, and Triangle, and implement the area() function in each class. Accept necessary dimensions from the user and display the computed area using base class pointers to demonstrate runtime polymorphism.
Set 2: Employee Salary System
Develop a payroll system using an abstract class Employee with a pure virtual function calculateSalary(). Derive classes such as FullTimeEmployee, PartTimeEmployee, and ContractEmployee, each calculating salary based on different criteria. Accept input values and display the salary using base class pointers.
Set 3: Banking Interest System
Create a banking system using a base class Bank with a virtual function calculateInterest(). Derive classes such as SavingsAccount and FixedDeposit, each overriding the function to calculate interest based on different formulas. Demonstrate runtime polymorphism using base class pointers.
Set 4: Vehicle Rental System ( ROLL NUM - 16 TO 20)
Design a vehicle rental system using an abstract class Vehicle with a pure virtual function calculateRent(). Derive classes such as Car, Bike, and Bus, each computing rental cost based on distance or duration. Accept input from the user and display the rental cost.
Set 5: Student Result Processing
Develop a program using an abstract class Student with a pure virtual function calculateResult(). Derive classes such as UGStudent and PGStudent, each implementing different grading rules. Accept marks and display the result using base class pointers.
Set 6: Electricity Bill Calculation
Create a program using an abstract class ElectricityBill with a pure virtual function calculateBill(). Derive classes such as Domestic, Commercial, and Industrial, each calculating the bill based on different unit rates. Accept the number of units consumed and display the total bill.
Set 7: Insurance Premium System
Design a program using an abstract class Insurance with a pure virtual function calculatePremium(). Derive classes such as LifeInsurance, HealthInsurance, and VehicleInsurance, each computing the premium using different parameters. Accept user input and display the premium amount.
Set 8: Payment Processing System
Develop an online payment system using an abstract class Payment with a pure
virtual function pay(). Derive classes such as CreditCard, DebitCard, and UPI,
each implementing payment processing logic differently. Simulate a payment
transaction and display appropriate messages.
Set 9: Hospital Billing System
Create a hospital billing system using a base class Patient with a virtual
function calculateBill(). Derive classes such as InPatient and OutPatient, each
calculating the bill based on different parameters such as consultation fees,
treatment cost, and room charges. Display the total bill.
Set 10: Library Item Management
Design a program using an abstract class LibraryItem with a pure virtual
function calculateFine(). Derive classes such as Book, Magazine, and DVD, each
calculating fine based on different per-day rates. Accept the number of days
delayed and display the fine amount.
Comments
Post a Comment