Section – C

### ISC Computer Science 2010 Class-12 Previous Year Question Paper Solved

• Each program /Algorithmshould is written in such a way that it clearly depicts the logic of the problem stepwise.
• This can be achieved by using pseudo-codes.
• Flowcharts are not required
• The programs must be written in Java.
• The Algorithm must be written in general/standard form.

Question 11.
A superclass Worker has been defined to store the details of a worker. Define a subclass Wages to compute the monthly wages for the worker. The details/specifications of both the classes are given below:
Class name: Worker
Data Members/instance variables:
Name: to store the name of the worker
Basic: to store the basic pay in decimals
Member functions:
Worker (…): Parameterised constructor to assign values to the instance variables
void display (): display the worker’s details
Class name: Wages
Data Members/instance variables:
hrs: stores the hours worked
rate: stores rate per hour
wage: stores the overall wage of the worker
Member functions:
Wages (…): Parameterised constructor to assign values to the instance variables of both the classes
double overtime (): Calculates and returns the overtime amount as (hours*rate)
void display (): Calculates the wage using the formula wage = overtime amount + Basic pay and displays it along with the other details
Specify the class Worker giving details of the constructor () and void display ( ). Using the concept of inheritance, specify the class Wages giving details of constructor ( ), double-overtime () and void display (). The main () function need not be written.

```importjava.io.*;
class worker
{
String Name;
double Basic;
public worker (String n, double b)
{
Name = n;
Basic = b;
}
public void display ( )
{
System.out.println (Name);
System.out.println (Basic);
}
}
class wages extends worker
{
int hrs, rate;
double wage
public wage (string n, double b, int h, int r, double w)
{
super (n, b);
hrs = h;
rate = r;
wage = w;
}
public double overtime ()
{
return (hours*rate);
}
public void display ( )
{
super.display ();
wage = overtime () + Basic;
System.out.prinln(wages);
}
}```

Question 12.
Define a class Repeat which allows the user to add elements from one end (rear) and remove elements from the other end (front) only.
The following details of the class Repeat are given below:
Class name: Repeat
Data Members/instance variables:
st[]: an array to hold a maximum of 100 integer elements
cap: stores the capacity of the array
f: to point the index of the front
r: to point the index of the rear
Member functions:
Repeat (int m): constructor to initialize the data members cap = m, f = 0, r = 0 and to create the integer array
void pushvalue (int v): to add integer from the rear index if possible else display the message (“OVERFLOW”)
int popvalue (): to remove and return element from the front. If array is empty then return -9999
void disp (): Displays the elements present in the list
(a) Specify the class Repeat giving details of the constructor (int), member function void pushvalue (int). int popvalue () and void disp (). The main ( ) function need not be written. [8] (b) What is the common name of the entity described above? [1] (c) On what principle does this entity work? [1] Answer 12:

(a)

```import java.io.*;
Class Repeat
{
intan [];
int cap, f, r;
public Repeat (int m)
{
cap = m;
f=0;
r=0;
an [ ] = new int[100];
}
public void pushvalue (int v)
{
if (r = = cap)
{
Systemout.println ("OVERFLOW");
}
else if (f = = 0)
{
f = 1;
}
else
{
an [r++] = v;
}
}
public int popvalue ( )
{
if (f == 0)
{
System.out.println (-9999);
}
elseif(f=r)
{
f=0; r = 0;
}
else
{
return (an [f++]);
}
}
public void display ( )
{
for (i = f; i< = r; i ++)
System.outprintln (an [ i ];
}```

(b) Queue
(c) It works on first in first out Principle(FIFO).

Question 13.
(a) A linked list is formed from the objects of the class, [4]

```class ListNodes
{
int item;
ListNodes next;
}```

Write a method OR an algorithm to compute and return the sum of all integers items stored in the linked list. The method declaration is specified below:
int listsum(ListNodes start);
(b) What is Big ‘O’ notation? State its significance. [2] (c) Answer the following from the diagram of a Binary Tree given below:

(i) Name the parent of node E. [1] (ii) Write the postorder tree traversal. [1] (iii) Write the internal nodes of the tree. [1] (iv) State the level of the root of the tree. [1] Answer 13:
(a) Algorithm
Let P be a pointer of type listNodes.

1. P = start, sum = 0
2. Repeat steps 3, 4 while (P! = NULL)
3. sum = sum + P → item
4. P = P → next (end of step 2 loop)
5. Return sum (Print sum)

(b) Big ‘O’ notation: It is used to represent the complexity of algorithms e.g. O(n), O(n log n)
Significance: By using this notation one can compare the complexities of algorithms and can select the best algorithms under time or memory limitations.

(c)

(i) C is a parent of E
(ii) Postorder: FGDBHECA
(iii) internal nodes: A B C D E
(iv) level 1

-: End of ISC Computer Science 2010 Class-12 Solved Paper :-

Thanks