ICSE Class 10 Computer Application Solved Question Paper Year 2013


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

    What is meant by precedence of operators?
    Ans. Precedence of operators defines the order in which the operators within an expression are executed. The order of evaluation can be modified with the help of parenthesis ( and ). For example, in the expression x = a + b * c the RHS evaluates using a + (b * c) since the * operator has a higher precedence as compared to the + operator. As another example, in the equaion x = a+b > c ? a : b, the + operator has higher precedence over the ternary operator ?: and hence the RHS evaluates to (a+b) > c ? a : b.

  2. Marks [2]

    What is a literal?
    Ans. A literal is a notation for representing a fixed value in source code. It is a value that is directly represented in code.
    For example, in the expression
    int x = 4;
    The 4 is a literal.

  3. Marks [2]

    State the Java concept that is implemented through:

    1. A superclass and a subclass
    2. The act of representing essential features without including background details

    Ans.

    1. Inheritance
    2. Abstraction
  4. Marks [2]

    Give a difference between constructor and a method.
    Ans. A constructor has the same name as the class; the name of the method is not the same as that of the class.
    A constructor does not have a return type; every method must specify a return type, and if none exists, the type void must be specified.
    The calls super( ) and this( ) can be used inside a constructor, but not inside a method.

  5. Marks [2]

    What are the types of casting shown by the following examples?

    1. double x = 15.2;
      int y = (int)x;
    2. int x = 12;
      long y = x;

    Ans.

    1. Explicit typecast
    2. Implicit typecast

Question 2

  1. Marks [2]

    Name any two wrapper classes.
    Ans. Integer, Double

  2. Marks [2]

    What is the difference between break and continue statements when they occur in a loop?
    Ans. The break statement stops the execution of the current loop iteration and transfers control to the statement outside the loop. The continue statement stops the execution of the current loop iteration and transfers control to the end of the loop body, for the next iteration to proceed.

  3. Marks [2]

    Write statements to show how finding the length of a character array named ch differs from finding the length of a String object str.
    Ans. Length of a character array: ch.length
    Length of a String array: str.length()
    Example statements:
    System.out.println(“Char array: ” + ch.length);
    System.out.println(“String array: ” + str.length());

  4. Marks [2]

    Name the Java keyword that:

    1. Indicates a method has no return type
    2. Stores the address of the currently calling object

    Ans.

    1. void
    2. this [The ‘this’ keyword is actually a reference to the current object, and hence it contains the address of where that object is stored. Hence the answer to this question is ‘this’.]
  5. Marks [2]

    What is an exception?
    Ans. An exception is the occurrence of something that should not normally happen. A Java method will throw an exception if it encounters a situation which it cannot handle. When an exception occurs, an object is created that contains details of the problem (exception). This object is created automatically by Java.
    Some exceptions, like a divide by zero, can be avoided through careful programming.
    Other exceptions, such as hard disk full, or network connection lost, cannot be avoided and nor can they be predicted.
    Dealing with exceptions is known as handling the exception.
    There are two types of exceptions: checked exceptions and unchecked exceptions.
    Unchecked exceptions are those that do not have to be addressed (handled) by the Java program. This includes division by zero, array index out of bounds, etc. Unchecked exceptions are normally the result of bad programming (programmer bugs).
    Checked exceptions are those that must be handled by the Java program. These include hard disk is full, file not found, unable to connect to database, and so on.

Question 3

    1. Marks [2]

      Write Java statement to create an object mp4 of class digital.
      Ans. digital mp4 = new digital( );

    2. Marks [2]

      State the values stored in variables str1 and str2
      String s1 = “good”; String s2 = “world matters”;
      String str1 = s2.substring(5).replace(‘t’,’n’);
      String str2 = s1.concat(str1);
      Ans. str1 = “ manners”(this is a space followed by manners)
      str2 = “good manners”

    3. Marks [2]

      What does a class encapsulate?
      Ans. A class encapsulates the implementation details of that class. This includes the methods and the variables that are needed for the functionality of that class. Only the functionality that needs to be exposed is exposed. The functionality that is not exposed is normally “private” to that class. Private variables can be exposed using getter (accessor) and setter (mutator) methods.

    4. Marks [2]

      Rewrite the following program segment using the if .. else statement.
      comm = (sale>15000)?sale*5/100:0;
      Ans.

      if(sale > 15000)
      comm = sale * 5 / 100;
      else
      comm = 0;
      
    5. Marks [2]

      How many times will the following loop execute? What value will be returned?

      int x = 2, y = 50;
      do{
      ++x;
      y -= x++;
      }while(x <= 10);
      return y;
      

      Ans. The loop will execute 5 times. The value returned will be 15.
      Explanation: x increased by 2 in each iteration. It starts with 2, then 4, 6, 8, 10. So, totally it executes 5 times. The amount by which y reduces each iteration is 3, 5, 7, 9, 11; hence the value of y returned is 50 – 3 – 5 – 7 – 9 – 11 = 15.

    6. Marks [2]

      What is the data type that the following library functions return?

      1. isWhitespace(char ch)
      2. Math.random( )

      Ans.

      1. boolean
      2. double
    7. Marks [2]

      Write a Java expression for ut + ˝ ft2
      Ans. u*t + 1.0 / 2.0 * f * t * t
      Note: u*t + 1/2*f*t*t cannot be used, since 1/2 will give an integer of 0. Hence we use 1.0 / 2.0 instead.
      Or
      We can change the expression into u*t + (double)(1/2) * f * t * t

    8. Marks [2]

      if int[ ] n = {1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
      x = Math.pow(n[4],n[2]);
      y = Math.sqrt(n[5]+n[7]);
      Ans. x is 343.0 and y is 5.0

    9. Marks [2]

      What is the final value of ctr after the iteration process given below, executes?

      int ctr = 0;
      for(int i = 1; i <=5 ; i++)
      for(int j = 1; j <= 5; j+=2)
      ++ctr;
      

      Ans. 15
      Explanation: The inner loop executes 3 times for each of the 5 iterations of the outer loop.

Ans. x is 343.0 and y is 5.0

Name the methods of the Scanner class that:

  1. Is used to input an integer from standard input stream
  2. Is used to input a string data from standard input stream

Ans.

  1. nextInt( )
  2. next( ) and nextLine( )

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 FruitJuice with the following description:
Instance variables/data members:
int product_code – stores the product code number
String flavour – stores the flavor of the juice. (orangle, apple, etc.)
String pack_type – stores the type of packaging (tetra-pack, bottle, etc.)
int pack_size – stores package size (200ml, 400ml, etc.)
int product_price – stores the price of the product
Member methods:
FruitJuice( ) – default constructor to initialize integer data members to zero and string data members to “”
void input( ) – to input and store the product code, flavor, pack type, pack size and product price
void discount( ) – to reduce the product price by 10
void display( ) – to display the product code, flavor, pack type, pack size and product price
Ans.

import java.io.*;
class FruitJuice
{
int product_code;
String flavour;
String pack_type;
int pack_size, product_price;
public FruitJuice()
{
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}
public void input( )throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print(" Enter the product code: ");
product_code = Integer.parseInt(input.readLine( ));
System.out.print(" Enter the flavour: ");
flavour = input.readLine( );
System.out.print(" Enter the pack type: ");
pack_type = input.readLine( );
System.out.print(" Enter the pack size: ");
pack_size = Integer.parseInt(input.readLine( ));
System.out.print(" Enter the product price: ");
product_price = Integer.parseInt(input.readLine( ));
}
public void discount()
{
product_price -= 10;
}
public void display()
{
System.out.println(" Product code : " + product_code);
System.out.println(" Flavour: " + flavour);
System.out.println(" Pack type: " + pack_type);
System.out.println(" Pack size: " + pack_size + " ml.");
System.out.println(" Product price: " + product_price + " Rs.");
System.out.println();
}
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
FruitJuice obj = new FruitJuice();
obj.input( );
obj.display( );
obj.discount( );
System.out.println(" After deducting the discount:-");
obj.display( );
}
}

Question 5

Marks [15]

The International Standard Book Number (ISBN) is a unique numeric book identifier which is printed on every book. The ISBN is based upon a 10-digit code. The ISBN is legal if 1*digit1 + 2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 + 8*digit8 + 9*digit9 + 10*digit10 is divisible by 11.
Example: For an ISBN 1401601499
Sum =1*1 + 2*4 + 3*0 + 4*1 + 5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible by 11.
Write a program to:

  1. Input the ISBN code as a 10-digit number
  2. If the ISBN is not a 10-digit number, output the message “Illegal ISBN” and terminate the program
  3. If the number is 10-digit, extract the digits of the number and compute the sum as explained above.

If the sum is divisible by 11, output the message “Legal ISBN”. If the sum is not divisible by 11, output the message “Illegal ISBN”.
Ans.

import java.io.*;
class ISBN
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print(" Enter the 10-digit ISBN number: ");
long isbn = Long.parseLong(input.readLine( ));
String temp = "" + isbn;
if( temp.length() != 10 )
{
System.out.println(" Illegal ISBN");
return;
}
int sum = 0;
int digit;
int digitNo;
int term;
for(int i = 0; i < temp.length( ); i++)
{
digit = Integer.parseInt(temp.substring(i, i+1));
digitNo = i + 1;
term = digitNo * digit;
sum += term;
}
if( (sum%11) != 0 )
{
System.out.println(" Illegal ISBN");
}
else
{
System.out.println(" Legal ISBN");
}
}
}

Question 6

Marks [15]

Write a program that encodes a word in Piglatin. To translate word into Piglatin word, convert the word into uppercase and then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets present before the vowel being shifted towards the end followed by “AY”.
Sample Input(1): London Sample Output(1): ONDONLAY
Sample Input(2): Olympics Sample Output(2): OLYMPICSAY
Ans.

import java.io.*;
class Piglatin
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print("Enter a word: ");
String word = input.readLine( ).toUpperCase( );
String piglatinWord = "";
int i, firstVowel = -1;
for(i = 0; (i < word.length( )) && (firstVowel < 0); i++)
{
char ch = word.charAt(i);
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
firstVowel = i;
break;
}
}
String part1 = "", part2 = "";
if(firstVowel >= 0)
{
part2 = word.substring(0, firstVowel);
part1 = word.substring(firstVowel);
}
else
{
part2 = "";
part1 = word;
}
piglatinWord = part1 + part2 + "AY";
System.out.println("Output: " + piglatinWord);
}
}

Question 7

Marks [15]

Write a program to input 10 integer elements in an array and sort them in descending order using bubble sort technique.
Ans.

import java.io.*;
class BubbleSort
{
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
int n = 10;
int[ ] arr = new int[n];
int i, j, temp;
System.out.println(" Enter the elements:-");
for(i = 0; i < n; i++)
{
System.out.print(" Enter " +(i+1) +" Numbered Element: ");
arr[i] = Integer.parseInt(input.readLine( ));
}
for(i = 0; i < (n-1); i++)
{
for(j = 0; j < (n-1-i); j++)
{
if(arr[j] < arr[j+1])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}				
System.out.println(" Sorted array (descending):- ");
for(i = 0; i < n; i++)
System.out.print(arr[i] + " ");
}
}

Question 8

Marks [15]

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

  1. double series(double n) with one double argument and returns the sum of the series.
    sum = 1/1 + 1/2 + 1/3 + … 1/n
  2. double series(double a, double n) with two double arguments and returns the sum of the series.
    sum = 1/a2 + 4/a5 + 7/a8 + 10/a11 … to n terms

Ans.

import java.io.*;
class OverlaodSeries
{
public static double series(double n)
{
double sum = 0.0;
int terms = (int)(Math.round(n));
for(int i=1; i <= terms; i++)
sum = sum + 1.0d / (double)i;
return sum;
}
public static double series(double a, double n)
{
double sum = 0.0;
int terms = (int)(Math.round(n));
for(int i = 1; i <= terms; i += 3)
sum = sum + (double)(i / (a * (i + 1)));
return sum;
}
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print(" Enter a: ");
double a = Double.parseDouble(input.readLine( ));
System.out.print(" Enter n: ");
double n = Double.parseDouble(input.readLine( ));
double sum1 = OverlaodSeries.series(n);
System.out.println(" Sum 1: " +sum1);
double sum2 = OverlaodSeries.series(a, n);
System.out.println(" Sum 2: " +sum2);
}
}

Question 9

Marks [15]

Using the switch statement, write a menu driven program:

  1. To check and display whether the number input by the user is a composite number or not (A number is said to be a composite, if it has one or more than one factors excluding 1 and the number itself).
    Example: 4, 6, 8, 9, …
  2. To find the smallest digit of an integer that is input:
    Sample input: 6524
    Sample output: Smallest digit is 2

Ans.

import java.io.*;
class Numbers
{
public static void doComposite( )throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print(" Enter integer for Composite check: ");
int n = Integer.parseInt(input.readLine( ));
int noOfFactors = 0;
for(int  i = 2; i < n; i++)
if( (n%i) == 0 )
noOfFactors++;
if(noOfFactors == 0)
System.out.println(" The Number " +n +" is not a composite.");
else
System.out.println(" The Number " +n +" is a composite number.");
}
public static void doSmallestDigit( )throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.print(" Enter integer for smallest digit check: ");
int n = Integer.parseInt(input.readLine( ));
int smallestDigit = 9; // initialize to largest digit 9
int temp = n;
int digit;
while(temp > 0)
{
digit = temp % 10;
temp = temp / 10;
smallestDigit = (smallestDigit <= digit) ? smallestDigit : digit;
}
System.out.println(" Smallest digit is: " + smallestDigit);
}
public static void main(String[] args)throws IOException
{
InputStreamReader read = new InputStreamReader(System.in) ;
BufferedReader input = new BufferedReader(read) ;
System.out.println(" MENU Options:-");
System.out.println(" Enter 1. for Composite ");
System.out.println(" Enter 2. for Smallest ");
System.out.print(" Enter your choices: ");
int cho = Integer.parseInt(input.readLine( ));
switch(cho)
{
case 1: // composite
doComposite( );
break;
case 2: // smallest digit
doSmallestDigit( );
break;
default:
System.out.println(" Invalid option - Try again");
}
}
}
One Comment

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.