Comp X Proj 1
Comp X Proj 1
Instructions:-
Do all the programs in BlueJ environment.
1. Write Program statement/question.
2. Write the BlueJ program/code and execute the program.
3. Paste the Program Code and Output Screen from the BlueJ environment.
4. Write Variable Description Table/Chart.
(Submit Latest By 10.07.24)
Question 1:
Write a menu driven class to accept a number from the user and check whether it is a
Palindrome or a Perfect number.
(a) Palindrome number— (a number is a Palindrome which when read in reverse order
is same as read in the right order)
Example : 11, 101, 151 etc.
(b) Perfect number— (a number is called Perfect if it is equal to the sum of its factors
other than the number itself.) Example : 6 = 1 + 2 + 3
Question 2:
Using the switch statement, write a menu driven program to :
(i) Generate and display the first n terms of the Fibonacci series 0, 1, 1, 2, 3, 5….upto n
terms. The first two Fibonacci numbers are 0 and 1, and each subsequent number is
the sum of the previous two.
(ii) Find the sum of the odd digits of an integer that is input by the user.
Sample Input: 15290
Sample Output: Sum of the odd digits =15 (1+5+9)
(For an incorrect choice, an appropriate error message should be displayed.)
Question 3:
A courier company charges differently for 'Ordinary' booking and 'Express' booking
based on the weight of the parcel as per the tariff given below:
Express
Weight of parcel Ordinary booking
booking
Up to 100 gm Rs 80 Rs 100
101 to 500 gm Rs 120 Rs 150
501 gm to 1000 gm Rs 180 Rs 200
More than 1000 gm Rs 200 Rs 250
Write a program to input weight of a parcel and type of booking (`O' for Ordinary
Booking and 'E' for Express Booking). Calculate and print the charges accordingly.
Question 4:
Question 5:
Write a program to create a class ‘Finder’ with the following functions:-
(i) int findMax(int nl, int n2)- to decide and return bigger of the two numbers nl
and n2. If both the numbers are same then return 0.
(ii) int accept(int n, int n2, int n3)- to decide and return largest of the three
numbers nl, n2 and n3. The function will use int findMax(int n1, int n2 ) to find
larger of first two numbers and store in a variable ‘x’.
Then again use findMax(x, n3) to find larger of the two numbers and store in
a variable ‘f ’. The value ‘f ’ will be returned to the main( ) function and output
will be displayed in the main( ) function.
Question 6:
Write a program to print whether a given number is a Special number or not, by using
given functions.
int fact( int d)- to find and return the factorial of digit(d).
void print_Numbers( int n)- by invoking function fact() find and print whether ‘n’
is a Special number or not.
[ If sum of factorials of each digits of a number is equal to the given number itself,
then the number is a Special number.]
Example:- 145
= 1! + 4! + 5!
= 1+ 24 + 120
= 145 [ 145 is Special number ]
Question 7:
Write a program to design a class to overload a function printSeries( )as follows:
(a). void printSeries( intx, int n ) To compute the sum of the series:
(b). void printSeries( int a, int x, int n ) To print the Sum of the given series :
Question 8:
(ii) int SumCalc(int n) - with one integer argument (n) calculate and return sum
of only odd digits of the number ‘n’.
Sample input : n = 43961
Sample output : sum = 3 + 9 + 1 = 13
Write the main method to create an object and invoke the above methods.
Question 9:
Design a class BusFare that has the following specifications:-
Instance variables:
String nm : To store the passenger name
int km : To store kilometres travelled.
int fare : To store total fare.
Member functions:
BusFare ( ) : Constructor to initialize the instance variables.
void input ( ) : To input name and km travelled by a passenger.
void calfare( ) : To calculate bus fare according to the given conditions :
kilometers travelled Rate
<= 5 km Rs. 25
Next 5 km Rs. 10 / km
Next 10 km Rs 8 / km
Next 10 km Rs 6 / km
>30 km Rs. 5 / km
void display( ) : To display the details ie. name , km travelled and the total fare of
the passenger.
Write a main( ) method to create an object of the class and call the above
member methods.
Question 10:
A class C_Interest is created to calculate the compound interest using:
Member Data:
p, r, ci (double data type to store principal, rate and compound interest),
t (integer to store time period)
Member Methods/Functions:
(i) C_Interest ( ) – constructor to assign default values to all the data members.
(ii) void input( ) – to input the principal, rate and time from the user.
(iii) voidCal_Interest( ) – to find the compound interest using the given formula.
(iv) voidprintData( ) – to print the principal, rate, time and compound interest.
Write a main function create object of the class and by invoking suitable functions to
print the entered data and compound interest.
--------------------------------
Note:-