ICSE Class 10 Computer Application Solved Question Paper Year 2012


COMPUTER APPLICATIONS ICSE – 2012
(Theory)
(Two Hours)

Answer to this paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given on the head of this paper is the time allowed for writing the answer.
This Paper is divided into Sections.
Attempt all questions from Section A and any four from Section B.
The intended marks for questions or parts of questions are given in brackets [ ]

SECTION A (40 MARKS)

Attempt all questions

Question 1

  1. Marks [2]

    Give one example each of a primitive data type and a composite data type.
    Ans. E.g. of primitive data type is ‘int’. E.g. of Composite data type is class.

  2. Marks [2]

    Give one point of difference between unary and binary operators.
    Ans. Unary operator – Operators that act on one operand are referred to as unary operator.
    Binary operator – Operator which requires two operands for their purpose are called Binary operators.

  3. Marks [2]

    Differentiate between call by value or pass by value and call by reference or pass by reference.
    Ans. In call by value, the called-function creates its own work copy for the passed parameters and copies the passed values in it. Any changes that take place remain in the work copy and the original data remains intact.
    In call by reference, the called-function receives the reference to the passed parameters and through this reference, it accesses the original data. Any changes that take place are reflected in the original data.

  4. Marks [2]

    Write a Java expression for mathematical expression

    Ans. double v = Math.sqrt (2 * a * s + u * u);

  5. Marks [2]

    Name the type of error (syntax, runtime or logical error) in each case given below:

    1. Division by a variable that contains a value of zero.
    2. Multiplication operator used when the operation should be division,
    3. Missing semicolon.

    Ans.

    1. Run time error,
    2. Logical error,
    3. Syntax error.

Question 2

  1. Marks [2]

    Create a class with one integer instance variable. Initialize the variable using:

    1. default constructor,
    2. parameterised constructor.

    Ans.

    1. class const
      {
      int i;
      public const ( )
      {
      i = 10;
      }
      }
      
    2. class const
      {
      int i;
      public const (int a)
      {
      i = a;
      }
      }
      
  2. Marks [2]

    Complete the code below to create an object of Scanner class.
    Scanner sc = ____________ Scanner(__________________)
    Ans. Scanner sc = new Scanner (System.in);

  3. Marks [2]

    What is an array? Write a statement to declare an integer array of 10 elements.
    Ans. An array is a collection of variables of the same type that are referenced by a common name.
    int array [ ] = new int [10];

  4. Marks [2]

    Name the search or sort algorithm that:

    1. Makes several passes through the array, selecting the next smallest item in the array each time and placing it where it belongs in the array.
    2. At each stage, compares the sought key value with the key value of the middle element of the array.

    Ans.

    1. Selection sort,
    2. Binary Search.
  5. Marks [2]

    Differentiate between public and private modifiers for members of a class.
    Ans. ‘public modifiers’ – It allows the data member visible to all classes outside the class in which it is defined, even in other packages.
    Syntax
    public data type data members
    E.g. – public int a, b, c ;
    ‘private modifiers’ – The private members are accessible only within the class in which they are defined They cannot be inherited to derived classes.
    Syntax
    private data type data members
    E.g. – private int sum ;

Question 3

  1. Marks [2]

    What are the values of x and y when the following statements are executed?
    Int a = 63, b = 36;
    boolean x = (a>b)? true : false;
    int y = (a<b)? a : b;
    Ans. x = true
    y = 36

  2. Marks [2]

    State the Values of n and ch.
    char c = Ar;
    int n = c * l;
    char ch = (char)n;
    Ans. n = 66
    ch = B

  3. Marks [2]

    What will be the result stored in x after evaluating the following expression?
    int x = 4;
    x+ = (x++) + (++x) + x;
    Ans. x = 20

  4. Marks [2]

    Give the output of the following program segment:
    double x = 2.9, y = 25;
    System.out.println(Math.min(Math.floor(x),y));
    System.out.println(Math.max(Math.ceil(x),y));
    Ans. Output will be:
    2.0
    3.0

  5. Marks [2]

    State the output of the following program segment.
    String s = “Examination”;
    int n= s.length( );
    System.out.println(s.startsWith(s.substring(5, n)));
    System.out.println(s.charAt(2) = = s.charAt(6));
    Ans. Output will be:
    False
    True

  6. Marks [2]

    State the method that:

    1. Converts a string to a primitive float data type
    2. Determines if the specified character is an uppercase character.

    Ans.

    1. Sting v = input.read Line ( );
      float f = float.parseFloat (v);
    2. if (Character.IsUpper Case( P’);
      Where, P is a character constant.
  7. Marks [2]

    State the data type and values of a and b after the following segment is executed.
    String s1 = “Computer”, s2 = “Applications” ;
    a = (s1.compareTo(s2));
    b = (s1 .equals(s2));
    Ans. a = 2 (Integer data type)
    B = false (Boolean data type)

  8. Marks [2]

    What will the following code output?
    String s = “mplqy?hrp”;
    System.out.println(s.indexOf(‘m’));
    System.out.println(s.lastlndexOf(‘m’));
    Ans.

  9. Marks [2]

    Rewrite the following program segment using while instead of for statement

    int f = 1, i;
    for(i = 1; i<= 5; i++)
    {
    f *= i;
    System.out.println(f);
    }
    

    Ans.

    int f = 1, i = 1 ;
    while (f =5)
    {
    f = f * i;
    i =I + l;
    System.out.println(f);
    }
    

    Although not asked for but the output of the code snippet would be:
    1
    2
    6
    24
    120

  10. Marks [2]

    In the program given below, state the name and the value of the

    1. method argument or argument variable
    2. class variable
    3. local variable
    4. instance variable
      class myClass
      {
      static int x=7;
      int y = 2;
      public static void main(String args[])
      {
      myClass obj = new myClass( );
      System.out.println(x);
      obj.sampleMethod(5);
      int a=6;
      System.out.println(a);
      }
      void sampleMethod(int n)
      {
      System.out,println(n);
      System.out.println(y);
      }
      }
      

    Ans.

    1. Argument variable = n and value is 5
    2. Class variable is x = 7
    3. Local variables is a = 6
    4. Instance variable is y = 2

SECTION B (60 MARKS)

Attempt any four questions from this Section.
The answers in this Section should consist of the Programs in either Blue J
environment or any program environment with Java as the base.
Each program should be written using Variable description/Mnemonic Codes
so that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required.

Question 4

Marks [15]

Define a class called Library with the following description:
Instance variables/data members:
int acc_ num – stores the accession number of the book.
String title – stores the title of the book.
String author – stores the name of the author.
Member methods:

  1. void input ( ) To input and store the accession number, title and author,
  2. void compute ( ) To accept the number of days late, calculate and display the fine charged at the rate of ` 2 per day.
  3. void display ( ) To display the details in the following format:
    Accession Number Title Author
    ————— ——- ——–

Write a main method to create an object of the class and call the above member methods.
Ans.

import java.io.*;
class Library
{
int acc_num, d;
String title, author;
int f = 0;
public Library()
{
acc_num = 0;
title = "";
author = "";
}
public void input( )throws IOException
{
InputStreamReader read = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (read);
System.out.println(" Enter the accession number of the book: ");
acc_num = Integer.parseInt(br.readLine ( ));
System.out.println(" Enter the name of the author: ");
author = br.readLine( );
System.out.println(" Enter the book title: ");
title = br.readLine( );
System.out.println(" Enter no.of days late: ");
d = Integer.parseInt(br.readLine());
}
public void compute( )
{
f = d * 2 ;
System.out.println(" Fine = " +f);
}
public void display( )
{
System.out.println(" Accession Number " +"\t" +" Title " +"\t" +"Author" );
System.out.println(acc_num +"\t" +title +"\t" +author);
}
public static void main (String args [ ]) throws IOException
{
Library lib = new Library();
lib.input();
lib.compute();
lib.display();
}
}

Question 5

Marks [15]

Given below is a hypothetical table showing rates of Income Tax for male citizens below the age of 65 years:

 Taxable Income (TI) in Income Tax in
Does exceed 1,60,000 Nil
Is greater than 1, 60,000 & less than or equal to 5,00,000 (TI – 1,60,000) x 10%
Is greater than 5,00,000 & less than or equal to 8,00,000 [(TI – 5,00,000) x 20%] + 34,000
Is greater than 8,00,000 [(TI – 8,00,000) x 30%] + 94,000

Write a program to input the age, gender (male or female) and Taxable Income of a person.
If the age is more than 65 years or the gender is female, display “wrong category”.
If the age is less than or equal to 65 years and the gender is male, compute and display the Income Tax payable as per the table given above.
Ans.

import java.io.*;
class Tax
{
public static void main(String[] args)throws IOException
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
int age;
char gender;
int taxableIncome;
String temp = "";
System.out.print(" Enter the age: ");
age = Integer.parseInt(read.readLine( ));
System.out.print(" Enter gender: ");
gender = (char)read.read( );
read.readLine( );	//for the trailing newline
temp = temp + gender;
temp = temp.toUpperCase( );
gender = temp.charAt(0);
System.out.print(" Enter taxable income: ");
taxableIncome = Integer.parseInt(read.readLine());
if( (age > 65) || (gender != 'M') )
System.out.println("wrong category");
else
{
double incomeTax = 0.0;
if( (taxableIncome > 160000) && (taxableIncome <= 500000) )
incomeTax = (taxableIncome - 160000)*0.1;
else if( (taxableIncome > 500000) && (taxableIncome <= 800000) )
incomeTax = (taxableIncome - 500000) * 0.2 + 34000;
else if( taxableIn	come > 800000 )
incomeTax = (taxableIncome - 800000) * 0.3 + 94000;
System.out.println(" Income tax payable: " + incomeTax);
}
}
}

Question 6

Marks [15]

Write a program to accept a string. Convert the string to uppercase. Count the number and output the double letter sequences that exist in the string.
Sample Input: “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output: 4
Ans.

import java.io.*;
class sequence
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader (System.in);
BufferedReader input = new BufferedReader (read);
String s,si;
int i, j, l, count = 1, dCount = 0;
char c, cl;
System.out.print(" Enter the sentence: ");
s = input.readLine( );
si = s.toUpperCase( );
l = si.length( );
for(i = 0; i<l-1; i++)
{
c = si.charAt(i);
cl = si.charAt(i+1);
if(c == cl)
count = count + 1;
if(count == 2)
{
System.out.println (" Double letter sequence of " +c +" that exist in the string");
dCount = dCount +1;
}
count = 1;
}
System.out.println (" Number of Double letter sequence presents in the string is: " +dCount);
}
}

Question 7

Marks [15]

Design a class to overload a function polygon( ) as follows:

  1. void polygon(int n, char ch) – with one integer argument and one character type argument that draws a filled square of side n using the character stored in ch.
  2. void polygon(int x, int y) – with two integer arguments that draws a filled rectangle of length x and breadth y, using the symbol ‘@’
  3. void polygon( ) – with no argument that draws a filled triangle shown below.
    Example:

    1. Input value of n = 2, ch = ‘O’
      Output:
      OO
      OO
    2. Input value of x = 2, y = 5
      Output:
      @@@@@
      @@@@@
    3. Output:
      *
      **
      ***

Ans.

import java.io.*;
class PatternOverload
{
// overloaded function 1
public static void polygon(int n, char ch)
{
System.out.println("Overloaded method #1");
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
System.out.print(ch);
System.out.println( );
}
}
// overloaded function 2
public static void polygon(int n, int y)
{
System.out.println("Overloaded method #2");
for(int i=1; i <= n; i++)
{
for(int j = 1; j <= y; j++)
System.out.print("@");
System.out.println( );
}
}
// overloaded function 3
public static void polygon()
{
System.out.println("Overloaded method #3");
for(int i=1; i <= 3; i++)
{
for(int j = 1; j <= i; j++)
System.out.print("*");
System.out.println( );
}
}
public static void main(String[] args)throws IOException
{
int N, X, Y;
char CH;
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader br = new BufferedReader(read) ;
System.out.print(" Enter Side for 1st Rectangle: ");
N = Integer.parseInt(br.readLine( ));
System.out.print(" Enter a character for Fill: ");
CH = (char)br.read( );
br.readLine( );
System.out.print(" Enter Length for 2nd Rectangle: ");
X = Integer.parseInt(br.readLine( ));
System.out.print(" Enter Breadth for Fill: ");
Y = Integer.parseInt(br.readLine ( ));
PatternOverload.polygon(N, CH);
PatternOverload.polygon(X, Y);
PatternOverload.polygon();
}
}

Question 8

Marks [15]

Using the switch statement, write a menu driven program to:

  1. Generate and display the first 10 terms of the Fibonacci series
    0, 1, 1, 2, 3, 5, …
    The first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two.
  2. Find the sum of the digits of an integer that is input.
    Sample Input: 15390
    Sample Output: Sum of the digits: 18
    For an incorrect choice, an appropriate error message should be displayed.

Ans.

import java.io.*;
class MenuDriven
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader br = new BufferedReader(read) ;
int ch;
System.out.println(" Menu") ;
System.out.println(" 1. Fibonacci series upto 10") ;
System.out.println(" 2. Sum of the digit") ;
System.out.print(" Enter your choice: ") ;
ch = Integer.parseInt(br.readLine ( ));
switch (ch)
{
case 1:
int c, a = 0, b = 1;
System.out.println(" Choosen Fibonacci series:-") ;
System.out.print(a +", ");
System.out.print(b +", ");
for(int i = 3; i <= 10; i++)
{
c = a + b;
System.out.print(c +", ");
a = b;
b = c;
}
break;
case 2:
int n, r, s = 0;
System.out.println(" Choosen Sum of Digits:-") ;
System.out.print(" Enter a number: ") ;
n = Integer.parseInt(br.readLine ( ));
whi	le (n != 0)
{
r = n % 10;
s = s + r;
n = n / 10;
}
System.out.println(" Sum of the digits = " +s);
break;
default :
System.out.println("Incorrect option. Try again...");
}
}
}

Question 9

Marks [15]

Write a program to accept the names of 10 cities in a single dimension string array and their STD (Subscribers Trunk Dialing) codes in another single dimension integer array. Search for a name of a city input by the user in the list’ if found, display “search Successful” and print the name of the city along with its STD code, or else display the message “search Unsuccessful, No such city in the list”
Ans.

import java.io.*;
class SearchSTD
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
int max = 3;
int i, flag = 0;
String name[ ] = new String[max];
int STD[ ] = new int[max] ;
System.out.println("Enter names and STD of 10 cities:-") ;
for(i = 0; i<max; i++)
{
System.out.print(" Enter City: " );
name[i] = input.readLine( );
System.out.print(" Enter STD code: " );
STD[i] = Integer.parseInt(input.readLine( ));
}
System.out. print(" Enter the name of a city to be reached: ") ;
String n= input.readLine( );
n = n.toUpperCase( );
for (i = 0; i < max; i++)
{
if(n.equals(name[i].toUpperCase( )) == true)
{
flag = 1;
break;
}
}
if(flag == 1)
{
System.out.println(" search Successful ");
System.out.println(" Name " +n);
System.out.println( " STD Code = " +STD[i]);
}
else
{
System.out.println (" Search Unsuccessful");
System.out.println (" Name not enlisted") ;
}
}
}

Add a Comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.