ICSE Class 10 Computer Application Solved Question Paper Year 2005


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

Marks [10]

  1. Name any two OOP’s principles.
  2. Mention two different styles of expressing a comment in a program.
  3. Which element is num[9] of the array num ?
  4. Differentiate between operator and expression.
  5. If m = 5 and n = 2 output the values of m and n after execution hi (i) and (ii)
    1. m – = n;
    2. n = m + m/n

Answer 1

  1. The two principles of OOP’s are:
    1. Encapsulation
    2. Inheritance.
  2. Two different styles of expressing a comment in a program:
    1. Single line comment
    2. Multi line comment
  3. 10th element is num[9] of the array num.
  4. An operator is a symbol which initiates some action for e.g., arithmetic operator + leads to addition between the given numbers.
    An expression is a group of atomic elements of Java (for e.g., keywords, identifiers, etc.) which is used to denote or carry out some job.
    1. m = 3, n = 2
    2. m = 5,n = 7

Question 2

Marks [10]

  1. Explain the term for loop with an example.
  2. What is a compound statement? Give an example.
  3. State the difference between Constructor and Method.
  4. State one similarity and one difference between while and do while loop.
  5. Explain, with the help of an example, the purpose of default in a switch statement.

Answer 2

  1. The for loop is one of Java’s iteration statements (Perhaps for most of the language also). It is used generally when the number of iterations is fixed and known before execution.
    The general form of the for loop is shown below:

    for (initialization; condition; iterate-updating )
    {
    // body of the loop
    }

    Example :

    	for(a = 0; a < 100; a++) 
    {
    System.out.println("a = " +a);
    }	

    The above for loop displays all the numbers from 1 to 100.

  2. A compound statement basically refers to a block i.e., a sequence of statements enclosed within a pair of braces {} for e.g.,
    if(x= =10)
    {
    int y = 20;
    x = y *2;
    System.out.pnntln("x = "+x);		
    }
  3. Functions in Java are known as methods. A method contains the code of the class. The code defines the interface to the data of the class.
    A constructor is a member function whose name is the same as its class name and whose task is to initialize the objects of its class.
  4. Similarity: while and do-while loop are used generally when the number of iterations are unknown.
    Difference: while loop is an entry-controlled loop and do-while loop is an exit-controlled loop.
  5. A common programming practice in any language is to test a variable against some value, and if it does not match that value, to test it again against a different value, and if it does not match that one to make yet another test, and so on until it matches with the right result. Using only if statements, this can become unwieldy, depending on how it’s formatted and how many different options you have to test. Many languages have a shorthand version of the nested if that is (somewhat) easier to read and allows you to group the tests and actions. Called a case or switch statement, in Java it’s called switch and behaves as it does in C :
    switch (test)
    {
    case valueOne: 
    resultOne;
    break;
    case valueTwo:
    resultTwo;
    break;
    case valueThree:
    resultThree;
    break;
    .
    default:
    defaultResult;
    }
    

    In the switch statement, the test (a variable or expression that evaluates to a byte, char, short, or int) is compared with each of the case values (valueOne, valueTwo, and so on) it turn. If a match is found, the statement (or statements) after the test is executed. If no match is found, the default statement is executed. The default is optional, so if there is not a match in any of the cases and default does not exist, the switch statement completes without doing anything.
    Note that the significant limitation of the switch in Java is that the tests and values can be only simple primitive types (and then only primitive types that are automatically cast-able to int). You cannot use larger primitive types (long, float), strings, or other objects within a switch, nor can you test for any relationship other than simple equality. This limits the usefulness of switch; nested ifs can work for any kind of test on any type.

Question 3

  1. What will be the output of the following, if x = 5 initially?
    1. 5 *++ x
    2. 5 * x++
  2. Marks [2]

  3. What is the output of the following?
    char c= ‘A’
    short m = 26;
    int n = c + m;
    System.out.println(n);
  4. Marks [2]

  5. Explain the meaning of break and continue statements.
  6. Marks [3]

    1. What is call by value?
    2. How are the following passed?
      1. Primitive types
      2. Reference types
  7. Marks [3]

  8. Enter any two variables through constructor parameters and write a program to swap and print the values.
  9. Marks [4]

  10. What do the following functions return for:
    String.x = “hello”
    String. = “world”
    1. System.out.println(x + y)
    2. System.out.println(x.length( ));
    3. System.out. prmtln(x.charAt(3));
    4. System.out.println(x.equals(y));
  11. Marks [4]

  12. Differentiate between toLowerCase() and toUpperCase() methods.
  13. Marks [2]

Answer 3

    1. x = 5
      5 * ++x
      = 5 * 6
      = 30
    2. x = 5
      5 * x++
      = 5 * 5
      = 25
  1. Output: 91
    (The ASCII value of ‘A’ is 65 and 26 added to it becomes 91. The final result obtained is of int data type.)
  2. The break statement is used to exit a loop and also inside a switch statement. When a break statement is encountered inside a loop, the loop is terminated and program control resumes at the next statement following the loop.
    The continue statement is used to terminate the current iteration of the loop and proceed with the next iteration of the loop.
    1. Call by value: This method copies the values of actual parameters into the formal parameters of the function.
      1. Primitive Data Types are passed by value.
      2. Arrays, classes, and interfaces are reference types. The value of a reference type variable, in contrast to that of a primitive type, is a reference to (an address of) the value or set of values represented by the variable (see the following figure). A reference is called a pointer, or a memory address in other languages. The Java programming language does not support the explicit use of addresses like other languages do. You use the variable’s name instead.
  3. class Swap
    {
    int a, b;
    Swap (int x. inty)		// This is the constructor for Swap
    { 
    a = x;
    }
    public void Swapping( )
    {
    int z;
    z = a;
    a = b;
    System.out.println ("Value of a after swapping:" + a);
    System.out.println ("Value of b after swapping:" + b);
    }
    
    1. helloworld
    2. 5
    3. 1
    4. false
  4. toLowerCase( ) – Cconverts all characters of a string to lowercase characters.
    to UpperCase( ) – Converts all characters of a string to uppercase characters.

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

Write a class with name employee and basic as its data member, to find the gross pay of an employee for the following allowances and deduction. Use meaningful variables.

Dearness Allowance = 25% of the Basic Pay
House Rent Allowance = 15% of Basic Pay
Provident Fund = 8.33% of Basic Pay
Net Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Gross Pay = Net – Provident Fund

Marks [15]

Answer 4

public class employee
{
private float basic;
public employee(float bas_sal)
{
basic = bas_sal;
}
public double getPay()
{
double da, hra, pf, netPay, grossPay;
da = basic * 0.25;
hra = basic * 0.15;
pf = basic * 0.0833;
netPay = basic + da + hra;
grossPay = netPay - pf;
System.out.println("Basic Salary = " +basic);
System.out.println("DA = " +da);
System.out.println("HRA = " +hra);
System.out.println("PF = " +pf);
System.out.println("Total Pay = " +netPay);
return grossPay;
}
public static void main(String Args[])
{
employee Emp = new employee(27470);
double grossPay = Emp.getPay();
System.out.println("Gross Pay: " + grossPay);
}//End of main
}//End of class

Question 5

Write a program to input any given string to calculate the total number of characters and vowels present in the string and also reverse the string:

Example:
INPUT
Enter String : SNOWY
OUTPUT
Total number of characters : 05
Number of Vowels : 01
Reverse string : YWONS

Marks [15]

Answer 5

import java.io.BufferedReader;
import java.io.IOException;
public class StringCal
{
private String input;
public StringCal(String str)
{
input = str;
}
public void stringFunc()
{
int len = input.length();
System.out.println(“Total number of characters :” +len);
int vowel = 0;
int i = 0;
char chr;
for(i = 0; i<len; i++)
{
chr = toUpperCase(input.charAt(i));
switch(chr)
{
case 'a' :					
case 'A' :
case 'e' :
case 'E' :
case 'i' :
case 'I' :
case 'o' :
case 'O' :
case 'u' :
case 'U' :
vowel + + ;
}
}
System.out.println(“Number of Vowels:” +vowel);
StringBuffer revStr = new StringBuffer(input);
revStr.reverse();
System.out.println(“Number of Vowels:” +vowel);			
}
public static void main(String Args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter String:”);
StringCal strCal = new StringCal(input.readLine());	
StrCal.stringFunc();
}//End of main
}//End of class

Question 6

Write a program using a function called area( ) to compute the area of a:-

  1. circle (π * r2) where π = 3. 14
  2. square (side * side)
  3. rectangle (length * breadth)

Display the menu to output the area as per User’s choice.

Marks [15]

Answer 6

import java.io.*;
public class FindArea
{
//Function overloaded - area()
public void area(float radius)
{
double circle = 3.14 * radius * radius;
System.out.println("Area of the circle = " + circle);
}
public void area(double side)
{
double square = side * side;
System.out.println("Area of the square = " + square);
}
public void area(double length, double breadth)
{
double rectangle = length * breadth;
System.out.println("Area of the rectangle = " + rectangle);
}
public static void main(String Args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
FindArea shape = new FindArea();
System.out.println("MENU");
System.out.println("1.Area of the circle");
System.out.println("2.Area of the square");
System.out.println("3.Area of the rectangle");
System.out.print("Please enter your choice from the MENU list: ");
int choice = Integer.parseInt(input.readLine());	
switch(choice)
{
case 1:
System.out.println("You have choosen circle");
System.out.print("Enter the radius: ");
Float rd = Float.valueOf(input.readLine()).floatValue();
shape.area(rd);
break;
case 2:
System.out.println("You have choosen square");
System.out.print("Enter the length of the side: ");
Double sd = Double.valueOf(input.readLine()).doubleValue();
shape.area(sd);
break;
case 3:
System.out.println("You have choosen rectangle");
System.out.print("Enter the length of the side: ");
Double len = Double.valueOf(input.readLine()).doubleValue();
System.out.print("Enter the breadth of the side: ");
Double bd = Double.valueOf(input.readLine()).doubleValue();
shape.area(len,bd);
break;
default:
System.out.println("Your Entered Option not in the MENU List");
}
} //End of main
}//End of class FindArea

Question 7

Write a program to bubble sort the following set of values in ascending order :-
5,3,8,4,9,2,1,12,98,16

Output:
1
2
3
4
5
8
9
12
16
98

Marks [15]

Answer 7

import java.io.*;
public class BubbleSort
{
private static int max(int[] array)
{
int max = array[0];
for(int i = 1; i<array.length; i++)
{
if(max < array[i])
{
max = array[i];
}
}
return max;
}
private static int min(int[] array)
{
int min = array[0];
for(int i = 1; i<array.length;i++)
{
if(min > array[i])
{
min = array[i];
}
}
return min;
}
public static void bubbleSort(int[] array)
{
int temp;
int n = array.length;
for(int i = 1; i<n; i++)
{
for(int j = 0; j<n-1; j++)
{
if(array[j] > array[j+1])
{
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
}
public static void main(String Args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int arr[] = {5,3,8,4,9,2,1,12,98,16};
bubbleSort(arr);
System.out.println("OUTPUT");
for(int i = 0; i<arr.length; i++)
{
System.out.println(arr[i]);
}
}
}

Question 8

Write a program to print the sum of negative numbers, sum of positive even numbers and sum of positive odd numbers from a list of numbers (N) entered by the user. The list terminates when the user enters a zero.

Marks [15]

Answer 8

import java.io.*;
public class ArrayProcess
{
public static int NegativeSum(int[] array)
{
int sum = 0;
for(int i = 0; i<array.length; i++)
{
if(array[i] < 0)
{
sum += array[i];
}
}
return sum;
}
public static int PositiveOddSum(int[] array)
{
int sum = 0;
for(int i = 0; i<array.length; i++)
{
if(array[i] > 0 && array[i]%2 != 0)
{
sum += array[i];
}
}
return sum;
}
public static int PositiveEvenSum(int[] array)
{
int sum = 0;
for(int i = 0; i<array.length; i++)
{
if(array[i] > 0 && array[i]%2 == 0)
{
sum += array[i];
}
}
return sum;
}
public static void display(int[] array)
{
for(int i = 0; i<array.length; i++)
{
if(array[i] != 0)
{
System.out.print(array[i] + " ");
}
}
System.out.println();
}
public static void main(String Args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter numbers in an array - to terminate the list enter zero:-");
int arr[] = new int[100];
int num = 10;
int i = 0;
while(num != 0)
{
num = Integer.valueOf(input.readLine()).intValue();
arr[i] = num;
i++;
}
System.out.println("The numbers in the array is:-");
display(arr);
System.out.println("Negative numbers sum: " + NegativeSum(arr));
System.out.println("Positive odd numbers sum: " + PositiveOddSum(arr));
System.out.println("Positive even numbers sum: " + PositiveEvenSum(arr));
}
}

Question 9

Write a program to initialize an array of 5 names and initialize another array with their respective telephone numbers. Search for a name input by the user, in the list. If found, display “Search Successful” and print the name along with the telephone number, otherwise display “Search Unsuccessful. Name not enlisted.”

Marks [15]

Answer 9

import java.io.*;
class StringCharacter 
{
private String names;
private String phones;
public String getNames(String nam)
{
names = nam;
return names;
}
public String getPhones(String ph)
{
phones = ph;
return phones;
}
public static void main(String args[]) throws IOException
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
StringCharacter list = new StringCharacter();
String[] Str = new String[5];
Long[] Phn = new Long[5];
String StrPhn, SearchName;
int Flag = 0;
for(int i=0;i<5;i++)
{
System.out.print("Name: ");
Str[i] = list.getNames(input.readLine());
System.out.print("Phone: ");
StrPhn = list.getPhones(input.readLine());
Phn[i] = Long.parseLong(StrPhn);
}
System.out.print("Enter the name to search for: ");
SearchName = input.readLine();
for(int j=0;j<5;j++)
{
if(SearchName.equalsIgnoreCase(Str[j]))
{
System.out.println("Search sucessful. Telephone number of" +Str[j] +": " 					+Phn[j]);
Flag = 1;
}
}
if (Flag == 0)
{
System.out.println("Search unsucessful. Name not enlisted");
}
}
}
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.