[go: up one dir, main page]

0% found this document useful (0 votes)
144 views54 pages

CFQ ISC Computer Science XII (1)

The document outlines the shift towards competency-based education in India, particularly by the Council for the Indian School Certificate Examinations (CISCE), which aims to enhance critical thinking and problem-solving skills among students. It introduces an Item Bank of Competency-Focused Practice Questions for ICSE and ISC levels, designed to aid teachers and students in preparing for higher-order thinking questions in upcoming board examinations. The document includes various types of questions and emphasizes the importance of these resources in developing individual learning pathways.
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)
144 views54 pages

CFQ ISC Computer Science XII (1)

The document outlines the shift towards competency-based education in India, particularly by the Council for the Indian School Certificate Examinations (CISCE), which aims to enhance critical thinking and problem-solving skills among students. It introduces an Item Bank of Competency-Focused Practice Questions for ICSE and ISC levels, designed to aid teachers and students in preparing for higher-order thinking questions in upcoming board examinations. The document includes various types of questions and emphasizes the importance of these resources in developing individual learning pathways.
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/ 54

0

PREFACE

With a growing emphasis on competency-based education globally, the educational landscape


in India has also steered towards high-quality learning experiences that allow learners to
incorporate critical thinking and problem-solving approaches. This approach goes beyond
rote memorisation and focuses on developing the skills and knowledge that students need to
apply in their real-world scenarios.
The Council for the Indian School Certificate Examinations (CISCE), as a national-level
progressive examination board, has taken several steps to infuse competency-based education
in CISCE schools through teacher capacity-building on item development for competency-
based assessments and the incorporation of competency-focused questions at the ICSE and
ISC levels from the examination year 2024.
To further facilitate the adoption of competency-based assessment practices in schools and to
support teachers and students towards the preparation for attempting higher-order thinking
questions in future board examinations, Item Banks of Competency-Focused Practice
Questions for selected subjects at the ICSE and ISC levels have been developed. This Item
Bank consists of a rich variety of questions, both objective and subjective in categories,
aimed at enhancing the subject-specific critical and analytical thinking skills of the students.
In this Item Bank, each question is accompanied by the topic and cognitive learning domain/s
that it intends to capture. The cognitive domains reflected in these questions include
understanding, analysis, application, evaluation and creativity, along with some questions of
the higher-order recall domain. The Answer Key at the end presents the possible answers to a
given question, but it is neither limiting nor exhaustive.
These practice questions are also meant to serve as teacher resources for classroom
assignments and as samplers to develop their own repository of competency-focused
questions. Apart from offering a good practice of higher-order thinking skills, engaging with
these questions would allow students to gauge their own subject competencies and use these
assessments for learning to develop individual learning pathways.
During the development of this Item Bank, a large pool of questions was prepared by a team
of experienced CISCE teachers. The questions that were finalised by the internal and external
reviewers as being higher-order competency-focused questions have been collated in this
item bank.
I acknowledge and appreciate all the ICSE and the ISC subject matter experts who have
contributed to the development and review of these high-quality competency-focused
questions for CISCE students.
We are hopeful that teachers and students will utilise these questions to support their
teaching-learning processes.

August 2024 Dr. Joseph Emmanuel


Chief Executive &
Secretary CISCE
Computer Science ISC-Class XII

Table of Contents

S.No. Types of Questions Page Nos.

I. Multiple Choice Questions (MCQs) 1-7

II. Assertion-Reason Questions 8-9

III. Very Short Answer Questions 10-14

IV. Short Answer Questions 15-19

V. Long Answer Questions 20-27

VI. Very Long Answer Questions 28-32

Answer Key 33-50

ISC Competency-Focused Practice


Computer ISC-Class
COMPETENCY-FOCUSED PRACTICE QUESTIONS

ISC-CLASS XII

Computer Science

I: Multiple Choice Questions (1 Mark


Please select ONE correct answer from the following options provided in MCQs.
S.No. Questions

1. [Scope]
For the given code snippet:

int i;
for( i = 5; i>=1; i--)
System.out.println( );
System.out.println(i);

(a) Zero will be displayed as variable i has local scope with respect to the loop.
(b) Zero will be displayed as variable i has global scope with respect to the loop.
(c) Error – Undeclared variable i.
(d) Output will be 1. (Analysis)

2. [StringBuffer]
m and n are two StringBuffer objects. The method call, m.append(n)will:

(a) mutate object m.


(b) mutate object n.
(c) mutate both the objects m and n.
(d) .append( ) is an accessor method so it cannot mutate any object. (Application)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions

3. [StringBuffer]
The code snippet given below will result in:

StringBuffer x= new StringBuffer("Hello");


StringBuffer y= new StringBuffer("HELLO");
System.out.println(x.equalsIgnoreCase(y));

(a) boolean value false


(b) boolean value true
(c) undeclared method equalsIgnoreCase(…)
(d) String literals mismatch. (Evaluate)

4. [Recursion]
Recursion takes toll on memory. Which of the following option is the reason for it?
(a) Every recursive call is placed in a call stack memory.
(b) Every recursive call is resolved in Last-In-First-Out (LIFO) manner.
(c) Values of local variables are maintained until each of the calls are resolved.
(d) All of the above. (Understanding)

5. [Recursion]
If binary search technique uses recursion instead of iteration, the code:
i. will contain two base cases.
ii. will contain two recursive cases.
iii. when executed will lead to an exception, stack overflow.
Which of the above is valid?
(a) i and ii
(b) ii and iii
(c) i and iii
(d) Only iii (Evaluate)

6. [Arrays]
Assume int [ ] [ ] x = { {8,9} , {5,6,7},{1,2,3,4}}, what are x[0].length, x[1].length, and
x[2].length ?
(a) 2, 3 and 3
(b) 2, 3 and 4
(c) 3, 3 and 3
(d) 2, 2 and 2 (Application)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

7. [Arrays, Strings]

Passwords are stored as two Strings-one is the user entered password saved in
StringA, the other is a password stored by the system in StringB.

If StringA must be checked with StringB, for validity, which one of the following
String functions are needed to be used?
(a) charAt( )
(b) equals( )
(c) equalsIgnoreCase( )
(d) startsWith( ) (Understanding)

8. [Arrays]
What is the outcome of the following code snippet:
public class Test
{
public static void main( )
{
char [ ][ ] matrix = {{'a','b','c'},{'p','q','r'},{'x','y','z'}};
for( int i=0 ; i<3 ; i++)
System.out.print( matrix[i] [1] + " " );
}
}
(a) a b c
(b) a p x
(c) p q r
(d) b q y (Analysis)

ISC Competency-Focused Practice 3


Computer ISC-Class

S.No. Questions

9. [Strings]
For the following code snippet choose the correct output:
int x =234;
String str= String.valueOf(x) ;
System.out.println(str.length( ));
System.out.println( x + x );
System.out.println( str + str );

a. b. c. d.

(Analysis)

10. [Object Oriented Programming]


Software developers of Banayan High School have created a class to store the name,
age and height of students. If the class shown below compiles correctly, which of the
following will be the correct statement to create an object and pass values as an
argument?
class StudentBanyan
{
String name;
int age;
double height;
StudentBanyan(String n, int a, double h)
{
name = n;
age = a;
height = h;
}
//implementation not shown here
}
Which one of the following is the correct statement of using a constructor?
(a) StudentBanyan stud1 = new StudentBanyan("Kylin",5.6, 23);
(b) StudentBanyan stud1 = new StudentBanyan("Kylin",23, 5.6);
(c) StudentBanyan stud1 = new StudentBanyan(5.6, "Kylin",23);
(d) StudentPine stud1 = new StudentPine(5.6, 23, "Kylin");
(Analysis)

ISC Competency-Focused Practice 4


Computer ISC-Class

S.No. Questions

11. [Object Oriented Programming]


Which of the following statements are valid for static member methods of a class?
I. They can access static as well as non-static data members.
II. They can call non-static member methods.
III. They cannot refer to this or super.
(a) I and II
(b) II and III
(c) I and III
(d) Only III (Analysis)

12. [Object Oriented Programming]


Which one of the following keywords will make the data member as a class variable?
(a) static
(b) final
(c) abstract
(d) public (Recall)

13. [Object Oriented Programming]


What is the constructor's implicit return type?
(a) none
(b) void
(c) same as constructor’s signature
(d) the class type itself (Recall)

14. [Object Oriented Programming]


Which of the following is a valid prototype of the non-parameterised constructor for the
class Book?
(a) public class Book {}
(b) Book(void)
(c) public Book( )
(d) public Book(void) (Application)

ISC Competency-Focused Practice 5


Computer ISC-Class

S.No. Questions

15. [Object Oriented Programming]


Which one of the given exceptions is raised when a user enters a String literal “hello”
on the execution of following code:
import java.util.*;
class Message
{
public void doIt( )
{
System.out.println("Enter a message");
int s = (new Scanner(System.in)).nextInt( );
System.out.println(s);
}
}
(a) InputMismatchException
(b) InputFormatException
(c) NullPointerException
(d) NumberFormatException

(Understanding & Application)

16. [Inheritance]
In single inheritance, which one of the following keywords should NOT be used.
(a) extends
(b) this
(c) super
(d) implements (Application)

17. [Inheritance]

interface A interface B
{ {
final static int x=5; final static int y=5;
abstract void abc( ); abstract void abc( );
} }
Assume that class Check implements interfaces A and B,
how many times the method abc( ) will be defined in class
Check ?
(a) Twice
(b) Once
(c) Compile time error
(d) Runtime error (Application)

ISC Competency-Focused Practice 6


Computer ISC-Class

S.No. Questions

18. [Data Structure]

The Central Processing Unit (CPU) scheduling follows the principle of _ data
structure.

(a) Two-dimensional array


(b) Circular queue
(c) Double ended queue dequeue
(d) Stack (Application)

19. [Data Structure]

For the above Binary Tree, which traversal order will arrange the elements in ascending
order?
(a) Post order
(b) Pre order
(c) In order
(d) Postfix order (Application)

20. [Data Structure]

is called a Self-Referential Data structure.


(a) Stack
(b) Circular queue
(c) Linked List
(d) Double ended queue - dequeue (Recall)

ISC Competency-Focused Practice 7


Computer ISC-Class

II. Assertion-Reason Questions (1 Mark Each)

The questions in this section have two statements marked Assertion and Reason. Read both
S.No.
the Questions
statements carefully and choose the correct option.

21. [Recursion]
Assertion (A): Recursion utilises more memory as compared to iteration.
Reason (R): Absence of base case leads to infinite recursion.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, and R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true. (Analysis)

22. [Boolean Algebra]

Assertion (A): In Boolean Algebra, dual of the Boolean expression (A+B)’.1 is equal
to 0.
Reason (R): In Boolean Algebra, the complement of an OR operation is equal to the
AND operation of complement of the individual variables.

(a) Both A and R are true, and R is the correct explanation of A.


(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.
(Understanding & Evaluate)
23. [Boolean Algebra]

Assertion (A): The truth table for the XOR gate shows that the output is HIGH only
when an odd number of inputs are HIGH.
Reason (R): The XOR gate performs addition modulo 2, thus producing a HIGH
output when the number of HIGH inputs is odd.

(a) Both A and R are true, and R is the correct explanation of A.


(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false
(d) A is false, but R is true. (Understanding & Evaluate)

ISC Competency-Focused Practice 8


Computer ISC-Class

S.No. Questions

24. [Proportional Logic]


Assertion (A): The Equivalence expression is p <-> q.
Reason (R): An Equivalence Statement always gives the final result as Contingencies.

(a) Both A and R are true, and R is the correct explanation of A.


(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true. (Application & Analysis)

25. [Boolean Algebra]


Assertion (A): The contrapositive of p’ => q is q’=> p
Reason (R): Contrapositive is the conditional statement, obtained after interchanging
antecedent and consequent.
(a) Both A and R are true, and R is the correct explanation of A
(b) Both A and R are true, but R is not the correct explanation of A
(c) A is true, but R is false.
(d) A is false, but R is true. (Understanding & Evaluate)

ISC Competency-Focused Practice 9


Computer ISC-Class

III: Very Short Answer Questions (1 Mark

S.No. Questions

26. [Inheritance]
Study the given two classes below and identify the error if any, in the given code.

class Vehicle class Car extends Vehicle


{ {
protected String colour; private double weight;
protected String registration; private String model;
public Vehicle(String c, String r) public Car(String model, double weight,
{ String colour, String registration)
colour = c; {
registration = r; this.model=model;
} this.weight=weight;
public void show( ) super(colour,registration);
{ }
System.out.println("Colour:"+colour); public void show( )
System.out.println("Registration {
number:"+registration); super.show( );
} System.out.println("Car Model
} name = " + model);
System.out.println("Car body
weight ="+weight);
}
}

(Evaluate)
27. [Inheritance]
What will happen if data members of super class are made private instead of protected?
(Evaluate)
28. [Inheritance]
What will happen if void show( ) in subclass Car is given access specifier as private?
(Evaluate)

29. [Interface]
All methods declared in the interface are abstract. Where will the body of these abstract
methods be defined?
(Application)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions

30. [Inheritance]

Based on the above given image, write the java statement to create the class Child.
(Create)

31. [Polymorphism]
In the given code snippet, which feature of object-oriented programming concept is
being exhibited by the substring( ) method?
String s1="sandwich";
System.out.println(s1.substring(4));
System.out.println(s1.substring(1,4));
(Analysis)

32. [Primitive Values, Wrapper Classes, Types and Casting]


Following is a code to convert a String into Double. Fill the missing parts of the code:
str = “15.45”;
double d = (Double.parseDouble(str));
(Create)

33. [Primitive Values, Wrapper Classes, Types and Casting]


How many bytes of data is passed when public void stu_data(int, double, char) is
invoked? (Analysis)
34. [Primitive Values, Wrapper Classes, Types and Casting]
Since a byte can represent 256 different numbers, why is its maximum value 127?
(Analysis)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions

35. [Primitive Values, Wrapper Classes, Types and Casting]


The following statement will generate a compile time error. This can be rectified in 2
different ways, without losing precision of price. Write these statements.
float price = 17.99;
(Analysis & Application)
36. [Primitive Values, Wrapper Classes, Types and Casting]
Ram and Hari are coder friends, who are debating effective usage of memory while
using variables, without compromising on precision of values. Help them on
identifying the right data type to use, for the following data:
(a) Population of a country
(b) Interest rate in a bank account
(Application)

37. [Primitive Values, Wrapper Classes, Types and Casting]


What gets printed?
char [ ] set= {'*','D','5'};
System.out.print(Character.isDigit(set[2]) + " ");
System.out.print(Character.isWhitespace(set[0]) + " ");
System.out.print(Character.isLetterOrDigit(set[1]));
(Understanding)

38. [Primitive Values, Wrapper Classes, Types and Casting]


While using Wrapper classes, we do not need to import any package. Give a reason.

(Understanding)

39. [Primitive Values, Wrapper Classes, Types and Casting]


Teachers of class XII are calculating the average attendance for 3 months. The class
attendance for 3 months is stored in double variables m1,m2,m3. TeacherA and
TeacherB are using different techniques to get the average. Complete the code of
TeacherA and name the technique used by him:

TeacherA TeacherB

int average=( )((m1+m2+m3)/3); int average= Math.round((m1+m2+m3)/3);

(Application)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions

40. [Computational Complexity and Big O Notation]


Consider the following snippet, calculate the time complexity assuming the code
compiles successfully.

double m = 1, n = 1;
for (int i = 0; i< x; i++)
{
m *= Math.random( );
}
for (int j = 0; j < y; j++)
{
n *= Math.random( );
}
(Analysis & Evaluate)

41. [Computational Complexity and Big O Notation]


“Finding the greatest common divisor (GCD) of two positive integers results in the
time complexity of O(log N) where N is the larger number of two inputs”. Justify the
statement. (Understanding & Analysis)

42. [Computational Complexity and Big O Notation]


A student had written the following method to display “Hello World” four times on the
output screen.
void displayMessage( )
{
System.out.println("Hello World");
System.out.println("Hello World");
System.out.println("Hello World");
System.out.println("Hello World");
}

The student modified the code later to reduce the number of lines in the code.
void displayMessage( )
{
int i =1;
while(i<=4)
{
System.out.println("Hello World");
i++;
}
}
Compare the above code snippets with respect to the time complexity.
(Understanding & Analysis)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions

43. [String and Arrays]


Find the output of the following snippet:
void check1( )
{ String x[ ]={"Kolkata","Chennai","Delhi"};
String y[ ]={"Kolkata","Chennai","Delhi"};
System.out.println(x.equals(y));
}
(Evaluate)

44. [String]
The java statement to print the position of 2nd occurrence of the letter 'I' within the
word "MICHIGAN".
(Recall)

45. [String]
Find the output:
System.out.println("RocKet".substring(0, 4).compareTo( "Rock".replace('m' , 'o')));
(Evaluate)

46. [Arrays]
What is the length of the array int arr[ ], if its first index is x and the last index is y ?
(Application)

47. [String]
String s1= "Gujarat";
String s2= new String("Gujarat");
String s3= new String ("Gujarat");
String s4= "Gujarat" ;
How many String objects are created in the above snippet? Justify your answer.
(Understanding)

48. [String]
Find the output of following snippet:
String S1= "AB" , S2= "BC";
for(int i=0, j=0 ; i<S1.length( ) ; i++, j++)
System.out.println(S1.charAt(i)+S2.charAt(j));
(Evaluate)

ISC Competency-Focused Practice 1


Computer ISC-Class

IV. Short Answer Questions (2 Marks


Each)

S.No. Questions
49. [Packages]
Why is the lang package termed as the default package in Java?
(Analysis & Recall)

50. [Packages]
State the purpose of the following keywords in Java:
(a) package
(b) import (Application)

51. [Packages]
Given the following code snippet:

package mine; import java.util.*;


public class Greetings import mine.*;
{ public class Trial
public static void greet(String name) {
{ public static void main()
System.out.println("Hello "+name+", {
welcome to the world of programming"); Scanner sc=new Scanner(System.in);
} System.out.println("Give your name");
} String n=sc.next();
Greetings.greet(n);
}
}

(a) Predict the output for n= “Abhay”;


(b) Explain the difference between the two statements:
import java.util.*; and import mine.*;

(Evaluate)

52. [Computer Hardware]


A 2 to 4 decoder contains 2 inputs denoted by A1 and A0 and 4 outputs denoted by
D0, D1, D2, D3. Write the minterm representations for D1 and D3. (Evaluate)

53. [Computer Hardware]


Write the cardinal Product-of-Sum (POS) expression for the sum and carry of a full adder.
(Application & Analysis)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions
54. [Computer Hardware]
Following is the circuit diagram of a full adder. Redraw the circuit diagram by adding
missing logic gates.

(Recall)

55. [Computer Hardware]


Draw the logic circuit diagram for the simplified form of the following expression:
AB’C’+ AB’C + ABC
The circuit diagram should only contain one AND, one OR and one NOT gates.
(Application & Analysis)

56. [Recursion]
Following method is a part of a class MyArray.
int check(int m[ ], int i)
{
if (i<= 0)
{
return 0;
}
return check(m, i-2 ) + m[i-1];
}
public static void main( )
{
int m[ ] = {1, 2, 3, 4};
int ans = check(m, m.length);
System.out.println(ans);
}
(a) Predict the output of the code considering there is no compilation error. Show
the working.
(b) Considering the if condition is changed to if(i<0), how will it affect the output?
(Recall & Analysis)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions
57. [Recursion]
A student has written the following code. It is written to check whether a string is
palindrome or not. However, the code is not giving the desired result when the parameter
“MADAM” is passed to the method isPalindrome(). Analyse the code and find out the
logical error.

public class PalindromeTesting


{
public static booleanisPalindrome(String word)
{ if (word.length( ) < 1)
{
return true;
}
else if (word.charAt(0) != word.charAt(word.length( ) - 1))
{
return false;
}
else
{
return isPalindrome(word.substring(0, word.length( ) - 1));
}
}
}
(Understanding & Analysis)

58. [Recursion]
Following code gives a StackOverException.

Stack is a data structure whereas recursion is related to a method. Why does the above
code give an exception with stack overflow?
(Understanding & Application)

ISC Competency-Focused Practice 1


Computer ISC-Class

S.No. Questions
59. [Operation on File]
What is the difference between the following two statements?
1. FileWriterfw=new FileWriter(<file name>);
2. FileWriterfw=new FileWriter(<file name>, true);
(Create)

60. [String Tokenizer]


What is the difference between the two methods, nextToken( ) and hasMoreTokens( ) of
StringTokenizer class ? (Recall)

ISC Competency-Focused Practice 1


Computer ISC-Class

61. [Operation on File]


A class teacher has kept the records of the marks obtained in Physics and Computer
Science of 3 students along with the students’ name. Write a java program to display the
name of those students, whose average marks are highest.
File name is Student. txt (Assume that following data is written in file )

Student Name Physics Computer Science

Anurag 90 95

Brijesh 95 95

Toshali 97 100

Now, there are four places in the code marked as ?1? , ?2? , ?3? and ?4? and they must
be replaced by the statements so that the program runs correctly.
import java.util.*;
import java .io.*;
class StuFile
{
public static void calculate( )throws IOException
{
FileReader fr= new FileReader(“Student.txt”);
BufferedReader br=new BufferedReader(fr);
String t , name, name1;
int ph, co;
double avg ;
double max=0;
while( ?1? )
{
StringTokenizer st=new StringTokenizer( t );
name= ?2? ; // Student name
ph= Integer.parseInt(st.nextToken( )); // Physics marks
co = Integer.parseInt(st.nextToken( )); // Computer Science marks
avg= (ph+co)/?3? ;
System.out.println(name+"- "+ph+", "+co+", "+avg);
if ( max<avg )
{
max=avg ;
name1=name ;
} // end of if
} // end of outer while
System.out.println( “Name of students with highest average =”+name1);
?4?
} // end of calculate method
} // end of class StuFile (Create)

ISC Competency-Focused Practice 1


Computer ISC-Class

V: Long Answer Questions (5 Marks Each)

S.No. Questions

62. [Linked List]


At Get It All supermarket, a POS (Point of Sale) system is designed. The cart management
is visible to the POS operator. The newer carts get added and once the bill payment is done
the current cart gets checked out from the system. The operator has 4 options like add cart,
check out cart, view cart queue and close the counter. The class Cart is created to represent
the node of the linked list.

public class Cart


{
int cartNo;
Cart next;
Cart(int cartNo)
{
this.cartNo=cartNo;
next=null;
}
}

The class POS is created to represent the POS for cart management. Observe the given code
and answer the following questions.
import java.util.*;
public class POS
{
Cart first;
static int count=0;
static Scanner sc=new Scanner(System.in);
void viewQueue( )
{
Cart temp=first;
boolean flag=false;
System.out.println("The carts at the counter are");
while(temp!=null)
{
System.out.println(temp.cartNo);
?1?
?2?
}
if(!flag)
System.out.println("The checkout counter is empty");
else
System.out.println("number of carts currently="+count);
}
void addCart()
{
System.out.print("Enter the new cart number: ");

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions
int no=sc.nextInt( );
Cart newCart = new Cart(no);
if(first==null)
first=newCart;
else
{
Cart temp=first;
while(temp.next!=null)
temp=temp.next;
temp.next=newCart;
}
count++;
}
void checkOutCart()
{
?1?
System.out.println("Cart being removed ="+temp.cartNo);
?2?
temp.next =null;
temp=null;
?3?
System.out.println("Carts remaining "+count);
}
}
(a) Write the code for the blanks given in the method void viewQueue( ).
(b) Mention the code for the blanks given in the method void checkOutCart( ).

(Analysis & Evaluate)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

63. [Binary Tree]


(a) Observe the following binary tree and identify its type. Justify your answer.

(b) Observe the given tree and answer the following questions.
(i) Why can the following tree not be termed as a full binary tree?

(ii) What is the size of the given binary tree?


(iii) Name the internal nodes of the given binary tree.
(c) State any one condition for a balanced binary tree.
(Evaluate)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

64. [Inheritance, Interfaces and Polymorphism]


(a) Complete the missing parts of the code given below:
class SI ?1? Account
{
double sINT;
public SI ( double sP, double sR ,double sT)
{
?2?
sINT=0;
}
public void Interest( )
{ sINT=(P*R*T)/100; }
public void display( )
{
?3? //invoke display( ) of base class
Interest ( );
System.out.println( "Simple Interest=" +sINT);
}
} // class ends

(b) Answer the following questions, based on the above code:


(i) Name the base class and derived class
(ii) Write the prototype of the base class constructor.

(Application)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

65. [Inheritance, Interfaces and Polymorphism]


Fix the following keywords at the right places:
(i) extends
(ii) super
(iii) protected
(iv) abstract
(v) implements

(a) class D1 i1,i2


{ }
(b) void printInfo( );
(c) class S1
{ }
class D2 S1
{ }
(d) class S2
{
public void show( )
{ }
}
class D3 extends S2
{
public void show( )
{
.show( );
}
}
(e)

(Understanding & Application)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

66. [Inheritance, Interfaces and Polymorphism ]


(a) In Java, polymorphism is exhibited in two different ways. Identify them in the code
snippets given in Column A and Column B?

Column A Column B

Shapes myShape = new Shapes( class Vehicle


); myShape.area( ); {
myShape.area(5); void drive( )
myShape.area(6.0,1.2); {
myShape.area(6,2); System.out.println("Vehicle is moving");
}
}
class Bus extends Vehicle
{
void drive( )
{
System.out.println("Bus is running safely");
}
public static void main( )
{
Bus b = new Bus(
); b.drive( );
}
}

(b) Differentiate between the keywords this and super (... ) with respect to constructor.

(c) Base class Student and derived class ICSEStudent are illustrated as given below:

Similarly, show the classes Shapes, Triangle, TwoD_Shapes, Sphere, ThreeD_Shapes


exhibiting inheritance at multi-levels, depending on the type of shapes.
(Analysis, Application, Evaluate & Create)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

67. [Karnaugh Map]

A student from the Electronics department is asked to design a digital alarm for a smart
home security system for the outside area. It comprises a sensor and a digital identification
(ID) card with six-digit personal identification number (PIN). The alarm is supposed to
buzz if wrongful entry is attempted, either by breaking the glass window or by entering the
wrong PIN.

Following statements are the criteria for the alarm to buzz:

 The sensor detects the door opening without scanning a digital ID card.
or
 The sensor detects the door opening by breaking of the door lock.
or
 The sensor detects the wrong pin entry thrice of the digital ID card while opening
the door.

The inputs are:

Inputs

D Door opening

B Breaking of door lock

S Scanning security card

P Entering correct six-digit pin less than three times

(In all the above cases 1 indicates Yes and 0 indicates No).

Output: A – Denotes the buzz of security alarm system (1 indicates yes and 0 indicates
no)

Draw the truth table for the inputs and outputs given above. Write the canonical POS
expression for the A (D, B, S, P).
(Understanding, Recall, Apply, Create)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions

68. [Karnaugh Map]

Given the Boolean function F (P,Q,R,S) = Σ (2,3,5,7,8,10,11,12,13,15).

(a)Reduce the above expression by using a 4-variable Karnaugh map, showing the various
groups (i.e. octal, quads and pairs).

(b) Draw the logic gate diagram for the reduced expression using NAND gate only.
Assume that the variables and their complements are available as inputs.

(Understanding, Recall, Apply, Create)

69. [Boolean Algebra]


(a) f (a, b, c ) = a.b’ + a.c + b.c’ .
Find its corresponding Cardinal and Canonical sum-of- product expression?
(b) If a=1, b=0, c=1, d=0, then write maxterm and minterm for F(a, b, c, d) in canonical
form?
(Analysis & Understanding)
70. [Boolean Algebra]
Post pandemic, to encourage the tourism industry in India, the Ministry of Tourism started
a policy in which a tourist would be allowed to book a resort at a rebate, if the any one of
the following criteria matches.

● The tourist has an AADHAR card and has no criminal record.


● The tourist is the government employee and has repeated the resort visit
in a span of six months.
● The tourist has an AADHAR card and has repeated the resort visit in a
span of six months.
Inputs :
A : The tourist has an AADHAR CARD
C : The tourist has a criminal record
G : The tourist is the government employee
V : The tourist has repeated the resort visit in a span of six months
Output : F : The tourist would be allowed to book the resort at rebate.
[ 1 indicates Yes and 0 indicates No ].
Draw the truth table for inputs and outputs given above and write the Cardinal Sum of
product expression for F ( A, C, G, V ).
(Understanding & Evaluate)

ISC Competency-Focused Practice 2


Computer ISC-Class

VI. Very Long Answer Questions (10 Marks Each)

S.No. Questions
71. [Programme based on Numbers]
An Automorphic number is a number whose square ends with the given
number itself. E.g. (5)2 = 25, (25)2 = 625, (76)2 = 5776.
Design a class Automorphic to check if numbers in the given range are
Automorphic numbers or not. The member functions and data members of the
class are given below:

Class Name : Automorphic


Data members/instance variables:
l, u :lower and upper limits of the range
count :frequency of the automorphic numbers in the range l and u
Member functions :
Automorphic(int l, int u): parameterised constructor to assign values to data
members
boolean check(int n) : to check if n is an automorphic number. If yes it
returns
true otherwise returns false.
void list( ) : to check all the numbers between the range l and u, by
calling check(int n) and to display only the
automorphic numbers. Also to display the frequency
of the automorphic numbers in the given range.
Specify the class Automorphic giving details of the parameterised constructor,
boolean check(int n) and void list( ). Create one object in the main( )method
and call all the methods appropriately.
Sample input
Enter the lower limit of the range->1
Enter the upper limit of the range-
>1000

Sample output
List of Automorphic numbers from 1 to 1000 :
Number Square
1 1
5 25
6 36
25 625
76 5776
376 141376
625 390625
Frequency of Automorphic numbers between 1 to 1000 : 7
(Create)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions
72. [Programme based on Strings]
Two words are called anagram of each other if both the words contain the same
letters but they are arranged in different order. Following are the three pairs of
the words which are anagrams of each other.
cat, act heart, earth silent, listen
Design the class Anagram to input two words in lower case and check if they
are anagram of each other. The member functions and data members of the
class are given below:
Class Name :Anagram
Data members/instance variables:
s1, s2 : stores the two words in lower case
l1,l2 : number of character in s1 and s2 respectively
Member functions :
Anagram(String s1, String s2): parameterised constructor to assign the accepted
values of s1 and s2 to data member
void sort(char c[]) : to sort the characters in array c[ ] in ascending
order using any sorting technique
boolean areAnagram(char[] str1, char[] str2)
: to check if str1 and str2 are anagrams of
each other and to return true or false
accordingly
void check() : to convert the two strings into two character
arrays and to display the appropriate message as
shown in the sample output by calling the
method areAnagram(char[] str1, char[] str2)

Specify the class Anagram giving details of the parameterised constructor, void
sort(char c[ ]), boolean areAnagram(char[] str1, char[] str2) and void check(
). Create one object in the main( )method and call all the methods
appropriately.

Sample input
Enter first word->earth
Enter second word->heart

Output
earth and heart are anagram of each other
(Create)

ISC Competency-Focused Practice 2


Computer ISC-Class

S.No. Questions
73. [Recursion program]
Design a class Spy to check if a number is a Spy number or not. A spy number
is a number where the sum of its digits equals the product of its digits. For
example, 1124 is a spy number, the sum of its digits is 1+1+2+4=8 and the
product of its digits is 1*1*2*4=8.
Class name : Spy
Data Members:
num : to store the number

Member methods:

Spy(int nn) : initialize the data member num=nn


int sumOfDigits(int i) : returns the sum of digits of num
using recursive technique
int prodOfDigits( int i) : returns the product of digits of num
using recursive technique
void check( ) : checks whether the given number is a
Spy number or not by invoking the
functions sumOfDigits( ) and prodOfDigits( )
and displays appropriate message

Specify the class Spy giving details of the functions int sumOfDigits(int ), void
check( ), int prodOfDigits(int). Assume that the data member and constructor
are already defined. Define a main method to create an object and call the
functions accordingly to enable the task.
(Analysis, Application, Evaluate & Create)

ISC Competency-Focused Practice 3


Computer ISC-Class

S.No. Questions
74. [Object as an Argument]
A sports academy wants to conduct a friendly match between two teams with
maximum fifteen players. A class Sports contains three data members, to store
the name of the team with ‘n’ number of players and a one-dimensional array to
store height of each player. Design a class Sports to compare average height of
both the teams. The details of the members of the class are given below:

Class Name : Sports

Data Members / Instance Variables:

height[] : to store the height of each player


name : to store the name of the team
n : to store total number of players

Member methods:

Sports() : default constructor

Sports(int n, String name): to initialize the number of players and


name of the team

void fillHeight() : to enter the height of all the players

double averageHeight() : to calculate average height of the team

String compare(Sports s1, Sports s2) :to compare average height of both
the teams and return the name of
the team with the higher average
height

void display(String msg) :to display the name of the team with the
higher average height stored in msg. If
both the teams have the same average
height, then it msg should be “Both teams
have the same average height.”

Specify the class Sports giving the details of constructors, void fillHeight( ),
double averageHeight( ), String compare(Sports, Sports),void display(String).
Write the main( ) method to call methods defined in an appropriate manner.

(Understanding, Recall & Create)

ISC Competency-Focused Practice 3


Computer ISC-Class

S.No. Questions
75. [Arrays]
Given below is an example of a double dimensional array with unequal number
of rows and columns. It must be arranged in such a way that the elements in the
even rows are in ascending order and the elements in the odd rows are in
descending order , using Insertion sort technique.
Sample Input :
Row=3
Column=4
Enter the array elements
1234
9876
4567
Before sort:
1 2 3 4
9 8 7 6
4 5 6 7
After sort:
4 3 2 1
6 7 8 9
7 6 5 4
The members of the class are given below:
Class name : Mix_sort
Data members / instance variables:
a[][] : to store integers in the double dimensional array.
m : to store the number of rows .
n : to store the number of columns .
Methods / Member functions :
Mix_sort(int row, int col) : parameterised constructor to initialise the
m=row, n=col and allocate memory for a[][]
void input() : to enter the integer elements in a [][]
void ascEven(int x[]) : arrange the elements of x[] in ascending
order using Insertion sort technique.
void dscOdd(int x[]) : arrange the elements of x[] in descending order
using Insertion sort technique.
void arrange() : to arrange the rows in even position in Ascending
order using ascEven(.. ) method and rows in odd
position in descending order using dscOdd(..)
method. Finally store the sorted elements into a[][]
void display( ) : display the original a[][] and sorted a[][] .

Define the class Mix_sort with details of the constructor, void input(), void
arrange(), void ascEv(int []), void dscOdd(int []) and void display( ). Define a
main() function to create an object and call the functions accordingly to enable
the task.
(Understanding, Recall & Create)

ISC Competency-Focused Practice 3


Computer ISC-Class

ANSWER

Q.No. Expected Answers

1. (b) Zero will be displayed as variable i has global scope with respect to the loop.

2. (a) mutate object m.

3. (c) undeclared method equalsIgnoreCase(…)

4. (d) All of the above

5. (a) i and ii

6. (b) 2, 3 and 4

7. (b) equals( )

8. (d) b q y

9. (d)

10. (b) StudentBanyan stud1 = new StudentBanyan("Kylin",23, 5.6);


11. (d) Only III

12. (a) static

13. (d) the class type itself

14. (c) public Book( )

15. (a) InputMismatchException

16. (d) implements

17. (b) Once

18. (b) Circular queue

19. (c) In order

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

20. (c) Linked List

21. (b) Both A and R are true, and R is not the correct explanation of A.

22. (d) A is false, and R is true.

23. (a) Both A and R are true, and R is a correct explanation of A.

24. (a) Both A and R are true, and R is the correct explanation for A.

25. (c) A is true, and R is false.

26. Call of super (...) in the body of the parameterised constructor of class Car should be the
first statement in the constructor body.

27. Though the data members with access specifier private will be inherited to subclass Car,
they will not be directly accessible in subclass Car.

28. In that case, Method overriding of void show() will fail and it will give syntax error.

29. The body for the abstract methods of interface, is defined in the class which implements
this interface.

30. class Child implements Father, Mother

31. The method substring( )of class String is an overloaded method, thus it is exhibiting
polymorphism.
String str = “15.45”;
32.
Double d =new Double (Double.parseDouble(str));

33. 14 bytes ( int=4 bytes, double=8 bytes, char=2 bytes )

34. Range of byte is -128 to 127,which represents 256 different numbers including 0.

35. float price =17.99f; OR double price=17.99;

36. (a) Population- long data type, (b) Interest rate - float data type

37. true false true

38. Wrapper classes are part of java.lang package. Since the java.lang package is an in-built
package, an import statement is not needed. Hence, in programs where wrapper class
methods are used, programmers need not import any package.

39. int average=(int) ((m1+m2+m3)/3); Technique is explicit type conversion.

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

40. O ( x + y )

41. In each iteration of the code, the size of both the numbers is reduced by a factor of at
least
2. This makes the number of iterations proportional to log N.
42. The complexity of both the codes will remain same as O(1) as the print statement is
independent of any input size.

43. false
System.out.print(″MICHIGAN″.lastIndexOf("I"));
44.
OR
System.out.print("MICHIGAN".indexOf('I',2));

45. -32

46. y-x+1

47. Three objects. This is because s2 and s3 are two objects created in the heap memory.
Value of s1 is stored in string pool and s4 refers to object it, as the values of s1 and s4
are same and it is already present in the string pool.

48. 65+66 =131


66+67 = 133

49. To use any class from any package one needs to import that package in the current class
by using the import statement. lang is an exception to this rule and it can be used in any
class without using import statement. Hence, it is called the default package.
50. (a) package statement enables the creation of a user defined package.
(b) import statement enables the usage of a package(built in/ user defined) in a
particular class.
51. (a) Hello Abhay, welcome to the world of programming.
(b) import java.util.*; enables us to import the built-in package util whereas import
mine.*; enables us to import the user defined package mine.
D1= A1’.A0 D3= A1.A0
52.

53. Sum = ∏(0,3,5,6) Carry= ∏(0,1,2,4)

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

54.

55.

56. a. Output will be 6


Working:

b. The code will throw an exception - java.lang.ArrayIndexOutOfBoundsException as


Index -1 out of bounds for length 4.

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

57. Correct code is:

public class PalindromeTesting


{
public static booleanisPalindrome(String word)
{
if (word.length() <= 1) // or (word.length( ) == 1)
{
return true;
}
else if (word.charAt(0) != word.charAt(word.length( ) - 1))
{
return false;
}
else
{
return isPalindrome(word.substring(1,word.length( ) - 1));
}
}
}

58. Due to recursion, when a method calls itself, it creates a new copy of itself on the call
stack memory. The stack stores each method call in a last-in, first-out (LIFO) order. This
means that the last method call will be the first one to get resolved.
Each time a recursive method is called, a new local variable and parameters of the
respective are pushed onto the call stack memory. In the given example the base case is
missing, hence the recursion happens infinitely. But as the call stack memory is finite,
gets full and thus at runtime, stack overflow exception is thrown

59. In the first statement, the FileWriter object fw creates an output stream ( text file )
using default mode i.e. overwrite mode.
In the second statement, the FileWriter object fw creates an output stream ( text file ) , in
append mode.

60. nextToken( ) : It returns the next token present in the String from the current tokens.
It returns the string value
.hasMoreTokens() : It checks whether there are more tokens available or not . It
returns the boolean value.
61.
?1? → (t=br.readLine()) != null

?2? → st.nextToken();

?3? → 2.0
? 4? → fr.close( );
br.close( );

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

62. (a) 1. temp = temp.next;


2. flag=true;

(b) 1. Cart temp=first;

2. first=temp.next;
3. count--;

63. (a) Complete binary tree. In the above binary tree all the levels of the tree are filled
completely except the lowest level nodes, which are filled from left.
(b)(i) In a full binary tree, every node possesses either 0 or 2 successors. Here, node C has
only one successor i.e. E, hence it is not a full binary tree.
(ii) 6
(iii) B and C

(c)The absolute difference of heights of left and right sub trees at any node
is less than -1 or 0.
OR
For each node, its left sub tree is a balanced binary tree.
OR
For each node, its right sub tree is a balanced binary tree.

64. (a) ?1? extends


?2? super(sP,sR,sT);
?3? super.display( );
(b) (i) Base class- Account, derived class- SI
(ii) public Account(double P, double R, double T)

65. (a) implements


(b) abstract
(c) extends
(d) super
(e) protected

66. (a) Column A- method Overloading for .area( )


Column B- method Overriding for .drive( )

(b) Using ‘this’ from within one constructor invokes another constructor of the same
class. Using ‘super’ keyword, the super class constructor is invoked from the sub-class
constructor.

(c)

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

67.
D B S P Output

0 0 0 0 0

0 0 0 1 0

0 0 1 0 0

0 0 1 1 0

0 1 0 0 1

0 1 0 1 1

0 1 1 0 1

0 1 1 1 1

1 0 0 0 1

1 0 0 1 1

1 0 1 0 1

1 0 1 1 1

1 1 0 0 1

1 1 0 1 1

1 1 1 0 1

1 1 1 1 1
Canonical POS expression:

A(D,B,S,P) = π(D+B+S+P).(D+B+S+P’).(D+B+S’+P).(D+B+S’+P’)

ISC Competency-Focused Practice 3


Computer ISC-Class

Q.No. Expected Answers

68.
(a)

(b) Logic Diagram using NAND gate:

69. (a) a.b’ + a.c + b.c’


= a.b’.(c+c’) + a.c.(b+b’)+ b.c’.(a+a’)
= a.b’.c + a.b’.c’ + a.b.c + a. b’.c + a.b.c’ + a’.b.c’
= a.b’.c + a.b’.c’ +a.b.c + a.b.c’ + a’.b.c’
Canonical Sum of product: f(a, b, c)= a.b’.c + a.b’.c’ +a.b.c + a.b.c’ + a’.b.c’
a.b’.c = 101 = 5
a.b’.c’= 100 =4
a.b.c= 111 = 7
a.b.c’= 110 =6
a’.b.c’= 010 =2
Cardinal Sum of product expression : f(a, b, c)= ∑( 2, 4, 5, 6,7)

(b) Maxterm = a’+b+c’+d


Minterm = a.b’.c.d’

ISC Competency-Focused Practice 4


Computer ISC-Class

Q.No. Expected Answers

70. F( A,C,G,V )= ∑( 3, 7, 8, 9, 10, 11, 13, 15 )

A C G V F
0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
0 0 1 1 1
0 1 0 0 0
0 1 0 1 0
0 1 1 0 0
0 1 1 1 1
1 0 0 0 1
1 0 0 1 1
1 0 1 0 1
1 0 1 1 1
1 1 0 0 0
1 1 0 1 1
1 1 1 0 0
1 1 1 1 1

ISC Competency-Focused Practice 4


Computer ISC-Class
import java.util.*;
71.
public class Automorphic
{
int l,u,count;
public Automorphic(int l,int u)
{
this.l=l;
this.u=u;
count=0;
}
public boolean check(int n)
{
int s,dn,ds;
s=n*n;
boolean flag=true;
do
{
dn=n%10;
ds=s%10;
if(dn!=ds)
{
flag=false;
break;
}
n/=10;
s/=10;
}
while(n>0);
return flag;
}
public void list( )
{
int i;
System.out.println("List of Automorphic numbers from "+ l +" to "+u);
System.out.println("\n\tnumber\t\tsquare ");
for(i=l;i<=u;i++)
{
if(check(i))
{
count++;
System.out.print("\t "+i+"\t\t "+i*i+"\n");
}
}
System.out.println("\nFrequency of Automorphic numbers between "+ l +" to
"+u+" : "+count);
}
public static void main( )
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the lower limit of the range->");
int l=sc.nextInt( );

ISC Competency-Focused Practice 4


Computer ISC-Class

Q.No. Expected Answers


System.out.print("Enter the upper limit of the range->");
int u=sc.nextInt( );
Automorphic la=new Automorphic(l,u);
la.list( );
}
}

ISC Competency-Focused Practice 4


Computer ISC-Class
import java.util.*;
72.
class Anagram
{
private String s1,s2;
private int l1,l2;
Anagram(String s1,String s2)
{
this.s1=s1;
this.s1=this.s1.toLowerCase( );
this.s2=s2;
this.s2=this.s2.toLowerCase( );
l1 = s1.length( );
l2 = s2.length( );
}
public void sort(char c[])
{
int i,j;
char temp;
for(i=0;i<c.length;i++)
{
for(j=0;j<c.length-i-1;j++)
{
if(c[j]>c[j+1])
{
temp=c[j];
c[j]=c[j+1];
c[j+1]=temp;
}
}
}
}
public boolean areAnagram(char[] str1, char[] str2)
{
if (l1!=l2)
return false;
sort(str1);// sorting the char array str1
sort(str2);// sorting the char array str2
for (int i=0;i<l1;i++)
if (str1[i] != str2[i])
return false;
return true;
}
public void check()
{
int i;
char ch1[]=new char[s1.length( )];
char ch2[]=new char[s2.length( )];
for(i=0;i<l1;i++)
ch1[i]=s1.charAt(i);
for(i=0;i<l2;i++)
ch2[i]=s2.charAt(i);

ISC Competency-Focused Practice 4


Computer ISC-Class

Q.No. Expected Answers


if (areAnagram(ch1,ch2))
System.out.println(s1+" and "+s2+" are anagram of each other");
else
System.out.println(s1+" and "+s2+" are not anagram of each other");
}
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter first word->");
String s1=sc.next();
System.out.print("Enter second word->");
String s2=sc.next();
Anagram an=new Anagram(s1,s2);
an.check();
}
}

ISC Competency-Focused Practice 4


Computer ISC-Class

Q.No. Expected Answers

73. import java.util.*;


class Spy
{
int num;
Spy(int nn)
{
num=nn;
}
int sumOfDigits(int i)
{
if (i == 0)
return 0;
return (i % 10 + sumOfDigits(i/10));
}
int prodOfDigits(int i)
{
if(i == 0)
{
return 1 ;
}
return ((i%10)*prodOfDigits(i/10)) ;
}
void check( )
{
int x=sumOfDigits(num);
int y=prodOfDigits(num);
if (x==y)
System.out.println(num+" is a spy number");
else
System.out.println(num+" is not a spy number");
}
public static void main( )
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number”);
int nn = sc.nextInt( );
Spy s1=new Spy(nn);
s1.check( );
}
}//classends

ISC Competency-Focused Practice 4


Computer ISC-Class
import java.util.*;
74.
class Sports
{
int n;
double height[];
String name;
Sports( ){ }
Sports(int n, String name)
{
this.name= name;
this.n=n;
height = new double[n];
}
void fillHeight( )
{
Scanner sc= new Scanner(System.in);
for(int i=0; i<n;i++)
{
System.out.println("Height of member "+(i+1));
height[i] = sc.nextDouble( );
}
}
double averageHeight( )
{
double avg, tot=0;
for(int i=0; i<n;i++)
{
tot+= height[i];
}
avg= (double)tot/n;
return avg;
}
String compare(Sports s1, Sports s2)
{
double avgT1 = s1.averageHeight();
double avgT2 = s2.averageHeight();
System.out.println("Average height of team "+s1.name+" = "+avgT1);
System.out.println("Average height of team "+s2.name+" = "+avgT2);
if(avgT1 > avgT2)
return "Teams"+s1.name + "has higher average height.";
else if(avgT2 > avgT1)
return "Teams"+s2.name + "has higher average height.";
else
return "Both teams have the same average height";
}
void display(String msg)
{
System.out.println(msg);
}
public static void main( )
{
String t1 = "XYZ", t2 = "ABC";
ISC Competency-Focused Practice 4
Computer ISC-Class

Q.No. Expected Answers


Sports s1 = new Sports(4, t1);
Sports s2 = new Sports(4,t2);
System.out.println("Enter height of team " + t1);
s1.fillHeight();
System.out.println("Enter height of team " + t2);
s2.fillHeight();
String a = s1.compare(s1,s2);
s1.display(a);
}
}

ISC Competency-Focused Practice 4


Computer ISC-Class
import java.util.*;
75.
class Mix_sort
{
int a[][];
int r,c;
Mix_sort(int row, int col)
{
r=row;
c=col;
a=new int[r][c];
}
void input( )
{
Scanner sc=new Scanner(System.in);
for(int i=0; i<r ; i++)
for(int j=0; j<c ; j++) a[i]
[j]=sc.nextInt( );
System.out.println("Before sort:");
}
void arrange()
{
int k[]=new int[c];
for(int i=0; i<r ; i++)
{
for(int j=0 ; j<c ; j++)
{
k[j]= a[i][j];
}
if((i+1)%2==0)
ascEven(k);
else
dscOdd(k);
for(int j=0; j<c; j++)
{
a[i][j]=k[j];
}
}
System.out.println("After sort:");
}
void ascEven(int x[])
{
for(int i=1; i<x.length ; i++)
{
int j=i-1;
int k=x[i];
while(j>=0 && x[j] > k)
{
x[j+1]=x[j];

ISC Competency-Focused Practice 4


Computer ISC-Class
j--;
}
x[j+1]=k;
}
}
void dscOdd(int x[])
{
for(int i=1; i<x.length ; i++)
{
int j=i-1;
int k=x[i];
while(j>=0 && x[j]<k)
{
x[j+1]=x[j];
j--;
}
x[j+1]=k;
}
}
void display( )
{
for(int i=0; i<r ; i++)
{
for(int j=0; j<c ; j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
public static void main( )
{
Scanner sc=new Scanner(System.in);
int r1,c1;
do
{
System.out.println("Enter the number of rows & columns.");
r1=sc.nextInt();
c1=sc.nextInt();
if(r1==c1)
System.out.println(“ Invalid : Square matrix “);
}while(r1<=0 || c1<=0 || r1==c1);
Mix_sortob=new Mix_sort(r1, c1);
ob.input();
ob.display();// original array
ob.arrange();
ob.display();// sorted array
} }

ISC Competency-Focused Practice 5

You might also like