# ICSE Class 10 Computer Application Solved Question Paper Year 2009

COMPUTER APPLICATIONS ICSE – 2009
(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]

Why is a class called factory of objects?
Ans. The class is an object maker or object factory. It contains all the statements needed to create an object, its attributes, as well as the statements to describe the operations that the object will be able to perform.

2. Marks [2]

State the difference between a boolean literal and a character literal.
Ans.

 Boolean Literal Character Literal The Boolean type has two values, represented by the literals true and false, formed from ASCII letter. A character literal is one character enclosed in single quotes, as in ‘a’.
3. Marks [2]

What is the use and syntax of a ternary operator?
Ans. Ternary operator: Ternary operator is a shortcut conditional operator (?:) that stores a value depending upon a condition. This operator requires three operators.
Syntax
expression 1 ? expression 2 : expression 3
e.g.
c = a >b?a: c;

4. Marks [2]

Write one word answer for the following:

1. A method that converts a string to a primitive integer data type.
2. The default initial value of a boolean variable data type.

Ans.

1. parse (parse)
2. false
5. Marks [2]

State one similarity and one difference between while and for loop.
Ans. Similarity: Both are looping statements.
Difference: ‘for’ is used to repeat some Java statements when the numbers of iterations are known whereas while statement is used to repeat when number of iterations are not known.

## Question 2

1. Marks [2]

Write the function prototype for the function “sum” that takes an integer variable (x) as its argument and returns a value of float data type.
Ans. public static float sum (int x).

2. Marks [2]

What is the use of the keyword this?
Ans. When a member function is called, It is automatically passed on implicit argument that is a reference to the object that invoked the function.

3. Marks [2]

Why is a class known as composite data type?
Ans. A class is a construct that binds one or more primitive types together to be used as a single data type.
These primitive types integrated in the class can be of primitive type variables or primitive type methods.

4. Marks [2]

Name the keyword that:

1. is used for allocating memory to an array,
2. causes the control to transfer back to the method call.

Ans.

1. Subscript or Index
2. return
5. Marks [2]

Differentiate between pure and impure function.
Ans.

 Pure function Impure function A function that only returns a value without bringing about any change in the values being passed to it. e.g. static Boolean max (int a, int h) { if(a==b) return true; else return false; } A function that brings about a change in the argument that it receives. e.g. static void count(int n) { n.counter = n.counter; }

## Question 3

1. Marks [4]

Write an expression for

Ans. Math,pow((a+b),n)/(Math.sqrt(3)+b).

2. Marks [2]

The following is a segment of a program.

```x = 1;y = 1;
if(n>0)
{
x = x + l;
y = y - 1;
}
```

What will be the value of x and y, if n assumes a value

1. 1
2. 0?

Ans.

1. n = 1
x = 2, y = 0
2. n = 0
x= l, y= 1
3. Marks [2]

Analyze the following program segment and determine how many times the body of loop will be executed (show the working).

```x = 1;	y = 1;
while(x<=y)
{
y = y/x;
System.out.println(y);
}
```

Ans.

1. x = 5, y = 50
x< = y
y = 50/5 = 10
y = 10 y = 10/5 = 2
y = 2
Two times the body of loop will be executed. The output is
10
2
4. Marks [2]

When there are multiple definitions with the same function name, what makes them different from each other?
Ans. When there are multiple definitions with the same name, argument types make them different from each other.

5. Marks [2]

Give that int x[][] = { {2,4,6}, {3,5,7}};
What will be the value of x [1][0] and x [0][2]?
Ans. x[l][0] = 3
x[0][2] = 6

6. Marks [2]

Give the output of the following code fragment:
when

1. opn = ‘b’
2. opn = ‘x’
3. opn = ‘a’

switch(opn)

```{
case 'a':
System.out.println("Platform Independent");
break;
case 'b':
System.out.println("Object Oriented");
case 'c':
System.out.println("Robust and Secure");
break;
default:
System.out.println("Wrong Input")
}
```

Ans.

1. Output
object oriented
Robust and secure
2. Output
Wrong Input
3. Platform Independent
4. array [2] = 8
7. Marks [3]

Consider the following code and answer the questions that follow:

```class academic
{
int x,y;
void access( )
{
int a,b;
System.out.println("Object created");
}
}
```
1. What is the object name of class academic?
2. Name the class variables used in the program.
3. Write the local variables used in the program.
4. Give the type of function used and its name.

Ans.

1. student
2. x,y
3. a,b
4. call by reference and its name is access.
The above statement creates a new object called staff of the class Employee.
8. Marks [5]

Convert the following segment into an equivalent do loop.
int x,c;
for (x=10, c=20; c>=10; c = c – 2)
x++;
Ans.

```int x = 10;
int c = 20;
do
{
x++;
c=c-2;
}
while (c>=10);
```

# 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]

An electronics shop has announced the following seasonal discounts on the purchase of certain items.

 Purchase Amount in Rs. Discount on Laptop Discount on Desktop PC 0-25000 0.0% 5.0% 25001 – 57000 5.0% 7.5% 57001 – 100000 7.5% 10.0% More than 100000 10.0% 15.0%

Write a program based on the above criteria, to input name, address, amount of purchase and the type of purchase (L for Laptop and D for Desktop) by a customer. Compute and print the net amount to be paid by a customer along with his name and address.
(Hint: discount = (discount rate/100)* amount of purchase
Net amount = amount of purchase – discount)
Ans.

```import java.io.*;
class getDiscount
{
public static void main (String args [ ]) throws IOException
{
double d = 0.0,S = 0.0;
System.out.println("Enter Customer Details:-");
System.out.print("Name: ");
String name = input.readLine ( );
System.out.print("Amount of purchase: ");
String at = inpu	t.readLine ( );
int amt = Integer.parseInt (at);
System.out.println("Type of purchase:-");
System.out.print("Enter L for Laptop and D for Desktop: ");
char ch = (char)input.read ( );
ch = Character.toUpperCase(ch);
switch (ch)
{
case 'L':
if (amt <= 25000)
{
d = 00.00;
S = amt - d;
}
else if (amt >= 250001 && amt <= 57000)
{
d = 0.05 * amt;
S = amt - d;
}
else if (amt >= 57001 && amt <= 100000)
{
d = 0.075 * amt;
S = amt - d;
}
else
{
d = 0.1 * amt;
S = amt - d;
}
System.out.println("Name = " +name);
System.out.println("Purchase Amount = " +amt);
System.out.println("Discount Amount = " +d);
System.out.println("Payable Amount = " +S);
break;
case 'D':
if (amt <= 25000)
{
d = .05 * amt;
S = amt - d;
}
else if (amt >= 25001 && amt <= 57000)
{
d = .075 * amt;
S = amt - d;
}
else if (amt >= 57001 && amt <= 100000)
{
d =0.1 * amt;
S= amt-d;
}
else
{
d = 0.15 * amt;
S = amt - d;
}
System.out.println("Name = " +name);
System.out.println("Purchase Amount = " +amt);
System.out.println("Discount Amount = " +d);
System.out.println("Payable Amount = " +S);
break;
default:
System.out.println("No discount available");
}
}
}
```

## Question 5

Marks [15]

Write a program to generate a triangle or an inverted triangle till n terms based upon the user’s choice of triangle to be displayed.

 Example 1 Example 2 Type 1 for a triangle and Type 1 for a triangle and Type 2 for an inverted triangle 2 Type 2 for an inverted triangle 2 Input:  1 Input:  2 Enter the number of terms 5 Enter the number of terms 6 1 6 6 6 6 6 2 2 5 5 5 5 5 3 3 3 4 4 4 4 4 4 4 4 3 3 3 5 5 5 5 5 2 2 1

Ans.

```import java.io.*;
class triangle
{
public static void main(String args[]) throws IOException
{
int i, j;
System.out.println("l. For a triangle");
System.out.println("2. For an inverted triangle");
System.out.print("Enter the number of terms: ");
switch (ch)
{
case 1:
for(i =1; i <= n; i++)
{
for(j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println( );
}
break;
case 2:
for (i = n; i >= 1; i--)
{
for(j = 1; j <=i; j++)
{
System.out.print(i);
}
System.out.println( );
}
break;
default:
System.out.println("Wrong choice");
}
}
}
```

## Question 6

Marks [15]

Write a program to input a sentence and print the number of characters found in the longest word of the given sentence.
For example if S = “India is my country” then the output should be 7.
Ans.

```import java.io.*;
class StringS
{
int c,big;
String S;
public StringS( )
{
c = 0;
big = 0;
S = " ";
}
public void count(String s)
{
S = s + S;
char ch;
int i;
int l;
String w = "";
for(i = 0; i< S.length(); i++)
{
l=0;
ch = S.charAt(i);
if (ch != ' ')
w = w + ch;
else
{
l = w.length();
System.out.println("Word " +w +" Length " +l);
w = "";
if(l>big)
big = l;
}
}
System.out.println("The character count of longest word in the given sentence is: " +big);
}
public static void main(String args[]) throws IOException
{
System.out.print("Enter any string: ");
StringS charCount = new StringS();
charCount.count(str);
}
}
```

## Question 7

Marks [15]

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

1. void num_calc (int mini, char ch) with one integer argument and one character argument, computes the square of integer argument if choice ch is ‘s’ otherwise finds its cube.
2. void num_calc (int a, int b, char ch) with two integer arguments and one character argument. It computes the product of integer arguments if ch is ‘p’ else adds the integers.
3. void num_calc (String si, String s2) with two string arguments, which prints whether the strings are equal or not.

Ans.

```import java.io.*;
{
static void num_calc (int x, char y)
{
y = Character.toLowerCase(y);
if(y == 's')
System.out.println("The Square of the Number :" +(x*x));
else
System.out.println("The Cube of the Number :" +(x*x*x));
}
static void num_calc(int l, int m, char n)
{
n = Character.toLowerCase(n);
if (n == 'p')
System.out.println("The Product of two Number :" +(l*m));
else
System.out.println("The Addition of two Number :" +(l+m));
}
static void num_calc (String u, String v)
{
int d = u.compareTo(v);
if(d == 0)
System.out.println("Both Strings are equal");
else
System.out.println("Both Strings are different");
}
public static void main(String Args[])throws IOException
{
int num, a, b;
char ch;
System.out.println("Enter Number and Character to find Square/Cube");
System.out.print("Enter a Number: ");
System.out.print("Enter a Character: ");
num_calc (num, ch);
System.out.println("Enter Two Numbers and a Character to find its Product/Addition");
System.out.print("Enter 1st Number: ");
System.out.print("Enter 2nd Number: ");
System.out.print("Enter a Character: ");
num_calc (a, b, ch);
System.out.println("Enter Two to test Equality");
System.out.	print("Enter 1st String: ");
System.out.print("Enter 2nd String: ");
num_calc(S1, S2);
}
}
```

## Question 8

Marks [15]

Write a menu driven program to accept a number from the user and check whether it is a ‘BUZZ’ number or to accept any two numbers and print the ‘GCD’ of them.

1. A BUZZ number is the number which either ends with 7 or divisible by 7.
2. GCD (Greatest Common Divisor) of two integers is calculated by continued division method. Divide the larger number by the smaller; the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.

Ans.

```import java.io.*;
{
public static void main(String args[ ])throws IOException
{
int n, a, b, r = 0;
System.out.println("l. for BUZZ number");
System.out.println("2. for GCD");
switch (ch)
{
case 1 :
System.out.print("Enter a number: ");
r = a%10;
n = a%7;
if(r == 7 || n == 0)
System.out.println("BUZZ no. " +a);
else
System.out.println("Not a BUZZ no. " +a);
break;
case 2:
System.out.print("Enter 1st number: ");
System.out.print("Enter the 2nd number: ");
r = a%b;
while (r != 0)
{
a = b;
b = r;
r = a%b;
}
System.out.println("GCD = " +b);
default:
System.out.println("Wrong Choice");
}
}
}
```

## Question 9

Marks [15]

The annual examination results of 50 students in a class are tabulated as follows.
Roll no. Subject A Subject B Subject C
Write a program to read the data, calculate and display the following:

1. Average marks obtained by each student.
2. Print the roll number and average marks of the students whose average mark is above 80.
3. Print the roll number and average marks of the students whose average mark is below 40.

Ans.

```import java.io.*;
class AEresult
{
public static void main (String args[])throws IOException
{
int i;
int max = 50;
int R[] = new int[50];
int SA[] = new int[50];
int SB[] = new int[50];
int SC[] = new int[50];
int t[ ] = new int[50];
int avg[] = new int[50];
for (i = 0; i<max; i++)
{
System.out.print("Enter the Roll No. of student " +(i + 1) +" : ");
System. out.println("Enter 3 subject marks:- ");
t[i] = SA[i]+SB[i]+SC[i];
avg[i] = t[i]/3;
}
System.out.println ("Roll No.Subject A Subject B Subject C Total
Average");
for(i=0; i<max; i++)
{
System.out.println(R[i] +"\t\t" +SA[i] +"\t\t" +SB[i] +"\t\t" +SC[i] +"\t\t" +t[i] +"\t\t" +avg[i]);
}
System.out.println("Students whose average mark is above 80:-");
System.out.println("Roll No. Average");
for (i=0; i<max; i++)
{
if(avg[i]>80)
{
System.out.println( R[i] +"\t\t" +avg[i]);
}
}
System.out.println("Students whose average mark is below 40:-");
System.out.println("Roll No. Average");
for (i=0; i<max; i++)
{
if(avg[i]<40)
{
System.out.println( R[i] +"\t\t" +avg[i]);
}
}
}//End of main
}
```