Prashnikaप्रश्निका
Code
About
Computer ScienceSpecimenClass 12

ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1 with Answers

The ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1 for Class 12: all 17 questions, 35 marks in all, in printed order and in full. It is free to download: tap "Show answer" under a question to see its answer, or use the download button to save the questions as a PDF, with or without answers; "Print this paper" below prints it as it was set.

17questions
35marks
5chapters
Q1(i)1 mark · MCQOpen: The keyword used by a class to acquire the properties of an interface is:

Choose the correct option.

The keyword used by a class to acquire the properties of an interface is:
  • (a)import
  • (b)implements
  • (c)extends
  • (d)include
Show answer

Answer

Correct option: (b)

Answer: (b) implements A class uses the keyword implements to acquire (implement) an interface; extends is used for class inheritance.
Q1(ii)1 mark · MCQOpen: The ability of an object to take many forms is known as:

Choose the correct option.

The ability of an object to take many forms is known as:
  • (a)inheritance
  • (b)data abstraction
  • (c)overriding
  • (d)polymorphism
Show answer

Answer

Correct option: (d)

Answer: (d) polymorphism Polymorphism is the ability of an object or function to take many forms.
Q1(iii)1 mark · MCQOpen: int Toy(int n) { return (n<=0)? 1: n%10 + Toy(n/10); } With reference to the…

Choose the correct option.

int Toy(int n)
{ return (n<=0)? 1: n%10 + Toy(n/10); }
With reference to the program code given above, what will the function Toy() return when the value of $n = 56$?
  • (a)65
  • (b)12
  • (c)651
  • (d)11
Show answer

Answer

Correct option: (b)

Answer: (b) 12 Toy(56) = 6 + Toy(5) = 6 + (5 + Toy(0)) = 6 + 5 + 1 = 12, since Toy(0) returns 1.
Q1(vii)1 mark · Short answerOpen: Give one reason, why iteration is better than recursion.

Answer the following question.

Give one reason, why iteration is better than recursion.
Show answer

Answer

Iteration uses less memory and is usually faster, because it does not create a new stack frame for every repeated call as recursion does (so there is no risk of stack overflow).
Q22 marks · DifferentiateOpen: Differentiate between direct recursion and indirect recursion.

Differentiate between the following.

Differentiate between direct recursion and indirect recursion.
Show answer

Answer

Direct recursion: a function calls itself directly, e.g. int f(int n) { ... f(n-1) ... }. Indirect recursion: a function calls another function, which in turn calls the first function back, e.g. A() calls B() and B() calls A().
Q5(i)6 marks · ProgramOpen: Design a class Check which checks whether a word is a palindrome or not…

Write the program described below.

Design a class Check which checks whether a word is a palindrome or not. (Palindrome words are those which spell the same from either ends). Example: MADAM, LEVEL etc. The details of the members of the class are given below: Class name: Check Data members/instance variables: wrd: stores a word len: to store the length of the word Methods/Member functions: Check(): default constructor void acceptword(): to accept the word boolean palindrome(): checks and returns ‘true’ if the word is a palindrome otherwise returns ‘false’ void display(): displays the word along with an appropriate message Specify the class Check giving details of the constructor, void acceptword(), boolean palindrome() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.
Show answer

Answer

import java.util.*;
class Check
{
    String wrd;
    int len;

    Check()
    {
        wrd = "";
        len = 0;
    }

    void acceptword()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a word: ");
        wrd = sc.next();
        len = wrd.length();
    }

    boolean palindrome()
    {
        for (int i = 0; i < len / 2; i++)
            if (wrd.charAt(i) != wrd.charAt(len - 1 - i))
                return false;
        return true;
    }

    void display()
    {
        if (palindrome())
            System.out.println(wrd + " is a palindrome word");
        else
            System.out.println(wrd + " is not a palindrome word");
    }

    public static void main(String[] args)
    {
        Check ob = new Check();
        ob.acceptword();
        ob.display();
    }
}
The method palindrome() compares the characters from both ends moving towards the middle; any mismatch returns false. Sample run: MADAM gives "MADAM is a palindrome word".
Q5(ii)6 marks · ProgramOpen: Design a class Toggle which toggles a word by converting all upper case…

Write the program described below.

Design a class Toggle which toggles a word by converting all upper case alphabets to lower case and vice versa. Example: The word “mOTivATe” becomes “MotIVatE” The details of the members of the class are given below: Class name: Toggle Data members/instance variables: str: stores a word newstr: stores the toggled word len: to store the length of the word Methods/Member functions: Toggle(): default constructor void readword(): to accept the word void toggle(): converts the upper case alphabets to lower case and all lower case alphabets to upper case and stores it in newstr void display(): displays the original word along with the toggled word Specify the class Toggle giving details of the constructor, void readword(), void toggle() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.
Show answer

Answer

import java.util.*;
class Toggle
{
    String str, newstr;
    int len;

    Toggle()
    {
        str = "";
        newstr = "";
        len = 0;
    }

    void readword()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a word: ");
        str = sc.next();
        len = str.length();
    }

    void toggle()
    {
        newstr = "";
        for (int i = 0; i < len; i++)
        {
            char ch = str.charAt(i);
            if (Character.isUpperCase(ch))
                newstr = newstr + Character.toLowerCase(ch);
            else if (Character.isLowerCase(ch))
                newstr = newstr + Character.toUpperCase(ch);
            else
                newstr = newstr + ch;
        }
    }

    void display()
    {
        System.out.println("Original word: " + str);
        System.out.println("Toggled word: " + newstr);
    }

    public static void main(String[] args)
    {
        Toggle ob = new Toggle();
        ob.readword();
        ob.toggle();
        ob.display();
    }
}
Each character is checked and its case reversed and appended to newstr. Sample run: mOTivATe gives MotIVatE.
Q6(i)6 marks · ProgramOpen: A class Fibo has been defined to generate the Fibonacci series 0, 1, 1, 2, 3…

Write the program described below.

A class Fibo has been defined to generate the Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, ……. (Fibonacci series are those in which the sum of the previous two terms is equal to the next term). Some of the members of the class are given below: Class name: Fibo Data member/instance variable: start: integer to store the start value end: integer to store the end value Member functions/methods: Fibo(): default constructor void read(): to accept the numbers int fibo(int n): return the nth term of a Fibonacci series using recursive technique void display(): displays the Fibonacci series from start to end by invoking the function fibo() Specify the class Fibo, giving details of the Constructor, void read(), int fibo(int), and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.
Show answer

Answer

import java.util.*;
class Fibo
{
    int start, end;

    Fibo()
    {
        start = 0;
        end = 0;
    }

    void read()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter start: ");
        start = sc.nextInt();
        System.out.print("Enter end: ");
        end = sc.nextInt();
    }

    int fibo(int n)
    {
        if (n <= 1)
            return n;
        return fibo(n - 1) + fibo(n - 2);
    }

    void display()
    {
        System.out.println("Fibonacci series from " + start + " to " + end + ":");
        int i = 0, t = fibo(0);
        while (t <= end)
        {
            if (t >= start)
                System.out.print(t + " ");
            i++;
            t = fibo(i);
        }
        System.out.println();
    }

    public static void main(String[] args)
    {
        Fibo ob = new Fibo();
        ob.read();
        ob.display();
    }
}
fibo(n) is recursive: fibo(0) = 0, fibo(1) = 1, otherwise the sum of the previous two terms. display() prints the terms that lie between start and end. Sample run: start 2, end 50 gives 2 3 5 8 13 21 34.
Q6(ii)6 marks · ProgramOpen: A class Gcd has been defined to find the Greatest Common Divisor of two integer…

Write the program described below.

A class Gcd has been defined to find the Greatest Common Divisor of two integer numbers. Some of the members of the class are given below: Class name: Gcd Data member/instance variable: num1: integer to store the first number num2: integer to store the second number Member functions/methods: Gcd(): default constructor void accept(): to accept the numbers int gcd(int x, int y): return the GCD of the two numbers x and y using recursive technique void display(): displays the result with an appropriate message Specify the class Gcd, giving details of the Constructor, void accept(), int gcd(int, int), and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.
Show answer

Answer

import java.util.*;
class Gcd
{
    int num1, num2;

    Gcd()
    {
        num1 = 0;
        num2 = 0;
    }

    void accept()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter first number: ");
        num1 = sc.nextInt();
        System.out.print("Enter second number: ");
        num2 = sc.nextInt();
    }

    int gcd(int x, int y)
    {
        if (y == 0)
            return x;
        return gcd(y, x % y);
    }

    void display()
    {
        System.out.println("GCD of " + num1 + " and " + num2 + " = " + gcd(num1, num2));
    }

    public static void main(String[] args)
    {
        Gcd ob = new Gcd();
        ob.accept();
        ob.display();
    }
}
The recursive method uses Euclid's algorithm: gcd(x, y) = gcd(y, x % y) until y becomes 0. Sample run: 48 and 18 gives 6.
Q74 marks · ProgramOpen: A super class Godown has been defined to store the details of the stock of a…

Write the program described below.

A super class Godown has been defined to store the details of the stock of a retail store. Define a subclass Update to store the details of the items purchased with the new rate and update the stock. Some of the members of both the classes are given below: Class name: Godown Data members/instance variables: item: to store the name of the item qty: to store the quantity of an item in stock rate: to store the unit price of an item amt: to store the net value of the item in stock Member functions/methods: Godown(...): parameterized constructor to assign value to the data members void display(): to display the stock details Class name: Update Data members/instance variables: pur_qty: to store the purchase quantity pur_rate: to store the unit price of the purchased item Member functions/methods: Update(...): parameterized constructor to assign values to the data members of both the classes void update(): to update the stock by adding the previous quantity by the purchased quantity and replace the rate of the item if there is a difference in the purchase rate. Also update the current stock value as: $(quantity * unit\ price)$ void display(): to display the stock details before and after updating Assume that the super class Godown has been defined. Using the concept of inheritance, specify the class Update giving details of the constructor, void update() and void display(). The super class, main function and algorithm need NOT be written.
Show answer

Answer

class Update extends Godown
{
    int pur_qty;
    double pur_rate;

    Update(String i, int q, double r, int pq, double pr)
    {
        super(i, q, r);
        pur_qty = pq;
        pur_rate = pr;
    }

    void update()
    {
        qty = qty + pur_qty;
        if (rate != pur_rate)
            rate = pur_rate;
        amt = qty * rate;
    }

    void display()
    {
        System.out.println("Stock before updating:");
        super.display();
        update();
        System.out.println("Stock after updating:");
        super.display();
    }
}
The constructor passes the stock details to Godown using super(). update() adds the purchased quantity, replaces the rate if it differs and recomputes the stock value as quantity * rate. display() shows the stock before and after the update. (Assumes rate and amt are double and qty is int in Godown.)
Q84 marks · ProgramOpen: A Queue is a linear data structure in which the operations are performed based…

Write the program described below.

A Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out). Define a class Queue with the following details: Class name: Queue Data member/instance variable: dat[]: array to hold the integer elements cap: stores the maximum capacity of the queue front: to point the index of the front rear: to point the index of the rear Member functions/methods: Queue(int max): constructor to initialize the data member cap = max, front = rear = 0 and create the integer array void add_dat(int v): to add integers from the rear index if possible else display the message (“Queue full”) int pop_dat(): to remove and return elements from front, if any, else returns -999 void display(): to display elements of the queue Specify the class Queue giving the details of void add_dat(int) and int pop_dat(). Assume that the other functions have been defined. The main() function and algorithm need NOT be written.
Show answer

Answer

void add_dat(int v)
{
    if (rear < cap)
    {
        dat[rear] = v;
        rear++;
    }
    else
        System.out.println("Queue full");
}

int pop_dat()
{
    if (front == rear)
        return -999;
    int v = dat[front];
    front++;
    return v;
}
Elements are added at index rear while rear is less than cap; otherwise "Queue full" is displayed. Elements are removed from index front, and -999 is returned when the queue is empty (front equals rear).

About this specimen paper

The ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1 is a specimen paper for Class 12: 17 questions in printed order, 35 marks in all, asked from 5 chapters. A specimen paper is the sample question paper CISCE publishes before the exam to show the layout and style of that year’s paper. It is a good guide to the pattern you will meet.

The layout of the current Computer Science paper (sections, marks, choices) is in the paper pattern guide.

By section

SectionQuestionsMarks printed*
A77
B48
C632

By kind of question

KindQuestionsMarks printed*
Program632
Binary tree24
MCQ33
Short answer33
Differentiate12
Conversion12
Output11

By chapter

ChapterQuestionsMarks printed*
Recursion516
Objects212
Data structures511
Inheritance, Interfaces and Polymorphism36
Arrays, Strings22

* Marks are those printed on each question; where a question offers an either-or choice, both options are counted, so the totals can come to more than the paper’s own total.

Common questions

How many questions are in the ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1?

17 questions, 35 marks in all, shown in full and in printed order on this page.

Which chapters does the ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1 ask most about?

By number of questions: Recursion (5), Data structures (5), Inheritance, Interfaces and Polymorphism (3) and Objects (2).

Does this page have the answers to the ISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1?

Tap “Show answer” under a question to see its answer. The download button saves the paper as a PDF, with or without the answers.