Class, Constructor and Objects
Section B
2005
Question 4
Write a class with name employee and basic as its data member.
Memeber method: compute() - to find the net pay of an employee for the following allowances and deduction.
Use meaningful variables.
Dearness Allowance = 25% of Basic Pay. House Rent Allowance = 15% of Basic Pay.
Provident Fund = 8.33% of Basic Pay. Gross Pay = Basic Pay + Dearness Allowance + HRA.
Net Pay = Gross Pay - Provident Fund. [15]
Variable Description
Variable | Type | Description |
---|---|---|
basic | double | To store basic pay |
da | double | To store dearness allowance |
hra | double | To store house rent allowance |
pf | double | To store provident fund |
gp | double | To store gross pay |
np | double | To store net pay |
2007
Question 4
Define a class salary described as below:-
Data Members:
Name, Address, Phone, Subject Specialization, Monthly Salary, Income Tax.
Member methods:
(i) To accept the details of a teacher including the monthly salary.
(ii) To display the details of the teacher.
(iii) To compute annual Income Tax as 5% of annual salary above Rs. 1,75,000/-
Write main method to create object and call the above member methods.
[15]
2008
Question 4
Define a class employee having the following description:
Data members/Instance Variables:
int pan to store personal account number.
String name to store name.
double taxincome to store annual taxable income.
double tax to store tax that is calculated.
Member functions:
input() Store the pan number,name and taxable income
calc() Calculate tax for an employee
display() Output details of an employee
Write a program to compute tax according to the given conditions and display output as given format. [15]
Total Taxable IncomeTax Rate
Upto Rs. 1,00,000No tax
From 1,00,001 to 1,50,00010% of the income exceeding Rs. 1,00,000
From 1,50,001 to 2,50,000Rs. 5,000+20% of the income exceeding 1,50,000
Above Rs.2,50,000Rs. 25,000+30% of income exceeding 2,50,000
Output:
Pan Name Tax
xxxx xxxx xx
2010
Question 5
Define a class student described as below:
Data members/Instance variables:
name, age, m1,m2,m3 (marks in 3 subjects), maximum, average.
Member methods:
(i) A parameterized constructor to initialize the data members.
(ii) To accept the details of a student.
(iii) To compute average and maximum out of three marks.
(iv) To display the name, age, marks in three subjects, maximum and average.
Write main () to create an object of the class and call the above member methods.
[15]
2011
Question 4
Define a class called mobike with following description:
Instance variables/data members:
int bno : to store the bike’s number
int phno : to store the phone number of the customer
String name : to store the name of the customer
int days : to store the number of days the bike is taken on rent
int charge : to calculate and store the total charge
Member methods:
void input() : to input and store the detail of the customer
void compute() : to compute the rental charge
The rent is charged as follows:
First five daysRs. 500 per day
Next five daysRs. 400 per day
Rest of the daysRs. 200 per day
void display() : to display the details in the following format:
Bike No.Phone No.NameNo. of daysCharge
xxxxxxxxxxxxxxxxxxxxxx[15]
2012
Question 4
Define a class Library with following description:
Instance Variables / Data Members:
int acc_num - stores the accession number of the book
String title - stores the title of the book
String author - stores the name of the author
Member methods:
1) void input() - To input and store the accession number, title and author
2) void compute() - To accept the number of days late, calculate and display
the fine charged at the rate of Rs. 2 per day.
3) void display() - To display the details in the following format:
Accession NumberTitle Author
--------------------- ------
xxxxxxxxxxxxxxxxxxxxx xxxxxx
Write a main method to create an object of the class and call the above methods.
[15]
2013
Question 4
Define a class named FruitJuice with the following description :
Instance variables/data members:
int product_code - stores the product code number
String flavour - stores the flavour of the juice(eg.orange,apple, etc)
String pack _type - stores the type of packaging(eg. Tetra pack, PET bottle, etc)
int pack_size - stores package size(eg.200ml,400ml,etc)
int product_price - stores the price of the product
Member methods:
(i) FruitJuice() - Default constructor to initialize integer data members to 0 and string data members to “”.
(ii) void input() - To input and store the product code, flavour, pack type, pack size and product price.
(iii) void discount() - To reduce the price by Rs. 10;
(iv) void display() - To display code, flavour, pack type, pack size and price
[15]
2014
Question 4
Define a class named movieMagic with the following description:
instance variables / data members:
int year - to store the year of release of a movie
String title - to store the title of the movie
float rating - to store the popularity rating of the movie
(minimum rating =0.0 and maximum rating =5.0)
Member methods:
(i) movieMagic() - Deafault constructor to initialize numeric data members to 0 and String data members to “”
(ii) void accept() - To input and store year, title and rating.
(iii) void display() - To display the title of a movie and a message based on the rating as per the table below:
0.0 to 2.0 Flop
2.1 to 3.4 Semi hit
3.5 to 4.5 Hit
4.6 to 5.0 Super hit
Wrtie a main method to create an object of the class and call the above member methods
[15]
2015
Question 4
Define a class ParkingLot with the following description:
Instance variables/data memebers:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle parked in the parking lot
double bill – To store the bill amount
Member methods:
void input() – To input and store the vno and hours.
void calculate() – To compute the parking charge at the rate of Rs. 3 for the first hour
or part thereof, and Rs. 1.50 for each additional hour or part thereof.
void display() – To display the details
Write a main method to create an object of the class and call the above methods.
[15]
2016
Question 4
Define a class named BookFair with the following description:
Instance variables / Data members:
String Bname – stores the name of the book
double price – stores the price of the book
Member methods:
(i) BookFair() - Default constructor to initialize data members
(ii) void Input() - To input and store the name and the price of the book
(iii) void calculate() - To calculate the price after discount. Discount is calculated based on the following
PriceDiscount
Less than or equal to Rs. 10002% of price
More than Rs. 1000 and less than or equal to Rs. 300010% of price
More than Rs. 300015% of price
(iv) void display() - To display name and price of the book after discount
Write a main method to create an object of the class and call the above member methods.
[15]
2017
Question 4
Define a class ElectricBill with the following specification:
Instance variables / Data members:
String n – to store the name of the customer
int units – to store the number units consumed
double bill – stores the amount to be paid
Member methods:
(i) void accept() - To accept name of the customer and number of units consumed
(ii) void calculate() - To calculate the bill as per the following tariff:
Number of unitsRate per unit
First 100 unitsRs.2.00
Next 200 unitsRs.3.00
Above 300 unitsRs.5.00
A surcharge of 2.5% charged if the number of units is above 300.
(iii) void print() - To print the details as follows:
Name of the customer: …………………….
Number units consumed: …………
Bill amount: …………………
Write a main method to create an object of the class and call the above member methods.
[15]
2018
Question 4
Design a class RailwayTicket with following description:
Instance variables/data members:
String name : To store the name of the customer
String coach : To store the type of coach customer wants to travel
long mobno : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalamt : To store the amount to be paid after updating the original amount
Member methods:
void accept() - To take input for name, coach, mobile number and amount.
void update() - To update the amount as per the coach selected
(extra amount to be added in the amount as follows)
Types of CoachesAmount
First_AC700
Second_AC500
Third_AC200
SleeperNone
void display() - To display all details of a customer such as name, coach, total amount and mobile number
Write a main method to create an object of the class and call the above member methods.
[15]
2019
Question 4
Design a class ShowRoom with following description:
Instance variables/data members:
String name : To store the name of the customer
long mobno : To store customer’s mobile number
double cost : To store cost of the items purchased
double dis : To store discount
double amount : To store amount to be paid after discount
Member methods:
ShowRoom - default constructor to initialize data members
void input() - To input customer name, mobile number and cost.
void calculate() - To calculate dicount on cost of purchased items based on following citeria:
(extra amount to be added in the amount as follows)
CostDiscount rate
Less than equal to Rs. 100005%
More than 10000 and less than equal to 2000010%
More than 20000 and less than equal to 3500015%
More than 3500010%
void display() - To display customer name, mobile number, amount to be paid after discount
Write a main method also to create an object of the class and call the above member methods.
[15]
2020
Question 4
A private Cab service company provides service within the city at the following rates:
AC CARNON AC CAR
UPTO 5 KM ₹ 150/-₹ 120/-
BEYOND 5 KM₹ 10/-PER KM₹ 08/- PER KM
Design a class CabService with the following description:
Member variables /data members:
String car_type - To store the type of car (AC or NON AC)
double km - To store the kilometer travelled
double bill - To calculate and store the bill amount
Member methods :
CabService() - Default constructor to initialize data members.
String data members to "" and
double data members to 0.0
void accept () - To accept car_type and km (using Scanner class only).
void calculate () - To calculate the bill as per the rules given above.
void display() - To display the bill as per the following format:
CAR TYPE:
KILOMETER TRAVELLED:
TOTAL BILL:
Create an object of the class in the main method and invoke the member methods.
[15]
Question 7
Design a class to overload a method Number( ) as follows:
(i) void Number (int num , int d) - To count and display the frequency of a digit in a number.
Example:
num = 2565685
d = 5
Frequency of digit 5 = 3
(ii) void Number (int n1) - To find and display the sum of even digits of a number.
Example:
n1 = 29865
Sum of even digits = 16
Write a main method to create an object and invoke the above methods.
[15]