[go: up one dir, main page]

0% found this document useful (0 votes)
50 views12 pages

Class 11 Computer

The document outlines a series of programming tasks for Class 11 students, covering various topics such as generating the Hailstone Sequence, converting day numbers to dates, implementing binary search, checking for palindrome numbers, and more. Each task includes specific requirements for classes, methods, and expected outputs, along with examples for clarity. The document serves as a comprehensive guide for students to practice their programming skills in Java.

Uploaded by

srivastavayug2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views12 pages

Class 11 Computer

The document outlines a series of programming tasks for Class 11 students, covering various topics such as generating the Hailstone Sequence, converting day numbers to dates, implementing binary search, checking for palindrome numbers, and more. Each task includes specific requirements for classes, methods, and expected outputs, along with examples for clarity. The document serves as a comprehensive guide for students to practice their programming skills in Java.

Uploaded by

srivastavayug2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Class 11

Question 1. Write a program to find the Hailstone Sequence of a given number. The Hailstone Sequence
of numbers can be generated starting from an integer n by following these rules:
If n is 1 then sequence ends.
If n is even then the next n of the sequence = n / 2
If n is odd then the next n of the sequence = (3 * n) + 1
Example:
Input:
Enter a number: 13
Output:
The Hailstone Sequence starting from 13 is:
40 20 10 5 16 8 4 2 1

Question 2. Create a class Convert to find the date and the month from a given day number for a
particular year.
Example: If day number is 64 and the year is 2020, then the corresponding date would be:
March 4, 2020 i.e. (31 + 29 + 4 = 64)
Some of the members of the class are given below:
Class name: Convert
Data members/instance variables:
n: integer to store the day number.
d: integer to store the day of the month (date).
m: integer to store the month.
y: integer to store the year.
Methods/Member functions:
Convert ( ): constructor to initialize the data members with legal initial values.
void accept( ): to accept the day number and the year.
void day_to_date( ): converts the day number to its corresponding date for a particular
year and stores the date in ‘d’ and the month in ‘m’.
void display( ): displays the month name, date and year.
Specify the class Convert giving details of the constructor ( ), void accept( ), void day_to_date( ) and void
display( ).
Define a main ( ) function to create an object and call the functions accordingly to enable the task.

Question 3. Design a class BinarySearch to search for a particular value in an array.


Some of the members of the class are given below:
Class name: BinarySearch
Data Members/Instance Variables:
No[ ]: to store integer elements.
n: integer to store the size of the array.
Member Functions/Methods:
BinarySearch(int nn) : parameterized constructor to initialize n=nn.
void fillArray( ): to enter elements in the array.
void sort( ) : sort the array elements in ascending order using bubble sort technique.
int binSearch(int l, int u, int v) : searches for the value ‘v’ using binary search and returns its location if
found otherwise returns -1.
Define the class BinarySearch giving details of the constructor( ), void fillArray( ),
void sort( ) and int binSearch(int, int, int).
Define the main( ) function to create an object and call the functions accordingly to enable the task.

Question 4. A class Palin has been defined to check whether a positive number is a Palindrome number or
not. The number ‘N’ is palindrome if the original number and its reverse are same.
Some of the members of the class are given below:
Class name : Palin
Data members/instance variables:
num : integer to store the number
revnum : integer to store the reverse of the number
Methods/Member functions:
Palin( ) : constructor to initialize data members with legal initial values
void accept( ) : to accept the number.
int reverse(int y) : reverses the parameterized argument ‘y’ and stores it in ‘revnum’.
void check( ) : checks whether the number is a Palindrome by invoking the function
reverse( ) and display the result with an appropriate message.
Specify the class Palin giving the details of the constructor( ), void accept( ), int reverse( int ) and void
check( ).
Define the main( ) function to create an object and call the functions accordingly to enable the task.

Question 5. A class SwapSort has been defined to perform string related operations on a word input.
Some of the members of the class are as follows:
Class name : SwapSort
Data members/instance variables:
wrd : to store a word
len : integer to store length of the word
swapwrd : to store the swapped word
sortwrd : to store the sorted word
Member functions/methods:
SwapSort( ) : default constructor to initialize data members with legal initial values.
void readword( ) : to accept a word in UPPER CASE.
void swapchar( ) : to interchange/swap the first and last characters of the word in ‘wrd’ and stores the new
word in ‘swapwrd’.
void sortword( ) : sorts the characters of the original word in alphabetical order and stores it in ‘sortwrd’.
void display( ) : displays the original word, swapped word and the sorted word
Specify the class SwapSort, giving the details of the constructor( ), void readword( ), void swapchar( ), void
sortword( ) and void display( ).
Define the main( ) function to create an object and call the functions accordingly to enable the task.

Question 6. Write a java program by using a class with the following specifications:
Class Name : Merge
Data Members/Variables:
str1-To enter first string, str2-To enter second string and str-To make a new string.
Member Functions:
void accept(): To accept str1 and str2.
void mergeFirstLast(): To make a new string by taking each character of the str1 from left to right and the
str2 from right to left. The characters should be taken alternatively from each string (assume that the length
of both the strings are same).
Example:
Input:
str1 = COMPUTER
str2 = COMMERCE
Output:
COMPUTER
COMMERCE
CEOCMRPEUMTMEORC
void display(): To print str1, str2 and str (new string).
Write main method also to call the functions and execute the program.

Question 7. 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 your program with the following data and some random 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.

Question 8. Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The
words may be separated by more than one blank space and are in UPPER CASE.
Perform the following tasks:
1. Find the number of words beginning and ending with a vowel.
2. Place the words which begin and end with a vowel at the beginning, followed by the remaining
words as they occur in the sentence.
Test your program with the sample data and some random data:
Example 1
INPUT:
ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL
Example 2
INPUT:
YOU MUST AIM TO BE A BETTER PERSON TOMORROW THAN YOU ARE TODAY.
OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 2
A ARE YOU MUST AIM TO BE BETTER PERSON TOMORROW THAN YOU TODAY
Example 3
INPUT:
LOOK BEFORE YOU LEAP.
OUTPUT:
NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL = 0
LOOK BEFORE YOU LEAP
Example 4
INPUT:
HOW ARE YOU@
OUTPUT:
INVALID INPUT

Question 9. A company manufactures packing cartons in four sizes, i.e. cartons to accommodate 6 boxes,
12 boxes, 24 boxes and 48 boxes. Design a program to accept the number of boxes to be packed (N) by the
user (maximum up to 1000 boxes) and display the break-up of the cartons used in descending order of
capacity (i.e. preference should be given to the highest capacity available, and if boxes left are less than 6,
an extra carton of capacity 6 should be used.)
Test your program with the following data and some random data:
Example 1
INPUT:
N = 726
OUTPUT:
48 * 15 = 720
6*1=6
Remaining boxes = 0
Total number of boxes = 726
Total number of cartons = 16
Example 2
INPUT:
N = 140
OUTPUT:
48 * 2 = 96
24 * 1 = 24
12 * 1 = 12
6*1=6
Remaining boxes = 2 * 1 = 2
Total number of boxes = 140
Total number of cartons = 6
Example 3
INPUT:
N = 4296
OUTPUT:
INVALID INPUT

Question 10. A Goldbach number is a positive even integer that can be expressed as the sum of two odd
primes.
Note: All even integer numbers greater than 4 are Goldbach numbers.
Example:
6=3+3
10 = 3 + 7
10 = 5 + 5
Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5.
Write a program to accept an even integer 'N' where N > 9 and N < 50. Find all the odd prime pairs whose
sum is equal to the number 'N'.
Test your program with the following data and some random data:
Example 1
INPUT:
N = 14
OUTPUT:
PRIME PAIRS ARE:
3, 11
7, 7
Example 2
INPUT:
N = 30
OUTPUT:
PRIME PAIRS ARE:
7, 23
11, 19
13, 17
Example 3
INPUT:
N = 17
OUTPUT:
INVALID INPUT. NUMBER IS ODD.
Example 4
INPUT:
N = 126
OUTPUT:
INVALID INPUT. NUMBER OUT OF RANGE.

Question 11. The names of the teams participating in a competition should be displayed on a banner
vertically, to accommodate as many teams as possible in a single banner. Design a program to accept the
names of N teams, where 2 < N < 9 and display them in vertical order, side by side with a horizontal tab (i.e.
eight spaces).
Test your program for the following data and some random data:
Example 1
INPUT:
N=3
Team 1: Emus
Team 2: Road Rols
Team 3: Coyote
OUTPUT:
E R C
m o o
u a y
s d o
t
R e
o
l
s
Example 2
INPUT:
N=4
Team 1: Royal
Team 2: Mars
Team 3: De Rose
Team 4: Kings
OUTPUT:
R M D K
o a e i
y r n
a s R g
l o s
s
e
Example 3
INPUT:
N = 10
OUTPUT:
INVALID INPUT

Question 12. Design a program to accept a day number (between 1 and 366), year (in 4 digits) from the
user to generate and display the corresponding date. Also, accept 'N' (1 <= N <= 100) from the user to
compute and display the future date corresponding to 'N' days after the generated date. Display an error
message if the value of the day number, year and N are not within the limit or not according to the condition
specified.
Test your program with the following data and some random data:
Example 1
INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22
OUTPUT:
DATE: 12TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4TH OCTOBER, 2018
Example 2
INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45
OUTPUT:
DATE: 26TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9TH FEBRUARY, 2019
Example 3
INPUT:
DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33
OUTPUT:
DAY NUMBER OUT OF RANGE
Example 4
INPUT:
DAY NUMBER: 150
YEAR: 2018
DATE AFTER (N DAYS): 330
OUTPUT:
DATE AFTER (N DAYS) OUT OF RANGE

Question 13. Write a program to accept a sentence which may be terminated by either ‘.’, ‘?’ or ‘!’ only.
The words are to be separated by a single blank space and are in uppercase.
Perform the following tasks:
(a) Check for the validity of the accepted sentence.
(b) Convert the non-palindrome words of the sentence into palindrome words by concatenating the word by
its reverse (excluding the last character).
Example:
The reverse of the word HELP would be LEH (omitting the last alphabet) and by concatenating both, the
new palindrome word is HELPLEH. Thus, the word HELP becomes HELPLEH.
Note: The words which end with repeated alphabets, for example ABB would become ABBA and not
ABBBA and XAZZZ becomes XAZZZAX.
[Palindrome word: Spells same from either side. Example: DAD, MADAM etc.]
(c) Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:
Example 1
INPUT:
THE BIRD IS FLYING.
OUTPUT:
THE BIRD IS FLYING.
THEHT BIRDRIB ISI FLYINGNIYLF
Example 2
INPUT:
IS THE WATER LEVEL RISING?
OUTPUT:
IS THE WATER LEVEL RISING?
ISI THEHT WATERETAW LEVEL RISINGNISIR
Example 3
INPUT:
THIS MOBILE APP LOOKS FINE.
OUTPUT:
THIS MOBILE APP LOOKS FINE.
THISIHT MOBILELIBOM APPA LOOKSKOOL FINENIF
Example 3
INPUT:
YOU MUST BE CRAZY#
OUTPUT:
INVALID INPUT

Question 14. A Prime-Adam integer is a positive integer (without leading zeros) which is a prime as well
as an Adam number.
Prime number: A number which has only two factors, i.e. 1 and the number itself.
Example: 2, 3, 5, 7 ... etc.
Adam number: The square of a number and the square of its reverse are reverse to each other.
Example: If n = 13 and reverse of 'n' = 31, then,
(13)2 = 169
(31)2 = 961 which is reverse of 169
thus 13, is an Adam number.
Accept two positive integers m and n, where m is less than n as user input. Display all Prime-Adam integers
that are in the range between m and n (both inclusive) and output them along with the frequency, in the
format given below:
Test your program with the following data and some random data:
Example 1
INPUT:
m=5
n = 100
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
11 13 31
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 2
INPUT:
m = 100
n = 200
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
101 103 113
FREQUENCY OF PRIME-ADAM INTEGERS IS: 3
Example 3
INPUT:
m = 50
n = 70
OUTPUT:
THE PRIME-ADAM INTEGERS ARE:
NIL
FREQUENCY OF PRIME-ADAM INTEGERS IS: 0
Example 4
INPUT:
m = 700
n = 450
OUTPUT:
INVALID INPUT

Question 15. Write a program to accept a sentence which may be terminated by either '.', '?' or '!' only. The
words are to be separated by a single blank space and are in UPPER CASE.
Perform the following tasks:
1. Check for the validity of the accepted sentence only for the terminating character.
2. Arrange the words in ascending order of their length. If two or more words have the same length,
then sort them alphabetically.
3. Display the original sentence along with the converted sentence.
Test your program for the following data and some random data:
Example 1:
INPUT:
AS YOU SOW SO SHALL YOU REAP.
OUTPUT:
AS YOU SOW SO SHALL YOU REAP.
AS SO SOW YOU YOU REAP SHALL
Example 2:
INPUT:
SELF HELP IS THE BEST HELP.
OUTPUT:
SELF HELP IS THE BEST HELP.
IS THE BEST HELP HELP SELF
Example 3:
INPUT:
BE KIND TO OTHERS.
OUTPUT:
BE KIND TO OTHERS.
BE TO KIND OTHERS
Example 4:
INPUT:
NOTHING IS IMPOSSIBLE#
OUTPUT:
INVALID INPUT
Question 16. Consider the sequence of natural numbers 1, 2, 3, 4, 5, 6, 7……
Removing every second number produces the sequence 1, 3, 5, 7, 9, 11, 13, 15, 17, ……….
Removing every third number produces the sequence 1, 3, 7, 9, 13, 15, 19, 21, 25, 27,…….
This process continues indefinitely by removing fourth, fifth …. and so on, till after a fixed number of steps
certain numbers remains indefinitely. These are known as lucky numbers. Write a program to generate and
print lucky numbers less than a given natural number N where N<=50.

Question 17. Input consists of month number (MM), the day of the month (DD) and the year (YYYY).
Write a program to calculate and print the corresponding day of the year (in the range 1 to 366).
Example:
Input: Month 05
Day 03
Year 1996
Output: CORRESPONDING DAY OF THE YEAR IS : 124
( 31 + 29 + 31 + 30 + 3 = 124 )
Test your program with the following sample data.
MONTH DAY YEAR
09 07 2000
05 03 1954
12 13 1960

Question 18. A number is said to Bouncy number if the digits of the number are unsorted.
For example,
22344 - It is not a Bouncy number because the digits are sorted in ascending order.
774410 - It is not a Bouncy number because the digits are sorted in descending order.
155349 - It is a Bouncy number because the digits are unsorted.
A number below 100 can never be a Bouncy number.
Write a program in java to accept a number. Check and display whether it is a Bouncy number or not.

Question 19. A triangular number is formed by the addition of consecutive integers starting with 1. For
example,
1+2=3
1+2+3=6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
Thus, 3, 6, 10, 15, are triangular numbers.
Write a program in Java to display all the triangular numbers from 3 to n, taking the value of n as an input.

Question 20. A Smith number is a composite number, whose sum of the digits is equal to the sum of its
prime factors. For example:
4, 22, 27, 58, 85, 94, 121 ………. are Smith numbers.
Write a program in Java to enter a number and check whether it is a Smith number or not.
Sample Input: 666
Sum of the digits: 6 + 6 + 6 = 18
Prime factors are: 2, 3, 3, 37
Sum of the digits of the prime factors: 2 + 3 + 3 + (3 + 7) = 18
Thus, 666 is a Smith Number.

Question 21. A unique-digit integer is a positive integer (without leading zeros) with no duplicates digits.
For example: 7, 135, 214 are all unique-digit integers whereas 33, 3121, 300 are not. Given two positive
integers m and n, where m < n, write a program to determine how many unique-digit integers are there in the
range between m and n (both inclusive) and output them. The input contains two positive integers m and n.
Assume m < 30000 and n < 30000. You are to output the number of unique-digit integers in the specified
range along with their values in the format specified below:
Sample Input:
m = 100
n = 120
Sample Output:
The Unique-Digit integers are:
102, 103, 104, 105, 106, 107, 108, 109, 120.
Frequency of unique-digit integers is : 9
Sample Input:
m = 2500
n = 2550
Sample Output:
The Unique-Digit integers are:
2501, 2503, 2504, 2506, 2507, 2508, 2509, 2510, 2513, 2514, 2516, 2517, 2518, 2517, 2530, 2519, 2530,
2531, 2534, 2536, 2537, 2538, 2539, 2540, 2541, 2543, 2546, 2547, 2548, 2549.
Frequency of unique-digit integers is: 28.

Question 22. A Composite Magic number is a positive integer which is composite as well as a magic
number.
Composite number: A composite number is a number which has more than two factors.
For example:
Factors of 10 are: 1, 2, 5, 10
Magic number: A Magic number is a number in which the eventual sum of the digit is equal to 1.
For example: 28 = 2+8=10= 1+0=1
Accept two positive integers 'm' and 'n', where m is less than n. Display the number of composite magic
integers that are in the range between m and n (both inclusive) and output them along with frequency, in the
format specified below:
Sample Input:
m=10 n=100
Output: The composite magic numbers are 10,28,46,55,64,82,91,100
Frequency of composite magic numbers: 8
Sample Input:
m=120 n=90
Output: Invalid input

Question 23. Write a program in Java with the class name ‘Meter’ with the following data members and
member methods:
Data Members:
String nm: Name of the consumer.
int mn: Meter number.
long tel: Telephone number of the consumer.
int past: Previous meter reading.
int pre: Present meter reading.
int u: Units calculated.
double amt: Amount calculated.
Member methods:
void accept( ): A parameterized method to accept all the required values through main.
void compute( ): Calculate the amt as follows:
Units Rate/Unit
<=150 5.5/-
>150 to <=300 6.0/-
>300 to <=500 6.5/-
>500 7.0/-
Meter Rent 500/-
void display(): To print the output in the following format:
Name of the consumer :___________________________
Meter number :___________________________
Telephone number :___________________________
Number of units :___________________________
Amount payable :___________________________
Also write the main program.

Question 24. School is going to elect the College Captain for the year 2025 – 26. For which there are 3
candidates and number of voters is 7500. So write a program in Java with the class name ‘Election’
and the following data members and the member methods:
Data Members:
String n1, n2, n3: First name of all the candidates.
int c1, c2, c3 : the number of votes gained by each candidate.
Member Methods:
void input(String, String, String): A parameterized function to accept the names from main.
void count(): To calculate the votes gained by each candidate.
void result(): To print the name of the College Captain and vote gained by all 3 candidates.
Also write the main program.

Question 25. Write a program in Java using function overloading with the following function:
void area( double a, double b, double c): To calculate and print area of a triangle using Heron’s formula.
void area(int a, int b, int height): To calculate and print area of trapezium (1⁄2 height (a + b))
void area (double d1, double d2): To calculate and print the area of a rhombus ( 1⁄2 (d1 * d2)
where d1 and d2 are 2 diagonals.
Also write the main program.

Question 26. Write a program in Java with the class name overload with the following function
overloading methods:
void compute( int n1, int n2, char ch) : To accept the values for n1, n2 and if choice is + then print
n1+n2 otherwise print n1*n2.
void compute( int n, char ch) : To accept the value for n and if choice is ‘c’ then print square of n
else print the cube of n.
void compute(int n1, int n2, int n3): To accept three numbers and print total and average.
Also write the main program.

Question 27. Define class named BookFair with the following description:
Instance Variable/Data Members:
String bname: Stores the name of the book.
double price: Stores the price of the book.
Member Methods/Functions:
BookFair( ): Default constructor to initialize data members.
void input( ): To input and store the name and the price of the book.
void calculate( ): To calculate the price after discount. Discount is calculated based on the following criteria:
Price Discount
<=750 8%
>750 and <=2000 12%
>2000 20%
void display( ): To display the name and price of the book after discount.
Write main( ) to create an object of the class and call the above member methods.

Question 28. Define a class called Mobike with the following description:
Instance Variables/ Data Members:
int bno - to store the bike’s number.
String 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 rental charge.
Member Methods/Functions:
void input() - to input and store the detail of the customer.
void compute() - to compute the rental charge.
The rent for a bike is charged on the following rental basis:
First five days Rs. 500 per day.
Next five days Rs. 400 per day
Rest of the days Rs. 200 per day.
void display() - to display the details in the following format:
Bike No. Phone No. Name No. of days Charge
_______ ________ _________ ________ _______
Write main( ) to create an object of the class and call the above member methods.

Question 29. A class Merger concatenates two positive integers that are greater than 0 and produces a
newly merged integer.
Example: If the first number is 23 and the second is 764, then the concatenated number will be 23764.
Some of the members of the class are given below:
Class name: Merger
Data members/instance variables:
n1: long to store the first number.
n2: long to store the second number.
mergNum: long to store the merged number.
Member Functions/Methods:
Merger(): constructor to initialize the data members.
void readNum(): to accept the values of the data members n1 and n2.
void joinNum(): to concatenate the numbers n1 and n2 and store it in mergNum without using string
concept.
void show(): to display the original numbers and the merged number with appropriate messages.
Specify the class Merger giving the details of the constructor, void readNum(), void joinNum() and
void show().
Write main() method also to call the functions and execute the program.

Question 30. A class MySeries is declared to find the sum of the following series:
s = (1 * x2/1!) + (2 * x4/2!) + (3 * x6/3!) + (4 * x8/4!) + .............................. n terms.
Some of the members of the class are:
Class Name : MySeries
Data Members/Instance Variables:
x : integer as number.
n : integer as number of term of series.
p : integer to store power of ‘x’.
fact : integer to store factorial.
Member Functions/Methods:
MySeries() : Constructor to store appropriate values to data members.
void getNum() : To accept integer n(as number of terms) and x.
int getPower(int g, int h) : To find and return g raised to the power h.
int findFact(int y) : To find and return factorial of y.
long findSum() : To find and return sum of above series using getPower() and findFact().
Write main() method also to call the functions and execute the program.

You might also like