ICSE Question Paper – 2012 (Solved)
Computer Applications
Class X
(Time: Two Hours)
SECTION A (40 Marks)
Answer all questions from this Section
Question 1.
(a)Give one example of a
primitive data type and composite data type. [2]
Ans. Primitive type: byte/short/int/long/float/double/char/boolean
Composite type: classes/interface/arrays
(b) Give
one point of difference between unary and binary operators. [2]
Ans. Unary operators work on a single
operand eg. ++a while binary operators work on two operands eg. a+b
© Differentiate
between call by value or pass by value and call by reference or pass by
reference [2]
Ans. Call by value method creates a new
copy of formal parameters and the changes made to them in the called function
are not reflected on the actual arguments in the calling function. They work
for primitive data types while call by reference method does not create a new
copy rather works on the reference of actual arguments and changes made to them
in the called function are reflected in the calling function. They work for reference
data types.
(d) Write
java expression for √2as+u2 [2]
Ans. double d=
Math.sqrt((2*a*s + u*u));
(e) Name
the type of error (syntax, runtime or logical error) in each case given
below: [2]
Ans. (i) Division by a variable that
contains a value of zero : Runtime
error
(ii) Multiplication operator used when
the operation should be division : Logical
error
(iii) Missing semicolon: Syntax error
Question 2.
(a)
Create a class with one integer instance
variable. Initialize the variable using :
(i) Default constructor
(ii) parameterized constructor
Ans.
class
Initialize
{
int
x; //instance variable
Initialize()
//default constructor
{
x=0;
}
Initialize(int
a) //parameterized constructor
{
x=a;
}
}
(b) Complete
the code given below to create an object of Scanner class: [2]
Ans. Scanner sc=new
Scanner (System.in);
© What
is an array? Write a statement to declare an integer array of 10 elements [2]
Ans. An array is a structure
created in memory to store multiple similar type of data under a single
subscripted variable name.
int
a[]=new int[10];
(d) Name
the search or sort algorithm that : [2]
(i) 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 : Selection
sort
(ii) At each stage, compares the sought
key value with the key value of the middle element of the array: Binary search
(e) Differentiate
between public and private modifiers for members of a class [2]
Ans. The scope of private members of a
class is within the class itself whereas the the scope of the public members of
a class is outside the class also ( outside the package also).
Question 3.
(a) What
are the values of x and y when the following statements are executed? [2]
int a=63, b=36;
boolean x = (a>b) ? true :
false ;
int y=(a<b) ? a : b;
Ans.
x=true
y=36
(b) State the values of n and ch. [2]
char
c=’A’;
int
n=c+1;
char
ch=(char)n;
Ans.
n=66 ,
ch=B
© What
will be the result stored in x after evaluating the following expression? [2]
int
x = 4;
x+=
(x++)+(++x)+x;
Ans.
x=4+4+6+6
=20
(d) Give
output of the following program segment: [2]
double
x= 2.9 , y=2.5;
System.out.println(Math.min(Math.floor(x),y));
System.out.println(Math.max(Math.ceil(x),y));
Ans.
2.0
3.0
(e) State
the output of the following program segment: [2]
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.
false
true
(f) State
the method that: [2]
(i)
Converts a string to a primitive float data type : parseFloat()
(ii) Determines if the specified character is an upper case character: isUpperCase()
(g) State the data type and values of a and b after the following segment
is executed: [2]
String s1= “Computer”,
s2=“Applications”;
a = (s1.compareTo(s2));
b = (s1.equals(s2));
Ans. a=2 or
positive data type
: int
b=
false data type
: boolean
(h) What will the
following code output: [2]
String s= “malayalam”;
System.out.println(s.indexOf(‘m’));
System.out.println(s.lastIndexOf(‘m’));
Ans.
0
8
(i) Rewrite
the following program segment using while instead of for statement[2]
int f=1,I;
for(i=1; i<=5; i++)
{
f*=i; System.out.println(f);}
Ans.
int
f=1, i=1;
while
(i<=5)
{
f*=i
System.out.println(f);
i++;
}
(j) In the program given below:
[2]
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);
}
}
State
the name and value of the :
(i) method argument or argument
variable: 5
(ii) class variable : x
(iii) local
variable: a
(iv) instance variable : y
SECTION B(60 Marks)
Answer
any four questions
Also write the variable description/pneumonic codes
Question 4.
Define a class called Library with the
following description:
Instance variables/data members:
Int
acc_num : stores the accession
number of books
String
title :
stores the title of book
String
author : stores the name of
author
Member methods:
Void input() : to input and store
the accession number, title and author
Void compute(): to accept the
number of days late, calculate and display the fine charged t the rate of Rs. 2
per day
Void display(): to display
the details in the following format:
Accession
number
Title Author
Write the main method to create an
object of the class and call the above member
methods
[15]
Ans
import
java.util.*;
class
Library {
int
acc_num;
String
title, author;
void
input {
Scanner
sn=new Scanner(System.in);
System.out.println(“enter
the accession number, title and author”);
acc_num=
sn.nextInt();
title=
sn.nextLine();
author
= sn.nextLine();
}
void
compute() {
Scanner
sn=new Scanner(System.in));
System.out.println(“enter
the number of days late”);
int
n= sn.nextInt();
int
fine=n*2;
System.out.println(“fine
: “+fine);
}
void
display() {
System.out.println(“Accession
Number \t\t Title \t\t Authpr”);
System.out.println(“acc_num+”\t\t”+title+”\t\t”+
author);
}
public
static void main() throws IOException
{
Library
ob=new Library();
ob.input();
ob.
compute();
ob.display();
}
}
Question 5.
Given below is a hypothetical table
showing rates of income tax for male citizens below the age of 65 yrs:
Does not exceed Rs.
1,60,000 -nil
TI > Rs. 1,60,000 & <=Rs.
50,000 –
(TI- 1,60,000)*10%
TI
>Rs.5,00,000 & <=Rs. 8,00,000 -
[(TI-5,00,000)*20%]+34,000
TI >Rs. 8,00,000 –
[(TI-8,00,000)*30%]+94,000
Write a program to input the age,
gender(male or female) and taxable income(TI) of a person.
If the age is more than 65 yrs or the
gender is female, display “wrong category”.
If the age is less than or equal to 65
yrs and the gender is male, compute and display the income tax payable as
per the table given above. [15]
Ans.
import
java.util.*;
class
IncomeTax {
public
static void main(){
Scanner
sn=new Scanner(System.in);
System.out.println(“enter
age, gender and taxable income”);
int
age=sn.nextInt();
String
gender= sn.next();
int
TI= sn.nextInt();
double
tax=0.0;
if((age>65)
|| (gender.equals(“female”)))
System.out.println(“wrong
category”);
else
if((age<=65) && (gender.equals(“male”)))
{
if(TI<160000)
tax=0;
else
if(TI>160000 && ti<=500000)
tax=(TI-160000)*(double)10/100*TI;
else
if(TI>500000 && TI<=800000)
tax=(TI-500000)*((double)20/100*TI)+34000;
else
tax=(TI-800000)*((double)30/100*TI)+94000;
}
else
System.out.println(“wrong
category”);
}//main
ends
}
//class ends
Question 6.
Write a program to accept a string.
Convert it to uppercase. Count and output the number of double letter sentences
that exist in the string. [15]
Sample Input: “SHE
WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample Output: 4
Ans.
class DoubleLetter {
void
count(String s1) {
s=s1.toUpperCase();
int
l=s.length();
int
c=0;
for(
int p=0; p<l-1; p++)
{
if(s.charAt(p)
== s.charAt(p+1))
c++;
}//for
ends
System.out.println(
c );
}//method
ends
}//class
ends
Question 7.
Design a class to overload a function
polygon() as follows: [15]
(i) 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.
(ii) void polygon(int x, int y) :
with two integer arguments that draws a filled rectangle of length x and
breadth y, using the symbol ‘@’
(iii) void polygon() : with no
argument that draws a filled triangle shown below:
*
* *
* * *
Ans.
class
Overload {
void
polygon(int n , char ch) {
for
(int p= 1; p<=n; p++)
{
for(int
q=1; q<=n; q++)
System.out.print(ch);
System.out.println();
}
}//method
ends
void
polygon(int x, int y) {
for(int
p = 1; p<=x; p++)
{
for
( int q=1; q<=y; q++)
System.out.print(“@”);
System.out.println();
}
}//method
ends
void
polygon() {
for(int
p= 1; p<=3; p++)
{
for(
int q=1; q<=p; q++)
System.out.print(“*”);
System.out.println();
}
}//method
ends
}//class
ends
Question 8.
Using the switch statement, write a
menu-driven program to:
(i) Generate and display the first 10
terms of the Fibonacci series 0,1,1,2,3,5,….
(ii) find the sum of the digits of an
integer that is input. Eg 15390=18
For an incorrect choice, appropriate
error message should be displayed. [15]
Ans.
import
java.io.*;
class
Menudriven {
public
static void main()
{
Scanner
sn=new Scanner(System.in);
System.out.print(“Enter
1 for Fibonacci numbers/ 2 for sum of digits”);
int
ch=sn.next();
switch(
ch)
{
case
1:
int
a=0, b=1, c;
System.out.print(a+
“ “+ b);
for(int
p=3; p<=10; p++)
{
c=a+b;
System.out.print(“
“+c);
a=b;
b=c;
}//for
ends
break;
case
2:
System.out.println”\nenter
an integer”);
int
n = sn.nextInt();
int
quo=0,rem=0, sum=0;
while(quo!=0)
{
rem%=10;
quo/=10;
sum+=rem;
}//while
ends
System.out.println(“\nsum
of digits “+sum);
break;
default:
System.out.println(“
Incorrect choice. Enter 1 or 2 only”);
}//switch
ends
}//main
ends
}//class
ends
Question 9.
Write a program to accept the names of
10 cities in a single dimension string array and their STD 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”. [15]
Ans.
import
java.io.*;
class
LinearSearch {
public static void main()
{
Scanner
sn=new Scanner(System.in);
String
city[] =new String[10];
int
std[]=new int[10];
for(int
i=0;i<10;i++)
{
System.out.println(“enter
city and std code”);
city[i]=sn.next();
std[i]=sn.nextInt();
}
System.out.print(“Enter
the city to be searched”);
String
ele = sn.next();
int
c=0;
for(int
p=0; p<10; p++)
{
if(city[p]
. equals(ele))
{
c=1;
break;
}
//end if
}//end
for
if(c==1)
{
System.out.print(“Search
Successful”);
System.out.print(“City:
“+city[p]+”\tSTD :”+std[p]);
}
else
System.out.print(“Search
Unsuccessful. No such city in the list”);
}//end
method
}//end
class