0% found this document useful (0 votes)
41 views

Class12Assignment2 24

Uploaded by

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

Class12Assignment2 24

Uploaded by

chill sings
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

BISHOP COTTON BOYS’ SCHOOL

COMPUTER SCIENCE
ASSIGNMENT
2024 – 2025
CLASS: 12
Date of Submission: First Week of October 2024
Question 1:
The result of a quiz competition is to be prepared as follows:
The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying
1 mark for the correct answer. Design a program to accept the number of participants N
such that N must be greater than 3 and less than 11. Create a double dimensional array of
size (Nx5) to store the answers of each participant row-wise.
Calculate the marks for each participant by matching the correct answer stored in a single
dimensional array of size 5. Display the scores for each participant and also the
participant(s) having the highest score.
Example: If the value of N = 4, then the array would be:
0.1 Q2 03 Q.4 Q.5

Participant I
Participant 2 A 13 9 C A
Participant 3 D A 0 C B
Participant 4 A A B AC
DC C AB

Key to the question: C C A B

Note: Array entries are line fed (i.e. one entry per line)
Test your program with the sample data and some random data: Example 1
INPUT: N = 5
Participant1 DABCC Participant2 AADCB Participant3
BACDB Participant4 DADCB Participant5 BCADD Key:
BCDAA
OUTPUT: Scores: Participant1 DABCC Participant1=0
Participant2=1
Participant3=1
Participant 4 = 3
Highest score: Participant) Participant 4
Example 3
INPUT: N = 12
OUTPUT: INPUT SIZE OUT OF RANGE.

Question 2:
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 sample data and some random data:
Example 1
INPUT: N = 726 .
OUTPUT: 48x15=720 6x1=6
Remaining boxes=0
Total number of boxes=726
Total number of cartons = 16
Example 2 INPUT: N = 140
OUTPUT: 48X2=96
24x1=24
12x1=12
6x1=6
Remaining boxes 2x1=2
Total number of oxes=140

Total number of cartons = 6


Example 3 INPUT: N = 4296
OUTPUT: INVALID LENGTH

Question 3:
Caesar Cipher is an encryption technique which is implemented as ROT13 ('rotate by 13
places'). It is a simple letter substitution cipher that replaces a letter with the letter 13 places
after it in the alphabets, with the other characters remaining unchanged.
ROT13
A/a B/b C/c D/d E/e F/f G/g H/h Ili J/j K/k L/1 M/m
ITT I TIT/IT I I 1
N/n 0/o P/p Q/q R/r S/s T/t U/u V/v W/w X/x Y/y Z/z
Write a program to accept a plain text of length L, where L must be greater than 3 and less
than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data:
Example 1
INPUT: Hello! How are you?
OUTPUT: The cipher text is:
Uryyb? Ubj ner lbh?
Example 2
INPUT: Encryption helps to secure data.
OUTPUT: The cipher text is:
Rapelcgvba urycf gb frpher qngn.
Example 3 INPUT: You
OUTPUT: INVALID LENGTH

Question 4:
Accept a paragraph of text consisting of sentences that are terminated by either '.' (full
stop), 'I' (exclamation mark) or a ' 7' (question mark). Assume that there can be maximum
10 sentences in a paragraph. Write a program to arrange the sentences in increasing order
of their number of words. Example:
INPUT: Please come and attend the party. Hello! How are you?
OUTPUT:
Hello=1
How are you=3
Please come and attend the party = 6

Question 5:
Write a program to declare a square matrix A[][] of order (M x M) where 'M' must be greater
than 3 and less than 10. Allow the user to input positive integers into this matrix. Perform the
following tasks on the matrix:
(a) Sort the boundary elements in descending order using any standard sorting technique and
rearrange them in the matrix.
(b)Calculate thesum of the boundary elements.
(c) Display the original matrix, rearranged matrix and sum of the boundary elements.
Test your program with the sample data and some random data:
Example 1
INPUT :M =4

9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
OUTPUT:
ORIGINAL
MATRIX
9 2 1 5
8 13 8 4
15 6 3 11
7 12 23 8
REARRANGED MATRIX
1
23 15 12
1
1 13 8
2 6 3
8
4 5 7
8

The sum of boundary elements is = 105

Question 6
Write a Program in Java to input a 2-D square matrix and check whether it is a
Scalar Matrix or not. A scalar matrix is a diagonal matrix in which the main
diagonals
all equal.
Example:
begin{bmatrix} 5 & 0 & 0 & 0 \\ 0 & 5 & 0 &0 0 &0 & 5 & 0 \\ 0 & 0 & 0 & 5
\end
The Matrix is :
5000
0500
0 0 5 0
0 0 0 5

Question 7:
Write a Program in Java to input a number and check whether it is a Keith Number
or not. Note: A Keith Number is an integer N with’d’ digits with the following
property:

If a Fibonacci-like sequence (in which each term in the sequence is the sum of the 'd' previous
terms) is formed, with the first 'd' terms being the decimal digits of the number N, then N
itself occurs as a term in the sequence.

For example, 197 is a Keith number since it generates the


sequence 1,9,7,17,33,57,107,197,

Some keith numbers are: 14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537..

Question 8
Write a program to input a list of integers in an array and arrange them in a way similar to the
to-and-fro movement of a Pendulum.
The minimum element out of the list of integers, must come in center position of array. The
number in the ascending order next to the’ minimum, goes to the left, the next higher
number goes to the right of minimum number and it continues. As higher numbers are
reached, one goes to either side of the minimum value in a to-and-fro manner similar to
that of a Pendulum.
Example:

INPUT —1 2 3 4 5
OUTPUT-5 3 1 2 4
INPUT- 11 12 3 14 5
OUTPUT-31 112 5 11 14

Question 9
Write a program to accept a sentence which may be terminated by either ‘’ ‘?’ or ‘!’ only. Any
other character ay be ignored. The words may be separated by more than one blank space and
are in UPPER CASE.’ Perform the following tasks:
(a) accept the sentence and reduce all the extra blank space between two words to a single
blank space. (b) Accept a word from the user which is part of the sentence along with its
position number and delete the word and display the sentence.
Test your program with the sample data and some random data:
Example 1 I
NPUT: A MORNING WALK IS AIS BLESSING FOR THE WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6
OUTPUT: A MORNING WALK IS A BLESSING FOR THE WHOLE DAY.
Example 2
INPUT: ASYOU SOW,SO SO YOU REAP
WORD TO BE DELETED: SO
WORD POSITION IN THE SENTENCE: 4
OUTPUT: AS YOU SOW, SO YOU REAP.
Example 3
INPUT: STUDY WELL ##.
OUTPUT: INVALID INPUT.

Question 10:
Given two positive numbers M and N, such that M is between 100 and 10000 and N is less
than 100. Find the smallest integer that is greater than M and whose digits add up to N.
For example, if M = 100 and N = 11, then the smallest integer greater than 100 whose digits
add up to 11 is 119.
Write a program to accept the numbers M and N from the user and print the smallest required
number whose sum of all its digits is equal to N. Also, print the total number of digits present
in the required number. The program should check for the validity of the inputs and display an
appropriate message for an invalid input.
Test your program with the sample data and some random data:
Example 1
INPUT: M=100 N=11
OUTPUT: The required number = 119
Total number of digits = 3
Example 2
INPUT: M= 1500 N=25
OUTPUT: The required number = 1699
Total number of digits = 4

Example 3
INPUT:
M = 99
N = 11
OUTPUT:
INVALID INPUT
Example 4
INPUT:
M = 112
N = 130
OUTPUT:
INVALID INPUT

Question 11:
Encryption is a technique of coding messages to maintain their secrecy. A String array of size
'n' where 'n' is greater than 1 and less than 10, stores single sentences (each sentence ends
with a full stop) in each row of the array.

Write a program to accept the size of the array. Display an appropriate message if the size
is not satisfying the given condition. Define a string array of the inputted size and fill it with
sentences row-wise. Change the sentence of the odd rows with an encryption of two characters
ahead of the original character. Also change the sentence of the even rows by storing the
sentence in reverse order. Display the encrypted sentences as per the sample data given
below.
Test your program on the sample data and some random data.
Input: n=4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.
IT IS COOL.

Output:
KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.

Input: n=13
Output: INVALID ENTRY

Question 12:
Design a program which accepts your date of birth in dd mm yyyy format. Check whether the
date entered is valid or not. If it is valid, display "VALID DATE", also compute and display the day
number of the year for the date of birth. If it is invalid, display "INVALID DATE" and then terminate
the program. Testing of the program
Input: Enter your date of birth in dd mm yyyy format
05
01

2010
Output: VALID DATE
5
Input: Enter your date of birth in dd mm yyyy format
03
04
2010
Output: VALID DATE
93
Input: Enter your date of birth in dd mm yyyy format
34
06
2010
Output: INVALID DATE
Question 13
What is an Ugly Number Series? Ugly Numbers are the ones whose prime
factors are 2,3 or 5 Only
So Ugly Number Series is 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, and so on...
The reason why1 is added is because of the old convention and mostly 1 is
added in many series may it
be a Fibonacci series.

Question 14:
Write a Program in Java to input a number and check whether it is an Evil
Number or not.
Evil Number: An Evil number is a positive whole number which has even
number of 1’s in its binary equivalent.
Example: Binary equivalent of 9 is 1001, which contains even number of 1's.
A few evil numbers are 3, 5, 6, 9...
Design a program to accept a positive whole number and find the binary
equivalent of the number and
Count the number of 1’s in it and display whether it is a Evil number or not
with an appropriate message.

Question 15:
Write a program to declare a square matrix A[] [] of order (M x M) where ‘WM’
is the number of rows and the number of columns such that M must be greater
than 2 and less than 10. Accept the value of M as user input. Display an
appropriate message for an invalid input. Allow the user to input integers into
This matrix.
Perform the following tasks:
(a) Display the original matrix.
(b) Check if the given matrix is Symmetric or not.
A square matrix is said to be Symmetric, if the element of the i” row and j
column is equal to the elements of the jth row and ith column.
(c) Find the sum of the elements of left diagonal and the sum of the elements
of right diagonal of the matrix and display them.
Test your program with the sample data and some random data:
Example 1
INPUT: M=3
1 2 3
2 4 5
3 5 6
Output
ORIGINAL MATRIX
1 2 3
2 4 5
3 5 6
THE GIVEN MATRIX IS
SYMMETRIC The sum of the left
diagonal = 11 The sum of the
right diagonal = 10 Example 2
INPUT: M = 4
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
OUTPUT
ORIGINAL MATRIX
7 8 9 2
4 5 6 3
8 5 3 1
7 6 4 2
THE GIVEN MATRIX IS NOT SYMMETRIC
The sum of the left diagonal = 17
The sum of the right diagonal = 20
Example 3
INPUT: M = 22
OUTPUT:
THE MATRIX SIZE IS OUT OF RANGE

Question 16:
Write a Program in Java to input a number and check whether it is a Keith Number
or not. Note: A Keith Number is an integer N with’d’ digits with the following
property:

If a Fibonacci-like sequence (in which each term in the sequence is the sum of the 'd' previous
terms) is formed, with the first 'd' terms being the decimal digits of the number N, then N
itself occurs as a term in the sequence.
For example, 197 is a Keith number since it generates the sequence
1, 9, 7, 17, 33, 57, 107, 197, ... .
Some Keith numbers are: 14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537_............

Question 17:
Write a program to input a word from the user and remove the consecutive repeated
characters by replacing the sequence cf repeated characters by its single occurrence
Example:
INPUT:Jaaavvvvvvvvaaaaaaaaaaa
OUTPUT — Java
IN PUT:Heeeiiiissggoiingg
OUTPUT— Heisgoing

Question 18:
A class Recursion has been defined to find the Fibonacci series up to a limit. Some of the
members of the class are given below:
Class Name: Recursion
Data Members/instance variables: a, b, c, limit (all integers)
Member functions/methods:
Recursion (): constructor to assign a,b,c with appropriate values.
void input() : to accept the limit of the series.
int fib(int n) : to return the nth Fibonacci term using recursive technique.
void genearate_fibseries() : to generate the Fibonacci series upto the given limit.
Specify the class Recursion giving details of the constructor, int fib() , void generate_fitiseries().
You may assume other functions are written for you and you need not write the main
function.

Question 19:
A class called Digi Number has been defined to find the frequency of each digit present in
a number and the sum &the digits.
Some of the members of the class
Digi Number
Are given below:
Class name: DigiNumberData members/instance variables:
num : long integer for storing the number
Member functions:
DigiNumber ( ):
Constructor to assign
0 to num
DigiNumber (long n):

parameterised constructor to assign


n to num
void digitfrequency( ) : find the frequency of each digit present in num and to display it long
sumDigits(long N) : to return the sum of the digits of the number stored in num using Recursive
Technique
void printsum( ) :
print sum of digits of num by invoking sumDigits(-)Specify the class
DigiNumber, giving details of the two Constructor arid functions
voiddigitfrequency( ), long sumDigits(long) and void printsum( ). Also write the main ( )
function to create an object and call the member function accordingly.

Question 20:
A class Collection contains an array of 100 integers. Using the following class description
create an array with common elements from two integer arrays. Some of the members of the
class are given below: Class name: CollectionData members/instance reliable:
arr[] : an array of 100 integers.
len : length of the array
Member functions/methods:
Collection( ) : default constructorCollection( int ) : parameterised constructor to assign the
length of arra yvoid readArray( ) : to accept array elements_Conection common(Collection) :
return the Collection containing the common elements of the current Collection object and the

Collection of objet passed as Parameter


void displayArray( ) : to display the array elements Specify the class Collection
Giving the details of the constructors and the given. You need not write the main function.

Question 21:

A word is considered elfish if it contains the letters: e, I, and f in it, in any order. For example,
we would say that the following words are elfish: whiteleaf, tasteful, unfriendly, and waffles,
because they each contain those letters. • Write a predicate function called elfish? That,
given a word, tells us if that word is elfish or not. • Write a more generalized predicate
function called x-ish? That, given two words, returns true if all the letters of the first
word are contained in the second. Use recursive method Question 21
A super class Record has been defined to store the names and ranks of 50 students.
Define a sub class Rank to find the highest rank along with the name. The details of both
classes are given below: Class name: Record
Data Members / instance variables:
name[ : to store the names of students
rnk[ ] : to store the ranks of students
Member functions:
Record() : constructor to initialize data members
void readvalues() : to store names and ranks
void display() : displays the names and the corresponding ranks
Class name: Rank
Data Members / instance variables:
index: integer to store the index of the topmost rank
Member functions
Rank (): constructor to invoke the base class constructor and to initialize index to 0.
void highest() : finds the index location of the topmost rank and stores it in index without
sorting the array 6
void display() : displays the name and ranks along with the name having the
topmost rank. Specify the class Record giving details of the constructor (), void ready-
alum°, void display (). Using the concept of inheritance, specify the class Rankgiving
details of constructor°, void
highest () and void display().
The main function and algorithm need not be written.

Question 22:
A super class Detail has been defined to store the details of a customer_ Define a
subclass Bill to compute the monthly telephone charge of the customer as per the
chart given below:
Number of Calls
1 100

101— 200
201— 300
Above 300
Rate
Only Rental charge
60 paisa per call + rental
charge 80 paisa per call +
rental charge 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:
Detail(...) : parameterized constructor to assign values to data members.
void show() : to display the detail 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:
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 charge given above.
void show() : to display the detail 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().
The main function has to be written.

Question 23:
Given a time in numbers we can convert it into words. For example:
5: 00 -- five o'clock
5: 10 ten minutes past five
--

5: 15 quarter past five


--

5: 30 -- half past five


5: 40 -- twenty minutes to six
5: 45 -- quarter to six
5: 47 thirteen minutes to six
--

Write a program which first inputs two integers, the first between 1 and 12 (both inclusive)
and second between 0 and 59 (both inclusive) and then prints out the time they represent,
in words.
Your program should follow the format of the examples above.

SAMPLE DATA:

1. INPUT:
TIME: 3, 0 OUTPUT: 3: 00 Three o' clock
2. INPUT:
TIME: 7, 29 OUTPUT: 7: 29 Twenty nine
minutes past seven
3. INPUT:
TIME: 6, 34 OUTPUT: 6: 34 Twenty six
minutes to seven
4. INPUT:
TIME: 12, 1
OUTPUT: 12: 01 One minute past Twelve
5. INPUT:
TIME: 12, 45
OUTPUT: 12: 45 Quarter to One
6. INPUT: TIME: 10, 59
OUTPUT: 10: 59 One minute to Eleven
7. INPUT: TIME: 14, 60
OUTPUT: Incorrect Input
Test your program for the data values given in the examples above and some random data.

Question 24:
A class Admission contain the admission numbers of 100 students. Some of the data members/
member functions are given below:
Class name: Admission
Data member/instance variable:
Adno[ ]: Integer array to store admission numbers
Member functions/methods:
Admission(): constructur to initialize the array elements
void fillArray(): to accept the element of the array in ascending order
int binSearch(int |, int u, int v): to search for a particular admission number(v) using binary search
and recursive technique and return 1 if found otherwise returns -1
Specify the class Admission giving details of the constructor, void fillArrray() and int binSearch(int,
int, int). Define the main() function to create an object and call the functions accordingly to enable
task.

Question 25:
A unique digit integer is a positive integer (without leading zeroes) with o duplicate digits.
For example 2,178,214 are all unique digit integers 55,9219,4001 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 print them. The input
contains two positive integers m and n. Assume m<50000 and n<50000. You are to display the
number of unique digit integers in the specified range along with their values in the format
specified below:
Sample data
Input 1:
m=100
n=120
Output:
The unique digit integers are:
102,103,104,105,106,107,108,109,120
Frequency of unique digit integers is = 9
Input 2:
m=250
n=2550
Output:
The unique digit integers are:
2501,2503,2506,2507,2508,2509,2510,2513,2514,2516,2517,2518,2519,2530,2531,2534,2536,2
537,2538,2539,2540,2541,2543,2546,2547,2548,2549,
Frequency of unique digit integers is = 27

You might also like