Final_Assignment_2024-25_Class_XII
Final_Assignment_2024-25_Class_XII
Question 13 :
Write a program to create square matrix of order N whose maximum
size = 11. You are then required to fill the matrix by the value ranging
from 1 to N2; and then display the matrix on the screen.
For example-
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Now let the user input the value ‘V’ in range [1 - N2] and the order
‘M’ of the sub matrix ‘S’ that is to be created using the values
starting from the feeded value ‘V’ to right side.
For example
S = 18 19
23 24
If user enters V = 14 and order of sub matrix M = 3, then the sub matrix
formed
S = 14 15 11
19 20 16
24 25 21
Question 14 :
Write a program to declare a square matrix M[][] of order ‘N’. Check if
the matrix is a Doubly Markov matrix or not. A matrix which satisfies the
following conditions is Doubly Markov
All elements are >= 0 Sum
of each row = 1 Sum of
each column =1
Accept ‘N’ from the user where 3 <= N <= 9. Display an appropriate
error message if ‘N’ is not in the given range or the entered numbers are
negative. Allow the user to create a matrix and check whether the
created matrix is a Doubly Markov Matrix or not.
Example 1
INPUT: N = 3
Enter elements in the matrix: 0.5, 0.25, 0.25, 0.25, 0.75, 0.0, 0.25, 0.0,
0.75
OUTPUT: FORMED MATRIX
0.5 0.25 0.25
0.25 0.75 0.0
0.25 0.0 0.75
IT IS A DOUBLY MARKOV MATRIX
Example 2
INPUT: N = 3
Enter elements in the matrix: 1.5, 3, 0.15, 0.25, 4, 1.0, 0.25, 1.0, 3
OUTPUT: FORMED MATRIX
1.5 3 0.15
0.25 4 1.0
0.25 1.0 3
IT IS NOT A DOUBLY MARKOV MATRIX
Example 3
INPUT: N = 3
Enter elements in the matrix: 0.8, -4.0, 0.9, 3.5, 0.25, 0.25, 0.5, 0.0, 0.5
OUTPUT: NEGATIVE NUMBERS ENTERED. INVALID ENTRY
Example 4
INPUT: N = 12
OUTPUT: SIZE IS OUT OF RANGE. INVALID ENTRY
Question 15 :
A super class EmpSal has been defined to store the details of an
employee. Define a subclass Overtime to compute the total salary of
the employee, after adding the overtime amount based on the
following criteria.
If hours are more than 40, then ₹ 5000 are added to salary as an
overtime amount
If hours are between 30 and 40 (both inclusive), then ₹ 3000 are
added to salary as an overtime amount
If hours are less than 30, then the salary remains
unchanged The details of the members of both the
classes are given below.
Class name: EmpSal
Data members/instance variables:
empnum: to store the name of the employee
empcode: integer to store the employee
code salary: to store the salary of the
employee in decimal Methods/Member
functions:
EmpSal(…): parameterized constructor to assign values to data
members void show(): to display the details of the employee
Class name: Overtime
Data members/instance variables:
hours: integer to store overtime in
hours totsal: to store the total salary
in decimal Methods/Member
functions:
Overtime(…): parameterized constructor to assign values to data
members of both the classes
void calSal(): calculates the total salary by adding the overtime
amount to salary as per the criteria given above
void show(): to display the employee details along with the total
salary (salary + overtime amount)
Assume that the super class EmpSal has been defined. Using the
concept of inheritance, specify the class Overtime giving the details of
the constructor(…), void calSal() and void show().
The super class, main() function and algorithm need not be written.
Question 16 :
Write a program to declare a square matrix M[][] of order (N × N)
where ‘N’ 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 ascending order using any standard
sorting technique and rearrange them in the matrix in clockwise
manner.
(b) Calculate the product of the non-boundary elements.
(c) Display the original matrix, rearranged matrix and only the non-
boundary elements of the rearranged matrix with their product.
Test your program for the following data and some random data:
Example 1
INPUT: N = 4
11 2 5 7
8 10 9 4
15 5 3 11
1 17 14 8
Output: Original Matrix
11 2 5 7
8 10 9 4
15 5 3 11
1 17 14 8
Rearranged Matrix
1 2 4 5
17 10 9 7
15 5 3 8
14 11 11 8
Non-Boundary Elements
10 9
5 3
PRODUCT OF THE NON-BOUNDARY ELEMENTS = 1350
Question 17 :
A Vampire number is a composite natural number with an even
number of digits that can be factored into two natural numbers each
with half as many digits as the original number and not both with
trailing zeros, where the two factors contain precisely all the digits of
the original number, in any order of counting multiplicity.
Accept two positive integers m and n, where m < n and values of both
‘m’ and ‘n’ must be >= 1000 and <= 9999 as user input. Display all
Vampire numbers that are in the range between m and n (both
inclusive) and output them along with the frequency, in the format
specified below:
Example 1
INPUT:
m = 1002
n = 1640
OUTPUT:
THE VAMPIRE NUMBERS ARE:
1260 1395 1435 1530
FREQUENCY OF VAMPIRE
NUMBER IS: 4
Example 2
INPUT: m = 1810 n = 7800
OUTPUT:
THE VAMPIRE NUMBERS ARE:
1827 2187 6880
FREQUENCY OF VAMPIRE NUMBER IS: 3
Question 18 :
Write a program in Java to accept day number (between 1 and 366)
and year
(yyyy) from the user and display the corresponding date. Also accept
‘N’ from the user where 1 <= N <= 100) to compute and display the
future date ‘N’ days after the given date. Display error message if the
value of the day number or ‘N’ are not within the limit. Day number is
calculated taking 1st January of the given year as 1.
Test your program with given set of data and some random data.
Example 1
INPUT: DAY NUMBER: 50
YEAR: 2023
N: 25
OUTPUT: ENTERED DATE: FEBRUARY 19, 2023
25 DAYS LATER: MARCH 16, 2023
Example 2
INPUT: DAY NUMBER: 321
YEAR: 2023
N: 77
OUTPUT: ENTERED DATE: NOVEMBER 17, 2023
77 DAYS LATER: FEBRUARY 2, 2024
Question 19 :
A snowball string is a sentence where each word is arranged in
ascending order of their length and is also consecutive.
Example 1
INPUT: He may give bonus.
OUTOUT: IT IS A SNOWBALL STRING
Example 2
INPUT: Is the cold water frozen?
OUTPUT: IT IS A SNOWBALL STRING
Question 20 :
Write a program to declare a square matrix M[][] of order ‘N’ where
‘N’ must be greater than 3 and less than 10. Accept the value of N as
user input. Display an appropriate message for an invalid input. Allow
the user to accept three different characters from the keyboard and
fill the matrix according to the instruction given below:
(i) Fill the four corners of the square matrix by character 1
(ii) Fill the boundary elements of the matrix (except the four corners)
by character 2
(iii) Fill the non-boundary elements of the matrix by character 3
(iv) Display the matrix formed by the above instructions
Test your program for the following data and some
random data: Example 1 INPUT:
N=4
Enter first character: @
Enter second character :
?
Enter third character: #
OUTPUT:
Formed Matrix:
@ ? ? @
? # # ?
? # # ?
@ ? ? @
Question 21 :
Question 22 :
Louise joined a social networking site to stay in touch with her
friends. The signup page required her to input a name and a
password. However, the password must be strong. The website
considers a password to be strong if it satisfies the following criteria:
She typed a random string of length n in the password field but wasn't sure
if it was strong. Given the string she typed, can you find the minimum
number of characters she must add to make her password strong?
Example
Password : ‘2bbbb’
This password is 5 characters long and is missing an uppercase and a
special character. The minimum number of characters to add is 2.
Password : ‘2bb#A’
This password is 5 characters long and has at least one of each character
type. The minimum number of characters to add is 1.
Question 23 :
Julius Caesar protected his confidential information by encrypting it using a
cipher. Caesar's cipher shifts each letter by a number of letters. If the shift
takes you past the end of the alphabet, just rotate back to the front of the
alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b
and c.
Sample Input:
11
middle-Outz
2
Sample Output:
okffng-Qwvb
Question 24 :
Given a square matrix, calculate the absolute difference between the sums
of its diagonals.
For example, the square matrix arr is shown below:
Example 1:
1 2 3
4 5 6
9 8 9
The left to right diagonal = 1+5+9 = 15
The right to left diagonal = 3+5+9 = 17
Absolute difference = | 15 – 17| = 2
Question 25 :
Given five positive integers, find the minimum and maximum values that
can be calculated by summing exactly four of the five integers. Then print
the respective minimum and maximum values as a single line of two space-
separated long integers. Example :
Input : 1 2 3 4 5
Output : 10 14
Explanation The numbers are 1,2 ,3, 4, and 5. Calculate the following sums
using four of the five integers:
1. Sum everything except 1, the sum is 2+3+4+5=14.
2. Sum everything except 2, the sum is 1+3+4+5=13.
3. Sum everything except 3, the sum is 1+2+4+5=12.
4. Sum everything except 4, the sum is 1+2+3+5=11.
5. Sum everything except 5, the sum is 1+2+3+4=10.