OBJECT-ORIENTED PROGRAMMING
1. Class: Rectangle
Question:
Define a class Rectangle to accept the length and breadth of a rectangle. Include the following
specifications:
Data Members:
• int length – to store the length
• int breadth – to store the breadth
• int area – to store area
• int perimeter – to store perimeter
Member Methods:
• void inputData() – to input length and breadth
• void calculate() – to compute area and perimeter
• void outputData() – to display area and perimeter
• void main()– to create an object and call all the function
2. Class: StudentResult
Question:
Define a class StudentResult to compute total and percentage of marks in three subjects.
Data Members:
• int rollNo – to store roll number
• String name – to store name
• int marks1, marks2, marks3 – to store subject marks
• int total – to store total marks
• float percentage – to store percentage
Member Methods:
• void input() – to accept roll number, name, and marks
• void calculate() – to compute total and percentage
• void display() – to display student details and results
• void main()– to create an object and call all the function
3. Class: BankAccount
Question:
Define a class BankAccount to simulate basic banking operations.
Data Members:
• int accountNo – to store account number
• String name – to store name
• double balance – to store account balance
Member Methods:
• void input() – to input account details
• void deposit(double amount) – to add amount to balance
• void withdraw(double amount) – to deduct amount if sufficient balance
• void display() – to show updated account details
• void main()– to create an object and call all the function
4. Class: ElectricityBill
Question:
Define a class ElectricityBill to calculate the bill based on units consumed.
Data Members:
• int consumerID – to store ID
• String consumerName – to store name
• int units – to store units consumed
• double billAmount – to store the bill
Member Methods:
• void input() – to accept inputs
• void calculate() – to calculate bill as per the following slab:
Units Consumed Rate per Unit
First 100 units ₹1.50/unit
Next 100 units ₹2.50/unit
Above 200 units ₹4.00/unit
• void display() – to display bill
• void main()– to create an object and call all the function
5. Class: Circle
Question:
Define a class Circle to compute area and circumference.
Data Members:
• double radius – to store radius
• double area – to store area
• double circumference – to store circumference
Member Methods:
• void input() – to accept radius
• void calculate() – to compute area and circumference
• void display() – to display results
• void main()– to create an object and call all the function
6. Class: EmployeeBonus
Question:
Define a class EmployeeBonus to calculate bonus based on salary.
Data Members:
• int employeeID – to store employee ID
• String name – to store employee name
• double basicSalary – to store salary
• double bonus – to store bonus amount
Member Methods:
• void input() – to accept data
• void calculate() – to compute bonus based on salary slab (see table below)
• void display() – to show results
• void main()– to create an object and call all the function
Bonus Rate Table:
Salary Range (₹) Bonus Rate (%)
Less than 20,000 20
20,000 to 50,000 15
Above 50,000 10
7. Class: Book
Question:
Define a class Book to manage book purchases and apply discount.
Data Members:
• int bookID – to store book ID
• String title – to store book title
• double price – to store price
• double discount – to store discount amount
• double netPrice – to store final price after discount
Member Methods:
• void input() – to accept book details
• void calculate() – to apply discount based on price slab (see table below)
• void display() – to show final price
• void main()– to create an object and call all the function
Discount Rate Table:
Price Range (₹) Discount Rate (%)
Less than 300 5
300 to 500 10
Above 500 15
8. Class: MobileRecharge
Question:
Define a class MobileRecharge to manage recharge details.
Data Members:
• long mobileNumber – to store mobile number
• String planType – to store plan type
• double amount – to store recharge amount
• int validity – to store validity period
Member Methods:
• void input() – to accept recharge details
• void planDetails() – to determine validity based on recharge amount (see table below)
• void display() – to show plan summary
• void main()– to create an object and call all the function
Plan Validity Table:
Recharge Amount (₹) Validity (Days)
100 7
200 28
500 84
9. Class: MarksGrade
Question:
Define a class MarksGrade to assign a grade based on marks.
Data Members:
• int rollNo – to store roll number
• String name – to store student name
• int marks – to store marks obtained
• char grade – to store assigned grade
Member Methods:
• void input() – to accept student details
• void calculateGrade() – to assign grade based on marks (see table below)
• void display() – to show grade
• void main()– to create an object and call all the function
Grade Assignment Table:
Marks Range Grade
90 and above A
75 to 89 B
50 to 74 C
Below 50 D
10. Class: GstCalculator
Question:
Define a class GstCalculator to compute GST and final price.
Data Members:
• int productID – to store product ID
• String productName – to store product name
• double price – to store price
• double gst – to store GST amount
• double finalAmount – to store total price including GST
Member Methods:
• void input() – to accept product details
• void calculateGST() – to compute GST based on product category and price (see table below)
• void display() – to show price summary
• void main()– to create an object and call all the function
GST Rate Table:
GST Rate
Product Category Price Range (₹)
(%)
Essentials Less than 100 5
Electronics All prices 18
Luxury items All prices 28