Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

ISC Computer Programs (Set 2)

Uploaded by

Suin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

ISC Computer Programs (Set 2)

Uploaded by

Suin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Divine Mercy School

Notice for Class 12(Sc. & Comm.)


Session:2024-25

ISC Computer Programs


SET - 2
16. Write a program in Java to display the first twenty Hamming numbers.
[Hamming numbers, also known as ugly numbers and 5-smooth numbers, are natural numbers whose prime
factors are less than or equal to 5. They are of the form H = 2i x 3j x 5k, where i, j and k >= 0]
For example:-
1 is a hamming number because 1 = 20
12 s a hamming number because its prime factors are 2 and 3. 12 = 22 x 31

17. Write a program in Java to accept a string terminated by a full stop (.) or a question mark (?) from the user, and
check whether the string is a snowball string or not.
[A snowball string is a sentence where each word is arranged in ascending order of their length and is also
consecutive.]
For example:-
I am the best.
He may give bonus.

18. A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit
is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The
process is repeated until the original number is reached again.
A number is said to be prime if it has only two factors 1 and itself.
Example:
131
311
113
Hence, 131 is a circular prime.
Accept a positive number N and check whether it is a circular prime or not. The new numbers formed after the
shifting of the digits should also be displayed.

Test the program with the following data:


Example 1
INPUT:
N = 197
OUTPUT:
197
971
719
197 IS A CIRCULAR PRIME.

Example 2
INPUT:
N = 1193
OUTPUT:
1193
1931
9311
3119
1193 IS A CIRCULAR PRIME.

Example 3
INPUT:
N = 29
OUTPUT:
29
92
29 IS NOT A CIRCULAR PRIME.

19. Consider the sequence of natural numbers.


1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ………………..
Removing every second number produces the sequence
1, 3, 5, 7, 9, 13, 15 ………………..
This process continues indefinitely by removing the fourth, fifth…. and so on, till after a fixed number of steps,
certain natural numbers remain indefinitely. These numbers are known as Lucky Numbers.
Write a program in Java to generate and print lucky numbers less than a number N, accepted from the user.

20. A class “Teacher” defines the related information such as name, date of birth and the date of joining while
another class “Principal” defines the different functions to display the relative information about the teachers.
The details of both the classes are given below:
Class Name : Teacher
Data members/instance variables:
String name[], dob[], doj[] : String variable to store name, date of birth and date of joining of 50 teachers.
Member functions/methods:
void getdata() : To input the values of all the data members.
void show_getdata() : To display all the data members with suitable headings.

Class Name : Principal


Member functions/methods:
void sortdata() : To sort the arrays based on alphabetical order of names using the bubble sort
technique.
void display() : To display the sorted list of all the data members with suitable headings.
void searchdata() : To input the name of a teacher and search for it using sequential search
technique. If found, print the details of the searched item, otherwise print an
appropriate message.
(i) Specify the class Teacher giving the details of functions void getdata() and void show_getdata().
(ii) Using concept of inheritance, specify the class Principal giving the details of functions void sortdata(),
void display() and void searchdata(). The class Principal is derived from class Teacher.

21. A super class Detail has been defined to store the details of a customer. Define a sub class Bill to compute the
monthly telephone charge of the customer as per the chart given below:

NUMBER OF CALLS RATE


1 – 100 Only rental charge
101 – 200 60 paise per call + rental charge
201 – 300 80 paise per call + rental charge
Above 300 1 rupee per call + rental charge

The details of both the classes are given below:


Class Name : Detail
Data members/instance variables:
name : To store the name of the customer.
address : To store the address of the customer.
telno : To store the phone number of the customer.
rent : To store the monthly rental charge.
Member functions/methods:
Detail(...) : Parameterized constructor to assign values to data members.
void show() : To display the details of the customer.

Class name : Bill


Data members/instance variables:
n : To store the number of calls.
amt : To store the amount to be paid by the customer.
Member functions/methods:
Bill(...) : Parameterized constructor to assign values to data members of both classes
and to initialize amt = 0.0.
void cal() : Calculates the monthly telephone charge as per the chart given above.
void show() : Displays the details of the customer and amount to be paid.

Specify the class Detail giving details of the constructor() and void show(). Using the concept of inheritance,
specify the class Bill giving details of the constructor(), void cal() and void show().

22. Write a program in Java to store the numbers in a 4 x 4 matrix in a Double Dimensional Array. Arrange the
numbers of each row in ascending order and display the result.
Sample Input Sample Output
22 14 23 25 14 22 23 25

81 26 31 10 10 26 31 81

58 64 17 12 12 17 58 64

55 33 26 14 14 26 33 55

23. Specify a class Display_word that accepts a sentence str. Pass it to a method void Longest(String wd) to display
longest word of the sentence. The program further displays the ASCII code of each letter of the longest word.
Define the main() method to create an object and call the method Longest(String wd) to enable the task.
For example,
Sample Input: Understanding Computer Science
Sample Output: Understanding
ASCII codes are:
U : 85
n : 110
d : 100
e : 101
r : 114
s : 115
t : 116
a : 97
n : 110
d : 100
i : 105
n : 110
g : 103

24. The MOBIUS function M(N) for a natural number N is defined as:
M(N) = 1 : if N = 1
=0 : if any prime factor of N is contained in N more than once.
= (-1)p : if N is a product of p distinct prime factors
Example:
M(78) = -1 : for 78 = 2x3x13 so, M(78) = (-1)3 = -1
M(34) = 1 : for 34 = 2x17 so, M(34) = (-1)2 = 1
M(12) = 0 : for 12 = 2x2x3 so, M(12) = 0, for 2 appears two times
M(17) = -1 : for 17 = 17 so, M(17) = (-1)1 = -1, as 17 itself is a prime
Write a program to input a positive natural number N and output M(N). The program should continue till the
user wants.
Check the program for N = 666, N = 327, N = 29.

25. Given the two positive integers p and q, where p < q. Write a program to determine how many Kaprekar
numbers are there in the range between p and q (both inclusive) and output them.
The input contains two positive integers p and q. Assume p < 5000 and q < 5000. You are to output the number
of Kaprekar numbers in the specified range along with their values in the format specified below.
The following steps can be used to check whether a number is Kaprekar number or not:
(i) Find square of the number (n).
(ii) Divide the square of the number (n) in two parts in such a way that both the parts have equal number
of digits (if square number has even number of digits). In case, square of the number has odd number
of digits then divide the number in two parts such that left part may have the number of digits one less
than the right part.
(iii) Add both the parts together.
(iv) If sum obtained is equal to the original number (n), then the given number is said to be Kaprekar
number.

Example 1:
Input number = 45
Square of the number = 2025
Dividing square in two parts:
Left part = 20
Right part = 25
Sum of both the parts = 45
Hence, 45 is a Kaprekar number.

Example 2:
297
297 = 88209, right-hand piece of 88209 = 209 and left hand piece of 88209 = 88
Sum = 209 +88 =297, i.e. equal to the number.

Sample Input:
p=1
q = 1000
Sample Output:
The Kaprekar Numbers are:
1, 9, 45, 55, 99, 297, 703, 999
Frequency of Kaprekar numbers is: 8

Date of Submission : 28th October, 2024 (Monday)

You might also like