0% found this document useful (0 votes)
126 views10 pages

Isc Computer Science 2024

The document is a solved paper for the ISC Class-12 Computer Science Board Examination for 2024, consisting of two parts: Part I with compulsory questions worth 20 marks and Part II with 50 marks where students must answer six questions from three sections. It includes various topics such as Boolean algebra, Java programming, and data structures, along with specific programming tasks and theoretical questions. Students are required to demonstrate their understanding of concepts through coding exercises and logical reasoning.
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)
126 views10 pages

Isc Computer Science 2024

The document is a solved paper for the ISC Class-12 Computer Science Board Examination for 2024, consisting of two parts: Part I with compulsory questions worth 20 marks and Part II with 50 marks where students must answer six questions from three sections. It includes various topics such as Boolean algebra, Java programming, and data structures, along with specific programming tasks and theoretical questions. Students are required to demonstrate their understanding of concepts through coding exercises and logical reasoning.
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/ 10

ISC BOARD EXAMINATION - 2024

COMPUTER SCIENCE
Solved Paper
Class-12th
Maximum Marks: 70
Time allowed: Three hours
(Candidates are allowed additional 15 minutes for only reading the paper. They must NOT start writing during this time.)
Answer all questions in Part I (compulsory) and six questions from Part-II, choosing two
questions from Section-A, two from Section-B and two from Section-C.
All working, including rough work, should be done on the same sheet as the rest of the answer.
The intended marks for questions or parts of questions are given in brackets [].
---------------------------------------------------------------------------------------------------------------------------------
PART I-20 MARKS (d) Assertion is false but Reason is true.
Answer all questions. (vii) State any one use of interfaces in Java. [1]
While answering questions in this Part, indicate briefly (viii) Write the cardinal form of the maxterm X + Y’ +Z
your working and reasoning, wherever required. (ix) Write the canonical SOP expression for F (A, B) = A
Question 1 <=> B [1]
(i) According to the Principle of duality, the Boolean (x) State any one difference between instance variable
equation (A+B’) • (A+1)= A + B’ will be equivalent and class variable. [1]
to: [1] Question 2
(a) (A’+B) • (A’+ 1) = A’ + B (i) Convert the following infix notation to postfix form.
(b) (A • B’)+(A • 0) = A • B’  [2]
(c) (A’ • B)+(A’ • 1) = A’ • B (P+Q•R-S)/T•U
(d) (A’ • B)+(A’ • 0) = A’ • B (ii) An array ARR [-5.....15, 10....20] stores elements
(ii) When a sequence of OR, NOT, NOR are connected in Row Major Wise with each element requiring 2
in series, the logic gate obtained is: [1] bytes of storage. Find the address of ARR [10] [15]
(a) AND (b) NOT when the base address is 2500. [2]
(c) OR (d) XOR (iii) The following function is a part of some class:
(iii) Idempotence Law states that: [1] int jolly(int[ ] x, int n, int m)
(a) X + X = X (b) X + X’ = 0 {
(c) X + X = 1 (d) X + X’ = X if (n < 0)
(iv) Assertion: For proposition ~A =>B its contrapositive return m;
is B=> ~ A [1] else if(n<x.length)
Reason: Contrapositive is the converse of inverse m= (x[n] > m) ?x[n]:m;
for any proposition. return jolly(x, - -n, m);
(a) Both Assertion and Reason are true, and Reason }
is the correct explanation for the Assertion. (a) What will be the output of jolly( ) when the
(b) Both Assertion and Reason are true, but Reason value of x[ ]= {6, 3, 4, 7, 1}, n = 4 and m = 0?[2]
is not the correct explanation for the Assertion. (b) What function does jolly() perform, apart from
(c) Assertion is true but Reason is false. recursion? [1]
(d) Assertion is false but Reason is true. (iv) The following function is a part of some class which
(v) The complement of the Boolean expression (P’ ⋅ Q) is used to find the smallest digit present in a number.
+ (R • S’) is: [1] There are some places in the code marked by ?1?,
(a) (P’ + Q) • (R’ + S) ?2?, ?3? which must be replaced by an expression / a
(b) (P + Q’) • (R’ + S) statement so that the function works correctly.
(c) (P’ + Q) • (R + S’) int small_dig(int n)
(d) (P + Q’) • (R + S’) { int min =? 1 ? ;
(vi) Assertion: Recursive data structure follows the while (n ! = 0)
LIFO principle. [1] {
Reason: Execution of recursive code follows the int q = n / 10
concepts of data structure Queue. int r =?2? * 10;
(a) Both Assertion and Reason are true, and Reason min = r > min ? 3 ? : r;
is the correct explanation for the Assertion. n = q;
(b) Both Assertion and Reason are true, but Reason }
is not the correct explanation for the Assertion. return min;
(c) Assertion is true but Reason is false. }
2 Oswaal ISC, COMPUTER SCIENCE, Class-XII

(a) What is the expression or statement at ?1? [1] Question 5


(b) What is the expression or statement at ?2? [1] (i) How is a decoder different from a multiplexer? Draw
(c) What is the expression or statement at ?3? [1] the logic circuit for 3:8 decoder (Octal decoder).
Which multiplexer can be derived from the Octal
PART II-50 MARKS decoder? [5]
Answer six questions in this part, choosing two questions from (ii) Draw the logic gate diagram for 2-input OR gate
Section A, two from Section B and two from Section C. using NAND gates only. Show the expression at
each step. [3]
SECTION-A
(iii) Write the canonical form of the cardinal terms, m3
Answer any two questions.
and M5 for F (A, B, C, D). [2]
Question 3
(i) To be recruited as the Principal in a renowned SECTION - B
College, a candidate must satisfy any one of the Answer any two questions.
following criteria: [5] Each program should be written in such a way that it clearly
• The candidate must be a Postgraduate and depicts the logic of the problem. This can be achieved by using
mnemonic names and comments in the program.
should either possess a B.Ed. degree or a teaching
experience of more than 15 years. (Flowcharts and Algorithms are not required.)
OR The programs must be written in Java.
• The candidate must be an employee of the same Question 6 [10]
college with a teaching experience of more than 15 Design a class DeciHex to accept a positive integer in
years. decimal number system from the user and display
OR its hexadecimal equivalent.
• The candidate must be a Postgraduate but not an Example 1: Decimal number = 25 Hexadecimal
employee of the same college and should have a equivalent = 19
teaching experience of more than 15 years. Example 2: Decimal number = 28 Hexadecimal
The inputs are: equivalent = 1C 1
Some of the members of the class are given below.
INPUTS
Class name : DeciHex
P Candidate is a Postgraduate Data members/instance variables:
S Candidate is an employee of the same College num : stores the positive integer
hexa :  string to store the hexadecimal
E Candidate has a teaching experience of more
equivalent of num
than 15 years
Methods/Member functions:
B Candidate possesses a B.Ed. degree DeciHex( ) :  constructor to initialise the data
members with legal initial values
(In all the above cases, 1 indicates yes and 0 indicates void getNum( ) : to accept a positive integer
no) void convert(int n) : to find the hexadecimal equivalent
Output: X Denotes eligibility of a candidate [1
of the formal parameter ‘n’ using
indicates eligibility and - 0 indicates ineligibility in
the recursive technique
all cases]
void display() :  to display the decimal number
Draw the truth table for the inputs and outputs
given above and write the SOP expression for X (P, and its hexadecimal equivalent by
S, E, B). invoking the function convert( )
(ii) Reduce the above expression X (P, S, E, B) by using Specify the class DeciHex giving details of the
4-variable Karnaugh map, showing the various constructor( ), void getNum( ), void convert(int) and
groups (i.e., octal, quads and pairs). void display( ). Define a main( ) function to create an
Draw the logic gate diagram for the reduced object and call all the functions accordingly to enable
expression. Assume that the variables and their the task.
complements are available as inputs. [5] Question 7 [10]
Question 4 class InsSort contains an array of integers which
(i) (a) Reduce the Boolean function F (A,B,C,D) = π (0, sorts the elements in a particular order.
2, 4, 6, 8, 9, 10, 11, 14) by using 4-variable Karnaugh Some of the members of the class are given below.
map, showing the various groups Class name : InsSort
(i.e., octal, quads and pairs). [4] Data members/instance variables:
(b) Draw the logic gate diagram for the reduced
arr[ ] : stores the array elements
expression. Assume that the variables and their
size : stores the number of elements in the
complements are available as inputs. [1]
array
(ii) Verify if the following proposition is a Tautology,
Contradiction or a Contingency, using a truth Methods/Member functions:
table. [3] InsSort(int s) : constructor to initialise size = s
((A=>B) ∧ (B=>C))=>(A=>C) void getArray() : accepts the array elements
(iii) Find the complement of the following expression void insertionSort() : sorts the elements of the array
and reduce it by using Boolean laws. [2] in descending order using the
P⋅(P+Q) ⋅ Q ⋅ (Q+R’) Insertion Sort technique
Solved Paper - 2024 3
double find() : calculates and returns the from the top of the card pile.
average of all The details of the class CardGame are given below.
indentation the odd numbers in the array Class name : CardGame
void display() : displays the elements of the
array in a sorted order along Data members/ instance variables:
with the average of all the cards[] : array to store integers as cards
odd numbers in the array by cap : to store the maximum capacity of
invoking the function find() array
with an appropriate message top : to store the index of the topmost
Specify the class InsSort giving details of the element of the array
constructor(), void getArray(), Void insertionSort(), Methods/Member functions:
double find() and void display(). Define a main()
function to create an object and call all the functions CardGame(int cc) : constructor to initialise cap =
accordingly to enable the task. cc and top=-1
Question 8 void addCard(int v) : to add the card at the top index
Design a class Coding to perform some string related if possible, otherwise display
operations on a word containing alphabets only. the “CARD PILE IS FULL”
Example: Input: “Java” 10 message
Output: Original word: Java int drawCard() : to remove and return the card
J = 74 from the top index of the card
a=97 pile, if any, else return the value
v = 118 -9999
a= 97 void display() : to display all the cards of card
Lowest ASCII code: 74 pile
Highest ASCII code: 118 (i) Specify the class CardGame giving details of the
Some of the members of the class are given below. functions void addCard(int) and int drawCard().
Class name : Coding Assume that the other functions have been defined.
Data members/instance variables:
The main() function and algorithm need NOT be
Wrd : stores the word
written.[4]
len : stores the length of the word
Methods/Member functions: (ii) Name the entity described above and state its
Coding() : constructor to initialise the principle. [1]
data members with legal initial Question 10
values A super class EmpSal has been defined to store the
void accept() : to accept a word details of an employee. Define a subclass Overtime
void find() : to display all the characters of to compute the total salary of the employee, after
‘wrd’ along with their ASCII adding the overtime amount based on the following
codes. Also display the lowest criteria.
ASCII code and the highest • If hours are more than 40, then ` 5000 are added to
ASCII code, in ‘wrd’ salary as an overtime amount.
void show() : to display the original word and
• If hours are between 30 and 40 (both inclusive), then
all the characters of ‘wrd’ along with their ASCII
`3000 are added to salary as an overtime amount.
codes. Also display the lowest ASCII code and
the highest ASCII code in ‘wrd’, by invoking the • If hours are less than 30, then the salary remains
function find( ) unchanged
Specify the class Coding giving details of the The details of the members of both the classes are
constructor(), void accept(), void find( ) and void given below.
show(). Define a main( ) function to create an object Class name EmpSal
and call all the functions accordingly to enable the task. Data members/instance variables:
SECTION - C empnum : to store the name of the employee
Answer any two questions. empcode : integer to store the employee code
Each program should be written in such a way that it clearly salary : to store the salary of the employee
depicts the logic of the problem stepwise . in decimal
This can be achieved by using comments in the program and
Methods/Member functions:
mnemonic names or pseudo codes for algorithms The programs
must be written in Java and the algorithms must be written in EmpSal(...) : parameterised constructor to
general standard form, wherever required/specified assign values to data members
(Flowcharts are not required.) void show() :  to display the details of the
Question 9 employee
CardGame is a game of mental skill, built on the Class name Overtime
simple premise of adding and removing the cards Data members/Instance variables:
4 Oswaal ISC, COMPUTER SCIENCE, Class-XII

hours : integer to store overtime in hours Question 11


totsal : to store the total salary in decimal (i) With the help of an example, briefly explain the
Methods/Member functions: dominant term in complexity. [2]
Overtime(...) : parameterised constructor to (ii) Answer the following questions based on the
assign values to data members of diagram of a Binary Tree given below:
both the classes A
void calSal() : calculates the total salary by
adding the overtime indentation
E H
amount to salary as per the criteria
given above
void show() : to display the employee details M L G
along with the total salary (salary
+ overtime amount)
F I C
Assume that the super class EmpSal has been defined.
Using the concept of inheritance, specify the class
Overtime giving the details of the constructor (...), (a) Name the external nodes of the tree. [1]
void calSal() and void show(). (b) State the degree of node M and node L. [1]
The super class, main function and algorithm need (c) Write the post-order traversal of the above tree
NOT be written. structure. [1]



ANSWERS
PART I (iv) Option (d) is correct.
Answer 1 Explanation: The contrapositive of a proposition
(i) Option (b) is correct. is formed by negating both the consequent (the
Explanation: Principle of Duality states that if we “then” part) and the antecedent (the “if ” part) and
have true Boolean postulates or equations then the then reversing their order. It is logically equivalent
dual of this statement equation is also true. to the original proposition.
Also to get dual of an expression following changes The contrapositive of the proposition ~A -> B is ~B
are done : -> A
+ to . (v) Option (b) is correct.
. to + Explanation: (P’Q + RS’)’
1 to 0 (P’Q)’ ∙ (RS’)’
0 to 1 (P”+Q’) ∙ (R’ + S”)
(ii) Option (c) is correct. (P+Q’) ∙ (R’+S)
Explanation: When you connect these gates in (vi) Option (b) is correct.
series, the output of one gate becomes the input of Explanation: Going with the implementation of
the next gate. stack , reverse strings etc. a recursive data structure
(A+B)’ = A’B’ follows the reverse order , last in first out.
(A’B’ +A’B’) ’= (A’B’)’= A+ B (vii) They are used to achieve abstraction,
However, you can analyze its behavior based on the polymorphism, and multiple inheritance.
operations of each gate: While getting the Cardinal form , the non
If the input to the OR gate is true (1), its output will complemented variables are written as 0 and the
be true (1). complemented variables are written as 1.
The NOT gate then negates this output, so it The binary combination formed is then converted
becomes false (0). to decimal equivalent.
Finally, the NOR gate receives false (0) as its input. (viii) (X + Y’ + Z): 010
Since both inputs are false (0), the NOR gate outputs Decimal Equivalent of binary pattern 010: 2
true (1). Hence, Cardinal form is M2
So, in this specific combination, the output would Cardinal form : If an expression is represented in its
be true only if the input to the OR gate is true. decimal equivalent of its terms.
(iii) Option (a) is correct. (ix) The canonical SOP expression for F(A,B) is:
Explanation: Idempotent Law – An input that is F(A,B)=A’∙B’+A∙B
AND´ed or OR´ed with itself is equal to that input · Cardinal form: If an expression is represented in its
e.g X+X= X , X.X =X decimal equivalent of its terms.
Solved Paper - 2024 5
A⇔B we first need to create a truth table for the (iii) (a) Output: 7
function: Explanation:
Given the array ‘x={ 6, 3, 4, 7, 1}`, `n= 4’, and ‘m=
A B F(A,B)
0 ’, let’s compute the output step by step:
0 0 1 1. `jolly(x, 4, 0) `:
0 1 0 • `n = 4`, SO `n <x.length` is true.
1 0 0 • `m = (x[4] > m) ? x[4]: m`, which is `m (1>0) ? 1
:0`,so`m` becomes ‘1’.
1 1 1 • Recursively call `jolly(x, 3, 1)’.
From the truth table, we can see that F(A, B) is true 2. `jolly(x, 3, 1)’:
(1) when either both A and B are false (0) or both A • ‘n = 3’, SO ‘n <x.length‘is true.
and B are true (1). • ‘m = (x[3] > m) ? x[3] : m’ , which is ‘m = (7>1) ? 7:
Now to construct the SOP expression, we take 1’, SO `m`becomes ‘7’.
the minterms (rows in the truth table where the • Recursively call ‘jolly(x, 2, 7)’ .
function is true) and negate them. Then, we tave 3. ‘jolly(x, 2, 7)’:
the product (AND) of these terms. • ‘n =2`, so ‘n< x. length’ is true.
The minterms for which F(A, B) =1 are m0 and m3: • ‘m= (x[2] > m) ? x [2] : m`, which is `m (4>7)?4: 7`,
• m0: A = 0,B =0, so the term A’∙B’. SO `m`remains ‘7’.
• m3: A = 1,B =1, so the term A∙B. • Recursively call ‘jolly(x, 1, 7)’.
(x) The main difference is that instance variables 4. ‘Jolly(x, 1, 7)’:
are unique to each instance of a class, while class • ‘n= 1’, so ‘n<x.length’ is true.
variables are shared among all instances of the class
• ‘m=(x[1] > m) ? x[1] : m’, which is `m = (3>7) ?3
and are associated with the class itself.
:7’, so ‘m’ remains ‘7’.
Answer 2
• Recursively call ‘jolly(x, 0,7)’.
(i) Postfix form: PQR*+S-T/U*
5. ‘jolly(x, 0, 7)’:
S No. Expression Stack Postfix • ‘n = 0, so ‘n < 0’ is false.
0 ( ( • ‘n <x.length’ is true.
• ‘m= (x[0] > m) ? x[0], which is ‘m (6>7) ?6 :7’, so ‘m’
1 P ( P remains ‘7’.
2 + (+ P • Recursively call ‘jolly(x, -1, 7)’ .
3 Q (+ PQ 6. ‘jolly(x, -1, 7)’:
• ‘n =-1, so ‘n <0’ is true, and it returns ‘m’, which is
4 * (+* PQ
‘7’.
5 R (+* PQR So, the output of the ‘jolly()’ function with the given
6 - (- PQR*+ parameters will be ‘7’.
7 S (- PQR*+S (b) T he jolly() function performs the task of finding
the maximum value in a given array x up to
8 ) PQR*+S- index n, while keeping track of the maximum
9 / / PQR*+S- value encountered so far in the parameter m.
10 T / PQR*+S-T (iv) (a) n%10
(b) q
11 * * PQR*+S-T/ (c) min
12 U * PQR*+S-T/U
SECTION-A
13 PQR*+S-T/U* Answer 3
(i)
(ii) Number or rows say M = (Ur – Lr) + 1 = [15 – (- 5)]
+1 = 21 P S E B X
Number or columns say N = (Uc – Lc) + 1 = [20 –
0 0 0 0 0
10)] +1 = 11
Row Major Wise Calculation 0 0 0 1 0
The given values are: B = 2500, W = 2 byte, I = 10, J 0 0 1 0 0
= 15, Lr = -5, Lc = 10, N = 11 0 0 1 1 0
Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + (
J – Lc ) ] 0 1 0 0 0
= 2500 + 2* [11 * (10 – (-5)) + (15 – 10)] 0 1 0 1 0
= 2500 + 2 * [11 * 15 + 5] 0 1 1 0 1
= 2500 + 2 * [165 + 5]
0 1 1 1 1
= 2500 + 340
= 2840 1 0 0 0 0
6 Oswaal ISC, COMPUTER SCIENCE, Class-XII

1 0 0 1 1 (i) (a)

1 0 1 0 1
1 0 1 1 1
1 1 0 0 0
1 1 0 1 1
1 1 1 0 1
1 1 1 1 1

SOP : X(P,S,E,B)= ∑(6,7,9,10,11,13,14,15)


        = m6+ m1+ m9+ m10+ m11+ m13+
m14+ m15 Logic Gate:
(ii) Quad1(M0 +M2 +M8 +M10)=B+D
Quad2(M8 +M9 +M11 +M10)=A’+B
Quad3(M2 +M6 +M14 +M10)= C’ + D
Pair1(M0 + M1)= A + C + D
Hence, F(A, B, C, D)=(B + D) ∙ (A’ + B) ∙ (C’+ D) ∙
(A+C+D)

Quad1(m6 +m7 +m14 +m15)=SE


Quad2(m9 +m11 +m13 +m15)=PB
Quad3(m10 +m11 +m14 +m15)= PE
Hence, X(P,S,E,B)=SE + PB + PE
Logic Gate: (B+D ).(A’+B).
( C’+D).(A+C+D)

SE + PB + PE

Answer 4 (ii)

A B C A=>B B=>C (A=>B)^(B=>C) A=>C ((A=>B)^(B=>C))=>(A=>C)


0 0 0 1 1 1 1 1
0 0 1 1 1 1 1 1
0 1 0 1 0 0 1 1
0 1 1 1 1 1 1 1
1 0 0 0 1 0 0 1
1 0 1 0 1 0 1 1
1 1 0 1 0 0 0 1
1 1 1 1 1 1 1 1
Hence, it is Tautology. 1. Multiplexers transmit data while decoders interpret
(iii) P∙(P+Q) ∙ Q∙ (Q + R’) coded data.
Taking complement: 2. Multiplexer is a device which consists of multiple
(P.(P+Q).Q.(Q+R’))’ input channels through a single line while decoders
=>P’+(P+Q)’ + Q’ +(Q+R’)’ consist of multiple inputs passing through multiple
=>P’ + P’Q’ + Q’ + Q’R output.
=>P’ (1+Q’) +Q’ (1+R) 3. Multiplexer converts inputs from unary codes
=>P’ +Q’ (initial) to binary codes while decoder converts
binary codes to inputs.
Answer 5
4. There is only 1 output lines in case of multiplexer. A
(i) Difference between decoder and multiplexer: decoder has 2n output lines.
Solved Paper - 2024 7
Logic Circuit for 3:8 Decoder: String strHex = “”;

// Constructor
public DeciHex()
{
num = 0;
hexa=””;
}

// Method to get the decimal number from the user


public void getNum()
{
Scanner scanner = new Scanner(System.in);
System.out.print(“Enter a decimal number:
“);
num = scanner.nextInt();
}

// Method to convert the decimal number to hexadecimal


public String convert(int n)
{
3 to 8 Decoder Circuit if (n != 0)
A multiplexer that can be derived from the Octal {
decoder is an 8-to-1 multiplexer. This multiplexer int t = n % 16;
has eight input lines (corresponding to the eight strHex = hexChar[t] + strHex;
output lines of the decoder) and three select lines n = n / 16;
(corresponding to the three input lines of the
convert(n);
decoder). The select lines control which input line is
forwarded to the output. }
(ii) return strHex
Desired gate
}
A + B = [(A + B)]’ involution
= [(A ∙ B)]’ DeMorgan’s // Method to display the decimal number
A+ B = [(A ∙ A)’ ∙ (B ∙ B)’]’ Idempotency public void display()
{
(A.A)' System.out.println(“Decimal number: “ +

num);
(A'.B')'= (A')' + (B')'=A+B
hexa=convert(num);
S y s t e m . o u t . p r i n t l n ( “ H e x a d e c i m a l
equivalent: “ + hexa);
(B.B)'
}
[(A ∙ A)’ ∙ (B ∙ B)’]’ = A + B
(iii) Canonical Form:
// Main method
m3= 0011 = A’B’CD
public static void main(String[] args)
M5 = 0101 = A+B’+C+D’
{
SECTION - B DeciHex obj = new DeciHex();
Answer 6 obj.getNum();
import java.util.Scanner; obj.display();
public class DeciHex obj.convert(num);
{ }
int num; }
String hexa; Answer 7
char[] hexChar = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’,’B’, import java.util.Scanner;
‘C’, ‘D’, ‘E’, ‘F’};
8 Oswaal ISC, COMPUTER SCIENCE, Class-XII

public class InsSort


{ // Method to display the array elements
double[] arr; public void display()
int size; {
System.out.println(“Sorted Array in Descending
// Constructor Order:”);
public InsSort(int capacity) { for (int i = 0; i < size; i++)
array = new double[capacity]; {
size = capacity; System.out.print(array[i] + “ “);
} }
System.out.println();
// Method to get the array elements from the user }
public void getArray()
{ // Main method
Scanner scanner = new Scanner(System.in); public static void main(String[] args)
System.out.println(“Enter the elements of the {
array:”); Scanner scanner = new Scanner(System.in);
for (int i = 0; i < size; i++) System.out.print(“Enter the size of the array: “);
{ int size = scanner.nextInt();
System.out.print(“Element “ + (i + 1) + “: “); InsSort obj = new InsSort(size);
array[i] = scanner.nextDouble(); obj.getArray();
size++; obj.insertionSort();
} obj.display();
} double average = obj.find();
 System.out.println(“Average of odd array
// Method to perform insertion sort in descending order elements: “ + average);
public void insertionSort() }
{ }
for (int i = 1; i <= size; i++) Answer 8
{ import java.util.Scanner;
double key = array[i];
int j = i - 1; public class Coding
while (j >= 0 && array[j] < key) {
{ String wrd;
array[j + 1] = array[j]; int len;
j = j - 1;
} // Constructor
array[j + 1] = key; public Coding()
} {
} wrd = “”;
len = 0;
// Method to find the average of the odd array elements }
public double find()
{ // Method to accept input word from the user
double sum = 0; public void accept()
for (int i = 0; i < size; i++) {
{ Scanner scanner = new Scanner(System.in);
if (array[i] %2!=0 ) System.out.print(“Enter a word containing
alphabets only: “);
sum += array[i];
wrd = scanner.next();
}
len = wrd.length();
return (sum / size);
}
}
Solved Paper - 2024 9
// Method to display all characters of the word along // Method to add a card to the top of the pile
with their ASCII codes public void addCard(int v)
public void find() {
{ if (top < cap - 1)
int lowest = Integer.MAX_VALUE; {
int highest = Integer.MIN_VALUE; top++;
System.out.println(“Original word: “ + wrd); cards[top] = v;
for (int i = 0; i < len; i++) System.out.println(“Card added
{ successfully.”);
char c = wrd.charAt(i); }
int ascii = (int) c; else
System.out.println(c + “ “ + ascii); {
lowest = Math.min(lowest, ascii);  System.out.println(“CARD PILE IS
highest = Math.max(highest, ascii); FULL”);
} }
System.out.println(“Lowest ASCII code: “ + }
lowest);
System.out.println(“Highest ASCII code: “ + // Method to draw a card from the top of the pile
highest); public int drawCard()
} {
if (top >= 0)
// Method to display the original word and all {
characters of the word along with their ASCII codes int card = cards[top];
public void show( ) top--;
{ return card;
find( ); // Invoking find( ) to display the original }
word and ASCII codes
else
}
{
System.out.println(“No card to draw.”);
// Main method
return -9999;
public static void main(String[] args)
}
{
}
Coding obj = new Coding();
//Method to display stack contents
obj.accept();
public void display()
obj.show();
{
}
int t=top;
}
if (t >= 0)
{
SECTION - C while (t>=0)
Answer 9
System.out.print(cards[t--] + “→”);
(i) public class CardGame
}
{
else
int[] cards;
System.out.println(“Stack empty”);
int cap;
}
int top;
}
(ii) Principle: The principle represented by this entity
// Constructor is the stack data structure principle. In a stack,
public CardGame(int cc) elements are added and removed from the top only,
{ following the Last In, First Out (LIFO) principle.
cap = cc; The addCard() function adds a card to the top of
the stack, while the drawCard() function removes
cards = new int[cap];
and returns the card from the top of the stack. The
top = -1; display() function displays all the cards in the stack,
} typically from top to bottom.
10 Oswaal ISC, COMPUTER SCIENCE, Class-XII

Answer 10 // Method to display employee details along with


public class Overtime extends EmpSal total salary
{ public void show()
int hours; {
double totsal;  super.show(); // Displaying employee
details from superclass
// Parameterized constructor  System.out.println(“Total Salary (with
overtime): Rs.” + totsal);
public Overtime(String empnum, int empcode,
double salary, int hours) }
{ }
super(empnum, empcode, salary); Answer 11
this.hours = hours; (i) The dominant term is the term that grows the
fastest. The dominant term in complexity is the
}
term that reflects the main factor determining the
algorithm’s performance.
// Method to calculate total salary including overtime For example, n² grows faster than n, so if we have
public void calSal() something like g(n) = n² + 5n + 6, it will be big
{ O(n²). If you have taken some calculus before,
if (hours > 40) this is very similar to the shortcut of finding limits
for fractional polynomials, where you only care
totsal = salary + 5000;
about the dominant term for numerators and
else if (hours <=40 && hours >= 30) denominators in the end.
totsal = salary + 3000; (ii) (a) External nodes: F, I, C, G
else (b) Degree of node M: 2 and L: 1
totsal = salary; (c) Post Order Traversal:
} F, I, M, E, C, L, G, H, A



You might also like