OBJECT-ORIENTED PROGRAMMING (OOP) PRACTICE PROGRAM
1. Class: VideoRental
Question:
Define a class VideoRental with the following:
Member Variables:
• String customerName – to store name of the customer
• int days – to store number of days the video is returned late
• double fine – to store the late fine
Member Functions:
• void input() – to input customer name and days
• void calFine() – to calculate fine based on:
Fine
Days Late per
Day
No
First 5 days
fine
Next 5 days ₹2/day
Next 5 days ₹4/day
Later ₹6/day
• void display() – to display name, days, and fine
• void main() – to create object and call the functions
2. Class: WaterBill
Question:
Define a class WaterBill to calculate a consumer's water bill.
Member Variables:
• String customerName
• int units – units of water consumed
• double billAmount
Member Functions:
• void input() – to input name and units
• void calculate() – to calculate bill as per:
Units Used Rate
First 50 units ₹1/unit
Next 50 units ₹1.5/unit
Next 100 units ₹2/unit
Remaining ₹3/unit
• void display() – display name, units, and bill
• void main() – to call the methods
3. Class: HotelStay
Question:
Define a class HotelStay to compute hotel stay charges.
Member Variables:
• String guestName
• int stayDays – total days stayed
• double charges
Member Functions:
• void input() – input name and number of days
• void computeCharges() – calculate charges based on:
Rated
Days Stayed
Per
Day
First 3 days ₹1000
Next 3 days ₹800
Next 4 days ₹600
After 10 days ₹500
• void display() – to display guest name, stay days, and charges
• void main() – to test the class
4. Class: LaundryService
Question:
Define a class LaundryService to compute the total cost for clothes washed.
Member Variables:
• String customerName
• int clothesCount
• double totalCost
Member Functions:
• void input() – to input the customer name and number of clothes
• void calculateCost() – cost per cloth:
Clothes Count Rate per Cloth
First 10 clothes ₹20
Next 10 clothes ₹15
Later ₹10
• void display() – to show customer name and total cost
• void main() – to run the functions
5. Class: GymMembership
Question:
Define a class GymMembership to calculate membership charges.
Member Variables:
• String memberName
• int months
• double charges
Member Functions:
• void input() – to input name and number of months
• void calcCharges() – based on:
Months Monthly Rate
First 3 months ₹1000
Next 3 months ₹900
Later ₹800
• void display() – to show name, months, charges
• void main() – to create object and run methods
6. Class: CourierService
Question:
Create a class CourierService to calculate shipping charges based on weight.
Member Variables:
• String senderName
• double weight (in kg)
• double charge
Member Functions:
• void input() – to input name and weight
• void calcCharge() – charges:
Weight (kg) Rate per kg
Up to 5 kg ₹50
Next 5 kg ₹40
Above 10 kg ₹30
• void display() – display sender name, weight, and charge
• void main() – to run the functions
7. Class: BusFare
Question:
Define a class BusFare to calculate total fare based on distance traveled.
Member Variables:
• String passengerName
• int distance (in km)
• double fare
Member Functions:
• void input() – take name and distance
• void calcFare() – rates:
Fare/
Distance (km)
km
First 10 km ₹5
Next 10 km ₹4
Above 20 km ₹3
• void display() – display name, distance, and fare
• void main() – to test the program
8. Class: MobileDataUsage
Question:
Create a class MobileDataUsage to calculate mobile data bill.
Member Variables:
• String userName
• double dataUsed (in GB)
• double bill
Member Functions:
• void input() – take user name and GB used
• void calcBill() – billing:
Data Used Rate/GB
First 2 GB ₹10
Next 3 GB ₹15
Beyond 5 GB ₹20
• void display() – show name, data used, and bill
• void main() – to create object and test methods
9. Class: Parking
Question:
Define a class Parking to calculate parking fees based on the number of hours a vehicle is parked.
Member Variables:
• String vehicleNumber – to store the vehicle's registration number
• int hours – to store the number of hours the vehicle is parked
• double fee – to store the calculated parking fee
Member Functions:
void input()
To input the vehicle number and number of hours.
void calculateFee()
To calculate parking fee based on the following tariff:
Parking Time Rate
First 2 hours Free
Next 3 hours ₹20/hour
Next 5 hours ₹30/hour
More than 10 hours ₹50/hour
Total fee is cumulative. For example, 7 hours:
• 2 hours free
• 3 hours × ₹20 = ₹60
• 2 hours × ₹30 = ₹60
• Total = ₹120
void display()
To display the vehicle number, hours parked, and total fee.
void main()
To create an object of the class, and invoke all methods in sequence.