ICSE 2009 Computer Application

ICSE 2009 COMPUTER APPLICATION

Answer to this ICSE 2009 Computer Application ICSE Board 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 at the head is the time allowed for writing the answer.

This paper is divided into two Sections. Answer all Questions from Section A and any four questions from Section B. The intended marks for questions or parts of questions are given in [].

SECTION A(40 Marks)
Attempt all questions.

Question 1.                                                      [10]
(a) Why is a class called a factory of objects?
Ans: Class is a set of objects, which contains a set of data items and related functions. As an object is a product of a class, hence class is referred as an Object factory.
(b) State the difference between a Boolean literal and a Character literal?
Ans: A boolean literal always of type boolean. It is either boolean value true or boolean value false. A character literal is one character enclodsed in single quotes, as in ‘z’. The character literal size is 16 bits (2 bytes), where as in boolean literal java reserved 8 bits but only use 1 bit.

(c) What is the use and syntax of ternary operator?
Ans: It is a conditional operator, that stores a value depending upon a condition. This operator is also known as ternary operator. The syntax for this operator is expression1?expression2:expression3 . and the example is bonus=sales>15000?250:50;
(d) Write one word for the following:
(i) A method that converts a string to a primitive integer data type.
(ii) The default initial value of a Boolean variable data type.
Ans:   (i) Integer.parseInt()      (ii)false

(e) State one similarity and one difference between while and for loop.
Ans: Similarity: Both the loops are pre-Tested (entry controlled), In both the loops the test expression is evaluated at the beginning.
Difference: The for loop should be preferred if number of iteration is known beforehand. The while loop should be preferred if the number iteration is dependent upon some control variable.

Question 2.                                                      [10]
(a) 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: float sum(int x)
(b) What is use of the keyword this?
Ans: The this keyword is used to refer to currently calling objects. The member functions of every objects have access to a sort of magic keyword name this, which points to the object itself. Thus any member function can find out the address of the object of which it is a member. The this keyword represents an object that invokes a member function. it stores the address of the object that invoking a member function and it is an implicit argument to the member function being invoked. The this keyword is useful in returning the object of which the function is a member.
(c) Why is a class known as composite data type?
Ans: A composite datatype is that datatype that are based on fundamental or primitive datatypes. A ‘class’ is an example of composite datatypes.
class Date
{
int dd, mm, yy;
public Date()
{
dd=1;
mm=1;
yy=2005;
}
}
Yes, we can refer to a class not having a main() method as composite datatype. Such classes containing main() method are more analogues to application than a datatype.

(d) Name the keyword that:
(i) is used for allocating memory to an array.
(ii) causes the control to transfer back to the method call.
Ans: (i) new    (ii) return
(e) Differentiate between pure and impure function.
Ans: Pure Function: These functions takes objects as an arguments but does not modify the state of the objects. The result of the pure function is the return value. Impure Function: These functions change the state of the object arguments they have received.

Question 3.
(a) Write an expression for     (a + b)n
——–
`/3 + b
Ans:   Math.pow((a+b),n)/Math.sqrt(3)+b  ;
(b) The following is a segment of a program.
x=1,y=1;
if(n>0)
{
x=x+1;
y=y-1;
}
what will be the value of x and y, if n assumes a value(i)1 (ii)0.
Ans:   (i) x=2  y=0   (ii) x=1   y=1

(c) Analyze the following program segment and determine how many times the body of loop will be executed (show the working)
x=5, y=50;
while(x<=y)
{
y=y/x;
System.out.println(y);
}
Ans: 2 times   and it will print 10 2
(d) When there are multiple definition with the same function name, what makes them different from other?
Ans: Function with same name having several definitions in the same scope that are differentiable by the number or type of their arguments, is said to be an overloaded function.
float area (float radius)
{
return (3.14 * radius * radius);
}
float area (float length, float breadth)
{
return (length*breadth);
}
If both the function signature is same then it is call Function overriding.
(e) Given that int x[][]={{2,4,6},{3,5,7}};
What will be the value of x[1][0] and x[0][2]?
Ans:  3    and    6

(f) Give the output of the following code fragment:
When i) opn=’b’ ii) opn=’x’ iii) opn=’a’
switch(opn)
{
case ‘a’:
System.out.println(“Platform Independent”);
break;
case ‘b’:
System.out.println(“Object oriented”);
break;
case ‘c’:
System.out.prinln(“Robust and secure”);
break;
default:
System.out.println(“Wrong input”);
}
Ans: (i) Object oriented   (ii) Wrong input  (iii) Platform Independent
(g) Consider the following code and answer the question that follows:
class academic
{
int x,y;
void access()
{
int a,b;
academic student=new academic();
System.out.println(“Object created”);
}
}
i) What is the object name of class academic?
ii) Name the class variable used in the program.
iii) Write the local variable used in the program.
iv) Give the type of function used and its name.   [4]
Ans: (i) student   (ii) x and y   (iii) a and b    (iv) function name is ‘access’ its a void function.
(h) Convert the following segment into an equivalent do loop. [3]
int x,c;
for(x=10,c=20;c>=10;c=c-2)
x++;
Ans:
int x=10,c=20;
while(c>=10)
{
x++;
c=c-2;
}

SECTION B (60 Marks)
Attempt any four questions from this Section. The answers in this Section should consist of the Program in BlueJ environment with Java. Each program should be written in using Variable descriptions/Mnemonic Codes such that the logic of the program is clearly depicted. Flow charts and Algorithms are not required.

Question 4.
An electronic shop has announced the following seasonal discount 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 above criteria, to input name, address, amount of purchase and type of purchase (L for Laptop and D for Desktop) by the 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)

import java.io.*;
class ICSE09q04
{
public static void main() throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader x=new BufferedReader(isr);
System.out.print(“Enter a Name : “);
String name=x.readLine();
System.out.print(“Enter the Address : “);
String add=x.readLine();
System.out.print(“Enter a AMOUNT : “);
int amt=Integer.parseInt(x.readLine());
System.out.print(“Enter the Type : “);
String type=x.readLine();
double disc=0.0d,netamt=0.0d;
if(amt>=0 && amt<=25000)
{
if(type.equals(“L”)) disc=0.0;
if(type.equals(“D”)) disc=0.05;
}
else if(amt>=25001 && amt<=57000)
{
if(type.equals(“L”)) disc=0.05;
if(type.equals(“D”)) disc=0.075;
}
else if(amt>=57001 && amt<=100000)
{
if(type.equals(“L”)) disc=0.075;
if(type.equals(“D”)) disc=0.10;
}
else
{
if(type.equals(“L”)) disc=0.10;
if(type.equals(“D”)) disc=0.15;
}
netamt=amt-(amt*disc);
System.out.println(“Name : “+name);
System.out.println(“Address : “+add);
System.out.println(“Net Amount to be PAID : “+netamt);
}
}

Question 5.
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
Input: Type 1 for a triangle and
Type 2 for a inverted triangle
1
Enter the number of terms
5
Output:
Input: Type 1 for a triangle and
Type 2 for a inverted triangle
2
Enter the number of terms
6
Output:
1
22
333
4444
55555
666666
55555
4444
333
22
1
import java.io.*;
class ICSE09q5
{
public static void main() throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader x=new BufferedReader(isr);
int ch=0;
System.out.println(“Enter 1 for Triangle and”);
System.out.println(“Enter 2 for Inverted Triangle”);
System.out.print(“Enter your choice (1-2): “);
ch=Integer.parseInt(x.readLine());
switch(ch)
{
case 1:
System.out.print(“Enter a number : “);
int n=Integer.parseInt(x.readLine());
for(int i=0;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
break;
case 2:
System.out.print(“Enter a number : “);
n=Integer.parseInt(x.readLine());
for(int i=n;i>=1;i–)
{
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}
break;
}
}
}

Question 6.
Write a program to input a sentence and print the number of character found in the longest word of the given sentence.
For Example if s = “India is my Country” then output should be 7.
import java .io.*;
class ICSE09q6
{
public static void main()throws IOException
{
InputStreamReader read =new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(read);
System.out.println(“Enter Sentence”);
String n=in.readLine();
n=n+” “;
String w, longestWord=””;
int p=0;
int l=n.length();
int x,wordlen=0;
while(p<l)
{
x=n.indexOf(‘ ‘,p); //findout the space position
w=n.substring(p,x); //extracting word
// find out the longest word
if(w.length()>=wordlen)
{
longestWord=w;
wordlen=w.length();
}
p=x+1;
}
System.out.println(“Longest word is : “+longestWord);
System.out.println(“Length is : “+longestWord.length());
}
}

Question 7.
Design a class to overload a function num_calc() as follows:
a. void num_calc(int num,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.
b. void num_calc(int a,int b,char ch) with two integer arguments and one character argument. It computes the product of integer argument if ch is ‘p’ else adds the integers.
c. void num_calc(Strings s1,String s2) with two string argument, which prints whether the strings are equal or not.
import java.io.*;
class ICSE09q7
{
public static void num_calc(int num,char ch)
{
if(ch==’s’)
System.out.println((num)*(num));
else
System.out.println((num)*(num)*(num));
}
public static void num_calc(int a,int b,char ch)
{
if(ch==’p’)
System.out.println(a*b);
else
{
int sum=a+b;
System.out.println(sum);
}
}
public static void num_calc(String s1,String s2)
{
if(s1.equals(s2))
System.out.println(“EQUAL”);
else
System.out.println(“NOT EQUAL”);
}
}

Question 8.
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.
a) A BUZZ number is the number which either ends with 7 or divisible by 7.
b) GCD (Greatest Common Divisor) of two integer is calculated by continued division method. Divide the larger number by smaller, the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results the GCD.
import java.io.*;
class ICSE09q08
{
public static void main() throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader x=new BufferedReader(isr);
System.out.println(“1. BUZZ Number”);
System.out.println(“2. GCD”);
System.out.print(“Enter your choice : “);
int ch=Integer.parseInt(x.readLine());
int n1,n2;
switch(ch)
{
case 1:
System.out.println(“enter a number”);
n1=Integer.parseInt(x.readLine());
if(n1%7==0 || n1%10==7)
{
System.out.println(“It is a BUZZ number”);
}
else
{
System.out.println(“It is not a BUZZ number”);
}
break;
case 2:
System.out.println(“Enter First Number”);
n1=Integer.parseInt(x.readLine());
System.out.println(“Enter Second Number”);
n2=Integer.parseInt(x.readLine());
if(n2>n1)
{
int y=n1;
n1=n2;
n2=y;
}
int t;
while(n1%n2!=0)
{
t=n1;
n1=n2;
n2=t%n2;
}
System.out.println(“GCD is=”+n2);
}
}
}

Question 9.
The annual examination results of 50 students in a class is tabulated as follows.
Roll no.     Subject A     Subject B     Subject C
——-      ———     ———     ———
Write a program to read the data, calculate and display the following:
a) Average marks obtained by each student.
b) Print the roll number and average marks of the students whose average mark is above 80.
c) Print the roll number and average marks of the students whose average mark is below 40.
import java.io.*;
class ICSE09q9
{
public static void main()throws IOException
{
InputStreamReader inp=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(inp);
int Roll[]=new int[50];
int SubA[]=new int[50];
int SubB[]=new int[50];
int SubC[]=new int[50];
String HighName;
int HighMarks,total=0;
for(int i=0;i<50;i++)
{
System.out.println(“Enter Roll and Marks”);
Roll[i]=Integer.parseInt(in.readLine());
System.out.println(“Enter Subject A Marks”);
SubA[i]=Integer.parseInt(in.readLine());
System.out.println(“Enter Subject B Marks”);
SubB[i]=Integer.parseInt(in.readLine());
System.out.println(“Enter Subject C Marks”);
SubC[i]=Integer.parseInt(in.readLine());
}
System.out.println(“Average Marks obtained by Students”);
for(int i=0;i<50;i++)
{
System.out.println(“Roll “+Roll[i]+” Average is : “+(SubA[i]+SubB[i]+SubC[i])/3.0);
}
System.out.println(“Average More then 80 by Students”);
for(int i=0;i<50;i++)
{
if( ((SubA[i]+SubB[i]+SubC[i])/3.0) > 80)
System.out.println(“Roll “+Roll[i]+” Average is : “+(SubA[i]+SubB[i]+SubC[i])/3.0);
}
System.out.println(“Average Less then 40 by Students”);
for(int i=0;i<50;i++)
{
if( ((SubA[i]+SubB[i]+SubC[i])/3.0) < 40)
System.out.println(“Roll “+Roll[i]+” Average is : “+(SubA[i]+SubB[i]+SubC[i])/3.0);
}
}
}

=*=*=*=*=*=

Leave a Comment