0% found this document useful (0 votes)
37 views151 pages

Computer Project 12th UPDATE

file

Uploaded by

Shashwat Yadav
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)
37 views151 pages

Computer Project 12th UPDATE

file

Uploaded by

Shashwat Yadav
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
You are on page 1/ 151

COMPUTER

PROJECT

2024-2025

Sarthak Bhagat XII-A 1


Submitted By: - Submitted to: -
Sarthak Bhagat Mr Sanjay Kumar Shah
XII-A
Index No: - 2254313/051

ACKNOWLEDGEMENT
I would like to express my special thanks of
gratitude to my teacher Mr. Sanjay Kumar
Shah as well as our principal Mrs. Bharti
Vishnoi, who gave me this opportunity to do
this wonderful project , which help me to
learn a lot in the research and course of
completion of the this project.

I am also indebted to my family and my


friends for their valuable support , advise

Sarthak Bhagat XII-A 2


and love which helped me to do this project
with the given time frame.

SARTHAK BHAGAT
CLASS- XII-A

Sarthak Bhagat XII-A 3


CERTIFICATE

This is to certify that the project entitled


“Different Programs of Academic Session"
Is prepared under my guidance and
supervision by :
Name:-Sarthak Bhagat
Index no:- 2254313/051
Class:- XII-A
Subject:- COMPUTER APPLICATION
SESSION 2024-2025

___________ ___________
Sarthak Bhagat XII-A 4
Signature of Signature of
Internal examiner External examiner

INDEX

Sno Name Remark


1. Different programs
2. Methods
3. Array

Sarthak Bhagat XII-A 5


4. String
5. Inheritance &
Interfaces
6. Recursion
7. Data Structure
8. Linked List

Sarthak Bhagat XII-A 6


Q1. An integer number whose digits are arranged in ascending order from left to right
is called an Increasing Number. At any position, the current digit is always greater than
or equal to the previous digit. For example, 1233, 13689, 112334566, etc. An integer
number whose digits are arranged in descending order from left to right is called a
Decreasing Number. Here the current digit is always less than or equal to the previous
digit. For example, 321, 88531, 8755321, etc. A positive integer where the digits are
neither in increasing nor decreasing order is called a Bouncy number. In other words, if
the digits of the number are unsorted then it is bouncy. For example, 123742, 101,
43682, etc. Design a program to accept a number (containing only digits 0 to 9) from the
user. For an invalid input, display an appropriate message. Check whether the number
is an increasing, decreasing or a bouncy number and display with an appropriate
message.

Sol. JAVA PROGRAM: -

Sarthak Bhagat XII-A 7


Sarthak Bhagat XII-A 8
Sarthak Bhagat XII-A 9
OUTPUT:-

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. a String To store num in String form
2. l Int To store length of the String
3. t int Used as a Testing Variable
4. i int Loop control Variable
5. j int Loop Control Variable
Sarthak Bhagat XII-A 10
6. num int Store the no to be checked
7. n int Store the no to be checked
8. c int To store the result

Q2 Write a program to determine how many Kaprekar numbers are there in the range
between 'p' and 'q' ( p and q are <1000) and output them also print the numbers.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 11


Sarthak Bhagat XII-A 12
OUTPUT: -

VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. a int To store the limit
2. b int To store the limit
3. i int Loop control Variable
4. j int Loop control variable
5 left int To store left part of number
6. right int To store right part of the number

Q3 Write a program to input an integer number and check the given number is a
‘Magic Number’ or not. A number is a magic number, if sum of all digits of the number
is equal to 1 and the number itself a single digit number.( i.e. keep adding the digits of
the number itself till it becomes a single digit number) If sum is one the number is a
magic number otherwise number is not a magic number. Example:- 55 = 5 + 5 =10,10 =
1 + 0 = 1 Hence, 55 is a magic number.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 13


Sarthak Bhagat XII-A 14
OUTPUT:-

Sarthak Bhagat XII-A 15


VARIABLE DESCRIPTION:
S.no VARIABLE TYPE USE
1. n int To store the number
2. x int To store the copy of the number
3. r int To store the digit
4. sum int To store the sum of digits

Q4 A program to check whether a number entered is a happy number or not. A happy


number is a number in which the eventual sum of the square of the digits of the number
is equal to 1.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 16


Sarthak Bhagat XII-A 17
OUTPUT: -
Ex1:- INPUT= 28

Ex2 : - INPUT= 78

VARIABLE DESCRIPTION: -
Sarthak Bhagat XII-A 18
S.no VARIABLE TYPE USE
1. n int To store the number
2. x int To store the copy of the number
3. sum int To store the sum of square of digits
4. r int To store the digit

Q5 Write a program which inputs a positive natural number N and Prints the possible
consecutive number combinations, which when added give N.

A positive natural number (for e.g. 27) can represented as follows: 2+3+4+5+6+7 =27 ,
8+9+40=27 , 13+14=27

Sarthak Bhagat XII-A 19


Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 20


OUTPUT: -

Sarthak Bhagat XII-A 21


VARIABLE DESCRIPTION:-
S.NO VARIABLE TYPE USE
1. a int To store the limit
2. b int To store the limit
3. c int To store number to be checked
4. i int Loop Control Variable
5. j int Loop Control Variable
6. n int To store the number
7. sum Int To store the sum

Q6 Write a program to accept a sentence which may be terminated by either ‘. ‘ or ?’ or


‘!’ only. Any other

character may be ignored. The words may be separated by more than one blank space
and are in UPPER

CASE. Perform the following tasks:

(a) Accept a sentence and remove all the extra blank space between two words to a
single blank space.

(b) Accept any word from the user along with its position and insert the word in the
given position. (The position is calculated by place value of each word where first word
is in position 1, second word in position 2 and so on).

c) Display the modified sentence

Sarthak Bhagat XII-A 22


Sarthak Bhagat XII-A 23
OUTPUT: -

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
Sarthak Bhagat XII-A 24
1. word String To store the word
2. sentence string To store the Sentence
3. position int To store the position
4. temporary int Temporary Variable

Q7 Write a program to declare a matrix A [ ] [ ] of order (M x 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.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 25


Sarthak Bhagat XII-A 26
Sarthak Bhagat XII-A 27
Sarthak Bhagat XII-A 28
OUTPUT:-

Sarthak Bhagat XII-A 29


Ex2:-

Sarthak Bhagat XII-A 30


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. m int To store the number of rows
2. n int To store the number of columns
3. Arr[][] int Matrix to store the Elements
4. i int Loop control Variable
5. j Int Loop control Variable
6. sum int To store the sum

Q8 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 are Doubly Markov
matrix

(i) All elements are greater than or equal to 0

(ii) Sum of each row is equal to 1.

(iii) Sum of each column is equal to 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.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 31


Sarthak Bhagat XII-A 32
Sarthak Bhagat XII-A 33
Sarthak Bhagat XII-A 34
Sarthak Bhagat XII-A 35
Sarthak Bhagat XII-A 36
Sarthak Bhagat XII-A 37
Sarthak Bhagat XII-A 38
Sarthak Bhagat XII-A 39
OUTPUT: -

VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. n int To store the size of array

Sarthak Bhagat XII-A 40


2. Arr[] int Array to store the elements
3. a int Formal Parameter
4. i int Loop Control Varaible
5. j int Loop Control Variable
6. SumR int Store the Sum of row
7. SumC int Store the Sum of Coloumn

Q9 Write a program to input any string find the shortest and the longest word present
in a sentence and print them along with their lengths.

Sol. Java Program

Sarthak Bhagat XII-A 41


Sarthak Bhagat XII-A 42
OUTPUT:-

VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. str String To store the String
2. word Sring To store the Word
3. Lword String To store the longest Word
4. sword String To store the shortest word
5. i int Loop Control Variable
6. len int To store the length of the String
7. ch char To store the character

Sarthak Bhagat XII-A 43


Q10 Write a program in java to find the difference between two matrices of the array
objects passed as parameter and store the difference in the current object (using void
calDiff( Array Ob1, Array Ob2) function and display the sum using void Display()
function of a class).

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 44


Sarthak Bhagat XII-A 45
Sarthak Bhagat XII-A 46
Sarthak Bhagat XII-A 47
Sarthak Bhagat XII-A 48
OUTPUT:-

Sarthak Bhagat XII-A 49


VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. rows int To store the number of rows
2. coloumns int To store the number of coloumns
3. Arr[][] int Matrix to store the elements
4. a int To store the number of rows
5. b int To store the number of coloumns
6. i int Loop Control Variable
7. j int Loop Control Variable

Q11 : Write a Java program to enter any number between 2 to 5( both inclusive) and
print all the unique combinations of the digits between 1 to that number. There should
be one blank space between each digit and each new combination should appear on
new line. Also display the total number of combinations formed for the given input.

Sarthak Bhagat XII-A 50


Sarthak Bhagat XII-A 51
OUTPUT:-

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. num1 int To store the first number
2. num2 int To store the second number

Sarthak Bhagat XII-A 52


3. maxDigit int To store the maximum of the two number
4. totalCombination int To store the total number of Combination
5. i int Loop Control Variable
6. j int Loop Control Variable

METHODS

Sarthak Bhagat XII-A 53


(CALL BY VALUE /
CALL BY
REFERENCE)

Q12 A class Adder has been defined to any two accepted Time.

Example: Time A: 6 Hours 35 minutes Time B: 7 Hours 45 minutes

Sarthak Bhagat XII-A 54


Their sum is: 14 hours 20 minutes(where 60 minutes = 1 hour)

The details of the members of the class are given below:

Class name : Adder

Data Members/Instance Variables

A[] : integer array to hold two elements(hours and


minutes)

Member functions/methods:

Adder( ) : constructor to assign 0 to the array elements

Void readTime() : to enter the elements of the Array

Void addTime(Adder X, Adder Y) : adds the time to the two parametrized objects X
and Y and stores the sum in the calling objects.

Void dispTime() : displays the array elements with an appropriate


message(i.e hours= ........... and minutes= .
...........)

Specify the class Adder giving the details of the constructor( ), void readTime(),void
addTime(Adder,Adder) and void dispTime().

Define the main() function to create objects and call the function accordingly to enable
the task.

Sarthak Bhagat XII-A 55


Sarthak Bhagat XII-A 56
OUTPUT: -

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. a[] int Array to store the time

Q13 A class Mixer has been defined to merge two sorted integer arrays in ascending
order. Some of the details of the class are given below:

Cass name: Mixer

Data members/instance variables:

int arr[ ] : to store the elements of an array

int n : to store the size of the array

Member functions/method:

Sarthak Bhagat XII-A 57


Mixer(int nn) : constructor to assign n=nn

void accept( ) : to accept the elements of the array in ascending order without any
duplicates

Mixer mix(Mixer A) : to merge the current object's array elements with the
parameterized array elements and return the resultant object

void display( ) :to display the elements of the array.

Specify the class Mixer, giving details of the constructor(int), void accept( ), Mixer

mix(Mixer) and void displav(). Define the main( ) function to create an object and call
the function accordingly to enable the task.

Sarthak Bhagat XII-A 58


Sarthak Bhagat XII-A 59
OUTPUT: -

VARIABLE DESCRIPTION:-

Sarthak Bhagat XII-A 60


S.no VARIABLE TYPE USE
1. arr[] int To store the elements of the Array
2. n int To store the size of the Array

Q14 A class Numbers contains the following data members and member functions to
check for triangular numbers. [A triangular number is formed by the addition ofa
consecutive sequence of integers starting from 1].

For example, 1+2 =3; 1+2 +3 =6; 1+2+3+4=10; 1+2+3+4+5=15

Therefore, 3, 6, 10, 15 etc. are triangular numbers.

Class name : Numbers

Data members/instance variables :

n : integers to be checked for whether it is triangular or not

Member function/methods

void getnum( ) :to accept integer n

int check(int) :to check if 'n' is triangular

void dispnum :to display message whether 'n' is triangular or not

Specify the class Numbers giving details of the functions void getnum( ), int check(int)
and void

dispnum(). The main function need not be written.

Sarthak Bhagat XII-A 61


Sarthak Bhagat XII-A 62
OUTPUT:-

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. n int To store the number
2. num int Formal Parameter
3. s int Counter Variable
4. mid int To store the mid term
5. i int Loop Control Variable

Sarthak Bhagat XII-A 63


RECURSION

Sarthak Bhagat XII-A 64


Q15. Write a Program to input a set of ‘n’ numbers (Ascending order) in a single
dimensional array. Enter a number and search whether the number is present among
the set of numbers or not by using binary search technique. If the number is present
then display a message “Element is present” otherwise, display “Element is not
present”. Perform the task by using Recursive Technique.

Sarthak Bhagat XII-A 65


Sarthak Bhagat XII-A 66
OUTPUT:-

VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. x[] int To store elements of array
2. l int To store Lower element
3. h int To store Upper Element
4. mid int To store the middle position
5. ele int Element to be searched

Sarthak Bhagat XII-A 67


6. f int Testing Variable
7. k int Element to be searched

Q16. The Factorial of a number is calculated as:

N! = n*(n-1)*(n-2)*-------------*1

A class Factorial is declared with the following details:

Class Name : Factorial

Data Members/Instance Variables:

n : to store a number(Integer type ) greater than zero

f : to store the factorial of a number entered by the


user

Member Functions/Methods:

Factorial() : a constructor to assign 0 to n

Int fact(int num) : to find and return the factorial of num(num>0)


using recursive technique otherwise, it should return
1 if num=0

Void get(int x) : to assign x to n and by invoking function fact()


store the factorial of n into f. Display the result with a
suitable message.

Write the main() method to create an object to class Factorial and call the functions
get(int).

Sarthak Bhagat XII-A 68


Sarthak Bhagat XII-A 69
OUTPUT: -

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. n int To store the number to find factorial
2. f int To store the factorial
3. m int To store the number
4. x int Formal Parameter

Q17 A Disarium number is a number in which the sum of digits to the power of their
respective position is equal to the number itself. Hence, 135 is a disarium number.

Design a class Disarium to check if a given number is a disarium number or not. Some
of the details of the class are given below:

Class Name : Disarium

Data Members/instance Variables:

Int num : stores the number

Int size : stores the size of the number

Member methods / Functions

Disarium(int nn) : Parametrized constructor to initialize the


data members n=nn and size= 0.

Sarthak Bhagat XII-A 70


Void countDigit() : count the total number of digits and assigns
it to size

Int sumofdigit(int n,int p) : returns the sum of the digits of the


number(n) to the power of their respective
positions (p) using recursive technique.
void check() : checks whether the number is a disarium
number and displays with
Appropriate.

Specify the class Disarium giving the details of the constructor(), void countDigit(), int
sumofDigits(int,int) and void check().Define the main Function to create an object and
call the functions accordingly to enable the task.

Sarthak Bhagat XII-A 71


OUTPUT: -

Sarthak Bhagat XII-A 72


VARIABLE DESCRIPTION: -
S. no VARIABLE TYPE USE
1. num int Data members to store number
2. size int To store the size
3. p int Store the value of num
4. sum int Store sum of the digits
5. no int store the user Input
6. nn int Formal Parameters

Q18 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 details 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 Function

Palin( ) : constructor to initialize data members with legal initial


values

Void accept( ) : to accept the number

Int reverse(int y) : reverses the parametrized argument ‘y’ and stores it in


‘revnum’ using recursive technique

Sarthak Bhagat XII-A 73


Void check( ) : checks whether the numbers is a palindrome or not by
invoking the function reverse() and display the result in 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.

Sarthak Bhagat XII-A 74


OUTPUT: -

Sarthak Bhagat XII-A 75


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. num int Store the entered number
2. revnum int Store the reverse of number
3. y int Formal Parameters

Q19 A class Prime_Series defines a recursive function to find the prime numbers from a
list of data. The details of the class are given below:

Class name : Prime_Series

Data Members/Instance Variables:

limit :To store the limit of the integers

Arr[] :To create an integer array(Maximum size 150)

Member Functions/Methods:

Prime_Series() : contructor to assign 0 to limit and arr[]

Void readList() : to accept the limit and input the integers in


array arr[] up to the limit.

Int isPrime(int q) : to check n is a prime or not, using recursion.


Technique. If prime then the function return 1
otherwise 0.

Void PrintPrime() : to display prime numbers from the array[] by


invoking int IsPrime() up to the given limit.

Sarthak Bhagat XII-A 76


Specify the class Prime_Series giving the details of the constructor, void readList(), int
IsPrime(int num,int j, int f) and void PrintPrime().

Sarthak Bhagat XII-A 77


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. arr[] int Array to store the numbers
2. limit int To store the size of the array
3. i int Loop Control Variable

Sarthak Bhagat XII-A 78


4. j int Loop Control Variable
5. num int To store the number to be checked

OUTPUT:-

Sarthak Bhagat XII-A 79


Sarthak Bhagat XII-A 80
Array
(Single and Double
Dimension)

Q20 Write a program in java to store 10 different numbers in a single Dimensional


Array. Display the numbers after eliminating the duplicate numbers from the array.

Sample Input:

M[0] M[1] M[2] M[3] M[4] M[5] M[6] M[7] M[8] M[9]
69 45 45 25 34 540 34 41 29 16

Sample Output: The result after removing duplicate numbers

Sarthak Bhagat XII-A 81


M[0] M[1] M[2] M[3] M[4] M[5] M[6] M[7]
69 45 25 34 40 41 29 16

Sarthak Bhagat XII-A 82


OUTPUT:-

Sarthak Bhagat XII-A 83


VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. i int Loop Control Variable
2. j int Loop Control Variable
3. a[] int Store the inserted elements in array
4. b[] int Store the new Array

Q21 Declare a square matrix A[][] of order MxN 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 from the user .Display an appropriate message for an invalid input .
Allow the user to input into this matrix , perform the following matrix .

Sarthak Bhagat XII-A 84


(a) Display the original Matrix

(b) Rotate the matrix 90 clockwise as shown below:

Sarthak Bhagat XII-A 85


OUTPUT: -

Sarthak Bhagat XII-A 86


VARIABLE DESCRIPTION: -
Sarthak Bhagat XII-A 87
S.no VARIABLE TYPE USE
1. a[][] int Matrix to store the numbers
2. i int Loop Control Variable
3. j int Loop Control Variable
4. m int To store the size of matrix
5. s int To store the sum of corners elements

Q22 Write a program to input long integer data not less than 5 digits . Your program
should reject , if data is less than 5 digits and ask to re-enter the value . In the input ,
last four digits will be taken as year (validity if the year should be checked that the year
should be in the range from 1900 to 3000 both inclusive , otherwise the computer should
reject the input and ask to re-enter data again) and remaining digits as total number of
days . your program should display the output as actual date(using number of days
extracted) followed by month name and actual year .

Test your program for the following data and some random data .

Sample input : 272008

Sample output: 27 January 2008

Sample input : 802005

Sample output: 21 March 2005

Sample input : 2008

Sample output: Invalid Data! Re-enter value not less than 5 digits

Sarthak Bhagat XII-A 88


Sarthak Bhagat XII-A 89
Sarthak Bhagat XII-A 90
OUTPUT:-

Sarthak Bhagat XII-A 91


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. month[] String Array to store month
2. dm[] int Array to store dates of month
3. i int Loop control Variable
4. j int Loop Control Variable
5. d int To store the date
6. c int Counter Variable
7. days int To store number of days
8. y int To store the year
9. date int To store the date of the month

Q23 A unique –digit number is a positive integer(without leading zeroes) and with no
duplicate digits . For example, 7,135,214 are all unique-digit integers whereas
33,3121,300 are not . Given two positive integers ‘a’ and ‘b’ ,write a program to
determine how many unique-digit integers are there in the range between ‘a’ and ‘b’
(both inclusive)and output them. The input contains two positive integers ‘a’ and ‘b’ .
Assume ‘a’<300 and ‘b’<500 . You are to find the number of unique-digits integers in
the specified range along with their values in the format specified below:

Sample Data:

Input m and n:

a=100 b=120

Output:

The unique-digit integers are: 102,103,104,105,106,107,108,109,120

Frequency of the unique-digit integer is : 9

Sarthak Bhagat XII-A 92


Sarthak Bhagat XII-A 93
OUTPUT:-

Sarthak Bhagat XII-A 94


VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. Ar1[] int Array to store the numbers
2. Ar2[] int Array to store the numbers
3. i int Loop control Variable
4. j int Loop Control Variable
5. m int Loop Control Variable
6. a int To store the limit
7. b int To store the limit
8. c int Increment Variable

Q24 Write a program to create a Double dimensional array of order [m] x [m] (where m
represents the number of rows and columns) to store integer numbers . Now , pass the
array to a method Diagonal() which calculates the sum of left and right diagonal
elements. Finally, display the elements of the original matrix and also the sum of left
and right diagonal elements.

Sol. Java Program

Sarthak Bhagat XII-A 95


Sarthak Bhagat XII-A 96
VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. m[][] int Matrix to store the numbers
2. re int To store the size of the matrix
3. i int Loop Control Variable
4. j int Loop Control Variable
5. ld int To store the sum of left diagnol
6. rd int To store the sum of right diagnol
7. k int Decrement variable

Sarthak Bhagat XII-A 97


OUTPUT: -

Sarthak Bhagat XII-A 98


STRING
Sarthak Bhagat XII-A 99
Q 25 Write a program to accept two words and check whether they are anagram or not.
The words that are made with the combination of letters present in the original word
are called anagram.

Sarthak Bhagat XII-A 100


Sarthak Bhagat XII-A 101
OUTPUT:-

VARIABLE DESCRIPTION:
S.no VARIABLE TYPE USE
1. p1 int To store the length of first word
2. p2 int To store the length of second word
3. i int Loop control Variable
4. j int Loop control Variable

Sarthak Bhagat XII-A 102


5. str1 String To store the first word
6. str2 String To store the second word
7. str3 String To store new word
8. str4 String To store new word

Q 26 The computer department of the International Criptological Agency is trying to


decode intercepted messages. The agency's spies have determined that the enemy
decodes messages by first converting all characters to their ASCII values and then
reversing the string.

For example, consider A - Z (the underscore is just to highlight the space).

The ASCIl values of A, < space >, z are 65, 32, 122 respectively. Concatenate them to get
6532122, then reverse this to get 2212356 as the coded message. Write a program which
reads a coded message and decodes it. The coded message will not exceed 200
characters. It will contain only alphabets (A ........Z and a.. z) and spaces. ASCII values
of A ......... Z are 65 90 and those of a ..........z are 97........122

Test your program for the following data and some random data.

Sample Data:

Input: Encoded Message

23121798623 1 0 19950 1 8723 5 623 101811792 7

Output: The Decoded Message:

Have A Nice Day

Sarthak Bhagat XII-A 103


Sarthak Bhagat XII-A 104
OUTPUT:-

VARIABLE DESCRIPTION:
S.no VARIABLE TYPE USE
1. l int To store length of word
2. k int Convert the strig to word

Sarthak Bhagat XII-A 105


3. i int Loop Control Variable
4. str1 String To store the String
5. str2 String To store the new Word
6. str3 String To store the new Word
7. str4 String To store the new sentence

INHERITANCE
&
Sarthak Bhagat XII-A 106
INTERFACES

Q27 Write a class Sentence to store a sentence and another class Duplicate to replace the
duplicate characters. The details of the classes are given below:

Class name: Sentence


Data members/instance variables
Str : To store a sentence in the string variable of protected type.
Member functions/methods
Sentence() :Constructor to assign string variable.
void Accept() : To accept a sentence in the variable str.
void Display() : To display the sentence after performing the task.
Class name :Duplicate
Data members/instance variables:
P :To store the length of sentence str.
Member functions/methods:
void removeDuplicate() : To remove the duplicate characters of each word in sequence
so that it should have only one occurrence. The new sentence should possess only one
space between two words, if it contains more spaces in the original string.

Sarthak Bhagat XII-A 107


For example, Ammmmiiit Kuulkkkkarnni iiiss aa sssttudddeentt of cccllassss
tttwweellvvvve
Output: Amit Kulkarni is a student of class twelve
(i) Specify the class Sentence giving the details of the function void Accept() and
Display().

(ii) Using the concept of inheritance, specify the class Duplicate giving the details of the
functions void removeDuplicate().

Sarthak Bhagat XII-A 108


Sarthak Bhagat XII-A 109
OUTPUT:

VARIABLE DESCRIPTION:

S no. Variable Type Use


1. str String To store the sentence
2. p int To store the length of sentence

Q28 Write a program by using class Employee to store the details of an employee and
another Class Overtime to calculate the amount paid for working more than the normal
working hours. The details of the classes are given below:

Class name : Employee

Data members/instance variables:

empc : To store employee code.

bpay : To store basic salary in double type.

Member functions/methods:

Employee() : Constructor to assign 0 to empc and bpay.

Employee (int c, double b) : Constructor to assign c to empc and 'b' to bpay

void Display() : To display empc and bpay after performing the task.

Sarthak Bhagat XII-A 110


Class name : Overtime

Data members/instance variables:

nd : To store number (int) of extra hours worked.

rate : To store rate (float) per hours.

Member functions/methods :

Overtime(int n, float r) : Constructor to assign 'n' to nd and 'r' to rate.

double Calculate() : paid for extra hours. To calculate gross salary (basic salary +
salary paid for extra hours)

void Show() : To display the amount paid for extra hours.

(i) Specify the classes Employee and Overtime by giving the details of the functions, void
Display() and void Show().

(ii) Using the concept of inheritance, specify the class Overtime giving the details of the
functions.

Sarthak Bhagat XII-A 111


Sarthak Bhagat XII-A 112
OUTPUT: -

VARIABLE DESCRIPTION:
Sarthak Bhagat XII-A 113
S.no Variable Type Use
1. empc Int To store employee code
2. bpay double To store basic salary in double type
3. nd Int Stores the numbers of extra hours
worked
4. Rate float To store rate per hours

Q29 Product has been defined to store the details of a product sold by a sealer to a
retailer. Define a sub class Sales to compute the total amount paid by the retailer with or
without fine along with service tax.

Some of the members of both the classes are given below:

Class name : Product

Data member/instance variables:

name : stores the name of the product

code :stores the name of the product

amount :to store the sale amount of the product code

member functions/methods:

Product (String n, int c, double p) : parameterized constructor to assign data


Members name=n, code=c and amount=p

void show( ) : displays the details of the data members.

Class name :Sales

Data member/instance variables:

Day : stores number of days taken to pay the sale amount

tax : to store the service tax (in decimals)

totamt :to store the total amount (in decimals)

Sarthak Bhagat XII-A 114


Member functions/methods:

Sales(...) :parameterized constructor to assign values to Data members of both the


classes.

void compute( ) : calculates the service tax @ 12.4% of the actual sale amount
calculates the fine @ 2.5%

of the actual sale amount only if the amount paid by the retailer to wholesaler exceeds
30 days.

Calculates the total amount paid by the retailer as (actual sale amount + service tax
+fine)

void show( ) : displays the data members of super class and the total amount.

Assume that the super class Product has been defined. Using the concept of
inheritance,specify the class Sales giving the details of the constructor(...), void
compute() and void show().

Sarthak Bhagat XII-A 115


OUTPUT: -

VARIABLE DESCRIPTION: -
S.No VARIABLE TYPE DESCRIPTION
1. Name String To store the name of product
2. code int To store the product code
3. amount Double To store the total sale amount of

Sarthak Bhagat XII-A 116


product
4. day Int To store the number of days
taken to pay sale amount
5. tax double To store service tax
6. totamt double To store Total amount

DATA
STRUCTURE
Sarthak Bhagat XII-A 117
(Stacks &
Queue)

Q30 Define a class Repeat which allows the user to add elements from one end(rear) and
remove elements from the other end(front) only.

The following details of the class repeat are given below:

Class Name : Repeat

Data Members/Instance variables

St[] : An Array to hold a maximum of 100


integer elements.

Cap : Stores the capacity of the Array

f : To point the index of the front


Sarthak Bhagat XII-A 118
r : To point the index of the rear.

Member function/Methods

Repeat (int m) : Constructor to initialize the data


members cap = m, f = 0 r = 0 and to create
the integer array.

void pushvalue (int v) : To add integers from the rear index


if possible else display the message
“OVERFLOW".

int popvalue() : To remove and return element from the


front.If array is empty then return -9999.

void display() : Displays the elements present in


the list.

(a) Specify the class Repeat giving the details of the constructor(int), member function
void pushvalue(int), int popvalue() and void disp().

Sarthak Bhagat XII-A 119


Sarthak Bhagat XII-A 120
Sarthak Bhagat XII-A 121
VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. st[] int Array to hold a max of 100 integers
2. cap int To store the capacity of the Array
3. f int To point the index of the front
4. r int To point the index of the rear
5. p int To store the length of word

Sarthak Bhagat XII-A 122


OUTPUT: -

Q31 A stack is a kind of data structure which can store elements with the restriction
that un element can be added or removed from the top only.

The details of the class Stack is given below.

Class name : Stack

Data Members/instance variables


Sarthak Bhagat XII-A 123
St[] : The array to hold the
names.

Size : The maximum capacity


of the string array

top : The index of the topmost stack

ctr : To count the number of elements


of stack.

Member functions/methods

Stack() : Default constructor.

Stack(int cap) : Constructor to initialize size = cap


and top= -1.

voidpushname(String n) : To push a name into the


stack. If the
stack is full, displays the message
“OVERFLOW".

String popnamel) : Removes a name from the top


of the stack and returns it.
If the stack is empty,
displays the message "UNDERFLOW”.

Void display() : Displays the element of the


stack.

Specify a class Stack giving details of the constructors(), void pushname(String n),
String popname() and void display().

Sarthak Bhagat XII-A 124


Sarthak Bhagat XII-A 125
Sarthak Bhagat XII-A 126
OUTPUT: -

Sarthak Bhagat XII-A 127


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. St[] String Array to store the name
2. size int Store the size of Array
3. top int Store the Top index
4. ctr int Store the number of elements
5. cap int Formal Parameters

Q32 Deque is an entity which can hold elements. The Deque data structure allows the
insertion and deletion of elements from both the ends(front and rear). The details of the
class are given below:

Sarthak Bhagat XII-A 128


Class Name : Deque

Data Members/Instance Variables:

Int Dq[] : To store integer elements of maximum size 200.

Int capc : To store Maximum capacity of the Array Dq[].

Int F : To point the index of front queue.

int R : To point the index of rear queue.

Member Functions/Methods

Deque( ) : Constructor to assign 0 to Dq[]

Deque(int c,int nf, int nr) : Constructor to assign ‘c’ to capc, nf to ‘F’ and nr to
‘R’ (nf gets a value –1 and nr gets a value -1).

Sarthak Bhagat XII-A 129


Sarthak Bhagat XII-A 130
Sarthak Bhagat XII-A 131
Sarthak Bhagat XII-A 132
Sarthak Bhagat XII-A 133
Sarthak Bhagat XII-A 134
OUTPUT: -

Sarthak Bhagat XII-A 135


VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. Dq[] int To store integer elements of max 200
2. capc int To store maximum capacity of array
3. F int To point the index of front queue
4. R int To point index of rear queue
Sarthak Bhagat XII-A 136
Q33 A Circular queue is a linear data structure which works on the principle of FIFO
enables the user to enter data from the rear end and remove data from the front end
with the rear end connected to the front end to form a circular pattern. Define a class
CirQueue with the following details:

Class name : CircularQueue

cql ] : array to store the integers

cap : stores the maximum capacity of the array

front : to point the index of the front end

rear : to point the index to the rear end

Members functions:

CirQueue (int max) : constructor to initialize the data member cap=max, front=0 and
rear=0

void push(int n) : to add integer in the queue from the rear end if possible,
otherwise display the message "QUEUE IS FULL"

int pop() : removes and return the integer from the end of the queue if any, else
returns -9999

void show( ) : display the queue element

Specify the class CirQueue giving details of the function void push(int) and int pop().
Assume that the other functions have been defined.The main function and algorithm
need NOT to be written.

Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 137


Sarthak Bhagat XII-A 138
Sarthak Bhagat XII-A 139
Sarthak Bhagat XII-A 140
Sarthak Bhagat XII-A 141
OUTPUT: -

VARIABLE DESCRIPTION: -
S.no VARIABLE TYPE USE
1. maxSize int To store maximum size
2. Array int To store queue
3. front int To store front end
4. rear int To store rear end`

Sarthak Bhagat XII-A 142


LINKED LIST

Sarthak Bhagat XII-A 143


Q34 Write a program to form a Singly linked list to form functions of insert , delete and
display the linked list.
Sol. JAVA PROGRAM

Sarthak Bhagat XII-A 144


Sarthak Bhagat XII-A 145
Sarthak Bhagat XII-A 146
Sarthak Bhagat XII-A 147
VARIABLE DESCRIPTION:-
S.no VARIABLE TYPE USE
1. info int Data to store int the node
2. next node Pointer to the next Node
3. head node Head of the List
4. newNode node Create a new Node
5. current node Start from the head

OUTPUT:-

Sarthak Bhagat XII-A 148


BIBLIOGRAPHY
Books used:-

1. APC COMPUTER APPLICATION CLASS XII


2. Computer Science with Java Class XII

WEBSITE USED:-
1. www.GeeksForGeeks.com
2. www.JavaTpoint.com
3. www.udemy.com

Sarthak Bhagat XII-A 149


Sarthak Bhagat XII-A 150

You might also like