0% found this document useful (0 votes)
34 views58 pages

PROJECT1

The document outlines various programming tasks for students, focusing on different algorithms and data structures. Each program includes specific requirements, input examples, and expected outputs, covering topics such as pangrams, palindrome conversion, matrix operations, encryption techniques, ISBN validation, date calculations, and Goldbach numbers. The programs are designed for a computer practical course at AUXILIUM CONVENT SCHOOL for the academic year 2024-25.

Uploaded by

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

PROJECT1

The document outlines various programming tasks for students, focusing on different algorithms and data structures. Each program includes specific requirements, input examples, and expected outputs, covering topics such as pangrams, palindrome conversion, matrix operations, encryption techniques, ISBN validation, date calculations, and Goldbach numbers. The programs are designed for a computer practical course at AUXILIUM CONVENT SCHOOL for the academic year 2024-25.

Uploaded by

sourimaaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AUXILIUM CONVENT

SCHOOL
BANDEL
NAME: SAMPRITI BANK
CLASS: XI
SECTION: B
ROLL NO: 36
COMPUTER PRACTICAL
ACADEMIC YEAR: 2024-25
PROGRAM 1
1.Write a program to accept a sentence which may be terminated by either
‘.’, ‘?’ or ‘!’ only. The words may be separated by a single blank space and
should be case-sensitive.
Perform the following tasks:
(a) Determine if the accepted sentence is a Pangram or not. A Pangram is
a sentence that contains every letter of the alphabet at least
once. Example: “The quick brown fox jumps over the lazy dog.”
(b) Display the first occurring longest and shortest word in the accepted
sentence.
Test your program for the following data and some random data:
Example 1
INPUT: Pack my box with five dozen liquor jugs.
OUTPUT:
IT IS A PANGRAM
LONGEST WORD: liquor
SHORTEST WORD: my
Example 2
INPUT: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
OUTPUT:
IT IS A PANGRAM
LONGEST WORD: QUICK
SHORTEST WORD: THE
Example 3
INPUT: Hello my World.
OUTPUT:
IT IS NOT A PANGRAM
LONGEST WORD: Hello
SHORTEST WORD: my
Example 4
INPUT: Alas! it failed#
OUTPUT: INVALID INPUT
OUTPUT:
PROGRAM 2
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 4
INPUT:
YOU MUST BE CRAZY#
OUTPUT:
INVALID INPUT
OUTPUT
PROGRAM 3
Write a program to declare a matrix A[][] of order (M × N) where ‘M’ is the number of rows and
‘N’ is the number of columns such that both M and N must be greater than 2 and less than 10.
Allow the user to input integers into this matrix. Display appropriate error message for an invalid
input.
Perform the following tasks on the matrix:
(a) Display the input matrix.
(b) Rotate the matrix by 270° anticlockwise and display the resultant matrix.
(c) Calculate the sum of the odd elements of the matrix and display.
Test your program for the following data and some random data:
Example 1
INPUT:
M=3
N=4
ENTER ELEMENTS: 8, 7, 9, 3, -2, 0, 4, 5, 1, 3, 6, -4
OUTPUT:
ORIGINAL MATRIX
8 7 9 3
-2 0 4 5
1 3 6 -4
ROTATED MATRIX (270° ANTICLOCKWISE)
1 -2 8
3 0 7
6 4 9
-4 5 3
SUM OF THE ODD ELEMENTS = 28
Example 2
INPUT:
M=3
N=2
OUTPUT: INVALID INPUT
Example 3
INPUT:
M=2
N = 10
OUTPUT: INVALID INPUT
OUTPUT
PROGRAM 4
Write a program to declare a matrix A[][] of order (M × N) where ‘M’ is the number of
rows and ‘N’ is the number of columns such that both M and N must be greater than 2
and less than 10. Allow the user to input integers into this matrix. Display appropriate
error message for an invalid input.
Perform the following tasks on the matrix:
(a) Display the input matrix
(b) Create and display the mirror image matrix
(c) Calculate the sum of the four corner elements of the matrix and display
Test your program for the following data and some random data:
Example 1
INPUT:
M=3
N=4
8 7 9 3

-2 0 4 5

1 3 6 -4

OUTPUT:
ORIGINAL MATRIX
8 7 9 3

-2 0 4 5

1 3 6 -4

MIRROR MATRIX
3 9 7 8

5 4 0 -2

-4 6 3 1

SUM OF THE CORNER ELEMENTS = 8


Example 2
INPUT:
M=2
N = 10
OUTPUT:
INVALID INPUT
OUTPUT
PROGRAM 5
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 Matrix:
(i) All elements are >= 0
(ii) Sum of each row = 1
(iii) 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.
Test your program for the following data and some random data:
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
OUTPUT
PROGRAM 6
Write a program to declare a square matrix A[][] of order M × M where ‘M’ 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 said to be symmetric or not. A square matrix is said to be
symmetric, if the element of the ith row and jth column is equal to the element 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.
Example 1
INPUT:
M=3
Enter elements of the matrix:
123
245
356
OUTPUT:
ORIGINAL MATRIX
123
245
356
THE GIVEN MATRIX IS SYMMETRIC.
THE SUM OF THE LEFT DIAGONAL = 11
THE SUM OF THE RIGHT DIAGONAL = 10
Example 2
INPUT:
M=4
Enter elements of the matrix:
7892
4563
8531
7642
OUTPUT:
ORIGINAL MATRIX
7892
4563
8531
7642
THE GIVEN MATRIX IS NOT SYMMETRIC.
THE SUM OF THE LEFT DIAGONAL = 17
THE SUM OF THE RIGHT DIAGONAL = 20
OUTPUT
PROGRAM 7
Keyword cipher is a form of encryption technique. A keyword is used as the key, and it
determines the letter matching the cipher alphabet to the plain alphabet. Repeats of letters in
the word are removed, then the cipher alphabet is generated with the keyword matching A, B,
C, etc. until the keyword is used up, whereupon the rest of the cipher text letters are used in
alphabetical order, excluding those already used in the key.

Encryption:
The first line of input contains the keyword which you wish to enter. The second line of input
contains the string which you have to encrypt.

Plaintext A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Encrypte
d K R Y P T O S A B C D E F G H I J L M N Q U V W X Z
With KRYPTOS as the keyword, all As become Ks, all Bs become Rs, and so on.

Example:
Encrypting the message: KNOWLEDGE IS POWER when, keyword is KRYPTOS
Encrypted message: DGHVETPST BM IHVTL

Write a program to accept a coded text in uppercase and a keyword. Using the above technique
decrypt the text and display.

Note: All the messages are encoded in uppercase. Whitespace, special characters, and
numbers remains unchanged.

Test your program for the following inputs:

Example 1
INPUT:
ENTER KEYWORD: SECRET
ENTER TEXT TO BE DECODED: ZLJEFT DTOT
OUTPUT:
DECODED TEXT: ZOMBIE HERE
Example 2
INPUT:
ENTER KEYWORD: STAR WARS
ENTER TEXT TO BE DECODED: SPPSAG SP RSVJ
OUTPUT: DECODED TEXT: ATTACK AT DAWN
Example 3
INPUT:
ENTER KEYWORD: PLAYERS
ENTER TEXT TO BE DECODED: Haln de yokl
OUTPUT: INVALID TEXT
OUTPUT
PROGRAM 8
An ISBN (International Standard Book Number) is a ten-digit code which uniquely
identifies a book.
The first nine digits represent the Group, Publisher and Title of the book and the last
digit is used to check whether ISBN is correct or not.
Each of the first nine digits of the code can take a value between 0 and 9. Sometimes it
is necessary to make the last digit equal to ten; this is done by writing the last digit of
the code as X.
To verify an ISBN, calculate 10 times the first digit, plus 9 times the second digit, plus 8
times the third and so on until we add 1 time the last digit. If the final number leaves no
remainder when divided by 11, the code is a valid ISBN.
For example:
1. 0201103311 = 10 × 0 + 9 × 2 + 8 × 0 + 7 × 1 + 6 × 1 + 5 × 0 + 4 × 3 + 3 × 3 + 2 × 1 +
1 × 1 = 55
Since 55 leaves no remainder when divided by 11, hence it is a valid ISBN.
2. 00746254X = 10 × 0 + 9 × 0 + 8 × 7 + 7 × 4 + 6 × 6 + 5 × 2 + 4 × 5 + 3 × 4 + 2 × 2 +
1 × 10 = 176
Since 176 leaves no remainder when divided by 11, hence it is a valid ISBN.
3. 0112112425 = 10 × 0 + 9 × 1 + 8 × 1 + 7 × 2 + 6 × 1 + 5 × 1 + 4 × 2 + 3 × 4 + 2 × 2 +
1 × 5 = 71
Since 71 leaves remainder when divided by 11, hence it is not a valid ISBN.
Design a program to accept a ten digit code from the user. For an invalid input, display
an appropriate message. Verify the code for its validity in the format specified below:
Test your program with sample data and some random data.
Example 1
INPUT CODE: 0201530821
OUTPUT: SUM = 99
LEAVES NO REMAINDER – VALID ISBN CODE
Example 2
INPUT CODE: 035680324
OUTPUT: INVALID INPUT
Example 3
INPUT CODE: 0231428031
OUTPUT: SUM = 122
LEAVES REMAINDER – INVALID ISBN CODE
OUTPUT
PROGRAM 9
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: 2024
N = 25
OUTPUT:
ENTERED DATE: FEBRUARY 19, 2024
25 DAYS LATER: MARCH 15, 2024
Example 2
INPUT:
DAY NUMBER: 321
YEAR: 2024
N: 77
OUTPUT:
ENTERED DATE: NOVEMBER 16, 2024
77 DAYS LATER: FEBRUARY 1, 2025
Example 3
INPUT:
DAY NUMBER: 400
YEAR: 2024
N: 125
OUTPUT:
INCORRECT DAY NUMBER
INCORRECT VALUE OF ‘N’
OUTPUT
PROGRAM 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.
OUTPUT
PROGRAM 11
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
OUTPUT
PROGRAM 12
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.
Example: 1260 = 21 × 60 (where, 21 and 60 contain precisely all the digits of the number)
Thus, 1260 is a Vampire number.
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:
Test your program for the following data and some random data:
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
Example 3
INPUT:
m = 8105
N = 9999
OUTPUT:
THE VAMPIRE NUMBERS ARE:
NIL
FREQUENCY OF VAMPIRE NUMBER IS: 0
Example 4
INPUT:
m = 174
n = 4500
OUTPUT:
INVALID INPUT
OUTPUT
PROGRAM 13
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.
OUTPUT
PROGRAM 14
Hamming numbers are positive integers whose prime factors include 2, 3 and 5 only.
Example:
n = 6 is a hamming number as 6 = 2 × 3. So, its prime factors are limited to 2, 3.
n = 8 is a hamming number as 8 = 2 × 2 × 2 and it has only 2 as its prime factors.
n = 90 is a hamming number as 90 = 2 × 3 × 3 × 5 which has only 2, 3, 5 as prime
factors.
n = 14 is not a hamming number as 14 = 2 × 7. It has 7 as one of its prime factors.
n = 44 is not a hamming number as 44 = 2 × 2 × 11. It has 11 as one of its prime
factors.
Design a program to accept any positive integer number and check if it is a Hamming
number or not. Display the result with an appropriate message in the format specified
below. The program should also generate error message if a negative number is
entered.
Test your program for the following data and some random data:
Example 1
INPUT: Enter any number: 3600
OUTPUT: 3600 = 2 × 2 × 2 × 2 × 3 × 3 × 5 × 5
3600 IS A HAMMING NUMBER
Example 2
INPUT: Enter any number: 5832
OUTPUT: 5832 = 2 × 2 × 2 × 3 × 3 × 3 × 3 × 3 × 3
5832 IS A HAMMING NUMBER
Example 3
INPUT: Enter any number: 7854
OUTPUT: 7854 = 2 × 3 × 7 × 11 × 17
7854 IS NOT A HAMMING NUMBER
Example 4
INPUT: Enter a number: -120
OUTPUT: NEGATIVE NUMBER ENTERED. INVALID INPUT
OUTPUT
PROGRAM 15
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.
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 22 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
OUTPUT
PROGRAM 16
Write a program to check if a given string is an Anagram of another string.
Two strings are anagrams if they can be rearranged to form the same
thing. For example, “listen” and “silent” are anagrams.
Accept two strings from the user and check if they are anagrams of each
other. Ensure that the comparison is case-sensitive and ignores spaces.
Display an appropriate message based on whether they are anagrams or
not. If any of the strings contain invalid characters (e.g., numbers or special
characters), generate an error message.
Test your program with the following data and some random data:
Example 1
INPUT:
Enter first string: Listen
Enter second string: Silent
OUTPUT: STRINGS ARE ANAGRAMS
Example 2
INPUT:
Enter first string: Dormitory
Enter second string: Dirty room
OUTPUT: STRINGS ARE ANAGRAMS
Example 3
INPUT:
Enter first string: Hello
Enter second string: World
OUTPUT: STRINGS ARE NOT ANAGRAMS
Example 4
INPUT:
Enter first string: Test123
Enter second string: 321tset
OUTPUT: INVALID CHARACTERS IN STRING. INVALID INPUT.
OUTPUT

You might also like