ICSE Class 10 Sample Paper 2021-2022 Answer sheet
- Categories Uncategorized
COMPUTER APPLICATIONS
(Theory)
(Two hours)
Answers 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 at the head of this Paper is the time allowed for writing the answers.
This Paper is divided into two Sections.
Attempt all questions from Section A and any four questions from Section B.
The intended marks for questions or parts of questions are given in brackets [ ].
SECTION A (40 Marks)
Attempt all questions(2 marks each question)
Question 1.
a . What do mean by Inheritance and Polymorphism in Java?
Ans. Inheritance
- When one object acquires the properties and behaviors of a parent object, it is known as inheritance. The data and methods available to the parent class or super class is also available to the child class with the same names.
- It also provides code reusability.
- For e.g. we can have a class shape from which I can drive sub class Circle, Triangle, Square etc…
Polymorphism
- Polymorphism means having many forms. In Java, we use method overloading and method overriding to achieve polymorphism.
- In method overloading, we can have multiple methods with same name, like to find area, based upon number of parameters the function can work for different shapes.
- In case of inheritance, the derived class can either use the method of base class or it can have its own implementation of the method which will then override the base class function. This is called method overriding.
- Polymorphism simplifies usage of object methods by external code and Java takes care of calling the right method with the help of the signature and declaration of these entities
b . Give the output of this code
int a = 9; a++;
System.out.println (a);
a -= a-- - --a;
System .out.println (a);
Ans: 10
8
Explanation
a = 9;
a++; // a = 10
SOP (a) // Prints 10
a -= a– – –a;
a = 10 – (10 – 8)
a = 10 -2 = 8
SOP (a) // Prints 8
c . What is the value stored in x and y after execution of these statements?
double x = Math.ceil(8.3) + Math.floor(-3.2)+Math.rint(4.5);
double y = Math.abs(Math.round(Math.max( -4.4, -9.6)));
Ans.
X = 9.0 Working: 9.0 + (-4.0) + 4.0 = 9.0
Y = 4.0 Working Math.abs(Math.round(-4.4)) = 4.0
d . Give the total number of bytes occupied by these arrays?
- int ar[25]
- double A[12]
Ans. The number of bytes:
- ar[25] = 4*25 =100 bytes.
- A[12] = 8*12 =96 bytes
e . What is the output of this code? Show the working
long num=729, sum 0;
for( long y= num; y> 0; y= y/10){
sum= sum + y % 10;
}
System.out.println("Sum of digits = "+ sum);
Ans. Sum of digits = 18
Initialization num = 729, sum = 0, y = 729
Iteration 1: sum = 0 + 729 % 10 = 9
Iteration 2: y = 729/10 = 72
sum = 9 + 72%10 = 11
Iteration 3 y = 72/10 = 7
sum = 11 + 7%10 = 18
y = 7/10 = 0 so the loop exits.
Print: Sum of digits = 18
Question 2.
a . If int y = 10 then find int z = (++y * (y++ + 5));
Ans. Increment operator has the highest precedence. So, ++y and y++ will be evaluated starting from left.
In ++y, the value of y will be incremented to 11 and then 11 will be used in the expression. When y++ is evaluated, the current value of y i.e. 11 will be used and then y will be incremented from 11 to 12.
int z = (++y * (y++ + 5));
= 11 * (11 + 5 )
= 11 * 16
= 176
b . State the result of the following statement.
System.out.print(“My Friends are \n”);
System.out.print(“Ronit \tNihir \t”);
System.out.print(“and Ananya too”);
Ans.
My Friends are
Ronit Nihir and Ananya too.
c . What do you mean by function overloading? Explain with the help of one example.
Ans. Java allows creating or defining various functions/methods by the same name which are differentiated by their data types or number of arguments. This is known as function overloading.
Example
class Overloading{
int Sum(int a){ // 1st overloaded function with one argument
return a*a;
}
int Sum(int a, int b){ // 2nd overloaded function with two arguments
return ((a*a) + (b*b));
}
}
d . What is the output of the following statements when executed?
char ch[ ]= {‘I’, ‘N’, T’, E’, ‘L’, P’, ‘E’, ‘N’, ‘T’, ‘I’, ‘U’, ‘M’};
String obj= new String(ch, 3, 4);
System.out.println(“The result is = “+ obj
Ans:
Output: ELPE
e . Differentiate between Character.toLowerCase() and Character.toUpperCase() methods. With an example. Character.toLowerCase() Character.isDigit() It is used to convert a string into lower case form (Small letters). It returns true if character argument is a digit, otherwise returns false. Example:
char ch= ‘d’;
char st= Character.toUpperCase( ch ); Example:
Char c=’b’;
boolean st1= Character.isDigit(ch);
Question 3.
a . Explain the statements (i) and (ii) from the following code.
char x =’a’;
(i) x+= 3; // why will this run?
(ii) x= x +3; //why will this gives compile time error?
Ans.
(i) Because x += 3; is equivalent to x = (char) (x+3); // here (char) is type casting
(ii) Where x +3 is default to int operation, assign an int to char must be type cast.
b . State the method that:
i. Converts a string to a primitive float data type
ii. Determines if the specified character is an uppercase character
Ans.
i. Float.parseFloat()
ii. Character.isUpperCase()
c . What is the difference between pure and impure function? Pure Function Impure Function It does not modify the arguments It modifies the state of arguments received or Relies only on parameters passed to it. Refers to variables outside of method. e.g.
public class TestMax {
/* Return the max between two int */
public static int max(int n1, int n2)
{ …;
Return n1;
}e.g.
public class TestMax {
highestNo = 23;
public static int max(int n1, int n2)
{
…
if (n1 < highestNo)
result = highestNo;
… }
d . What is this keyword? Also discuss the significance
Ans. Keyword THIS is a reference variable in Java that refers to the current object. It is automatically created when an object is created.
It can be used -:
- To refer to instance variable of current class
- To invoke or initiate current class
- To return the current class instance
- To pass as argument to class method or constructor.
e.g
Class Simply {
int x, y;
// Constructor
Simply (int x, int y)
{
this.x = x;
this.y = y;
}
}
e . State the output of this program Segment?
String str1 = ”great”;
String str2= “Minds”;
System.out.println(str1.substring(0,2). Concat(str2.substring(1)));
System.out.println(( “WH”+(str1.substring(2).toUpperCase() )));
Ans.
The 1st output is= grinds ( because str1. Substring(0,2)gives “gr” & str2. Substring(1) gives “inds”)
The 2nd output is= WHEAT ( because str1. Substring(2). toUpperCase() gives “EAT”, so ”WH”+”EAT”= “WHEAT”)
f . Write a statement each to perform the following task on a string:
- Extract the second last character of a word stored in the variable wd.
- Cheek if the second character of a string str is in uppercase.
Ans.
- char ch = wd.charAt(wt.length() -2);
- if (Character.isUpperCase(str.charAt(1))) OR
if (str.charAt(1)> ‘A ‘ && str.charAt(1) <= ‘z’)
g . Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a= new int(5);
for(int i=0; i<=5; i++)
a[i]= I;
Ans. The statement 1 has two errors: the square brackets ‘[ ]’ is required as “int[ ] a” or “int a[ ]”. Also, the size of the array 5 should be within the ‘[ ]’ bracket instead of ( ).
The statement 2 has one error. The loop should be 0 to 4 i.e. for( int i=0; i< 5; i++) or for( int i= 0; i <5;i++)
Correct program code
int a[ ]= new int[ 5 ];
for(int i= 0; i <5; i++)
a[i]= i;;
h . What do you mean by Punctuators? Give examples.
Ans. The specific symbols used to indicate how group of codes are divided and arranged are known as punctuators.
Examples:
[ ] (used for creating array),
{} (used to make compound statement body),
() (used to perform arithmetic operations, used to enclose arguments of the function, for type casting),
; (semicolon- used as statement terminator),
, (comma- used to separate list of variables),
. (dot or decimal- used make fraction value, include package, referencing object).
i . If String n1 = “99”; and String n2=”100”; Give the output of the following:
- String st= n1+n2; System.out.println (st) ;
- System.out.println( n1.charAt( 1 ));
- System.out.println( n2 + n1);
- System.out.printlnt (n1+ “ ”+n2); [2]
Ans.
- 99100
- 9
- 10099
- 99 100
j . Write an expression for :
Ans. Math.pow ((x+y), 2) / (Math.cbrt(3)+y)
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 descriptions/Mnemonic Codes such that the logic of the program is clearly depicted.
Flow-Charts and Algorithms are not required .
Question 4.
Define a class employee having the following description:
Data members: | |
int Epan | : To store personal account number |
Instance variables | |
String Ename | : To store name. |
double taxincome | : To store annual taxable income. |
double tax | : To store tax that is calculated. |
Member functions: | |
inputData () | : Store the pan number, name, taxable income. |
cal() | : Calculate tax of an employee. |
display() | :Output details of an employee. |
Write a program to compute the tax according to the given conditions and display the output as per given format.
Total Annual Taxable Income | Tax Rate |
---|---|
Up to 1, 00, 000 | No tax |
From 1, 00, 001 to 1, 50, 000 | 10% of the income exceeding 1, 00, 000 |
From 1, 50, 001 to 2, 50, 000 | 5000+20% of the income exceeding 1, 50, 000 |
Above 2, 50, 000 | 25000+30% of the income exceeding 2, 50, 000 |
Output:
Pan Number Name Tax-Income Tax
………………. …………… ……………… …………..
………………. …………… ……………… …………..
import java.io.*;
public class Employee
{
int Epan;
double inc, tax;
String Ename;
public void inputData()throws IOException
{
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter the Pan Number");
Epan= Integer.parseInt(in.readLine());
System.out.println("Enter the name of the employee");
Ename=in.readLine();
System.out.println(" Enter the Taxable Income");
inc= Integer.parseInt(in.readLine());
}
public void cal()
{
if(inc<= 100000)
tax= 0;
else if(inc<= 150000)
tax=10* (inc-100000)/100;
else if(inc<= 250000)
tax= 5000+20*(inc-150000)/100;
else
tax= 25000+30* (inc-250000)/100;
}
public void display()
{
System.out.println("Pan Number\tName\tTaxablelncome\tTax ");
System.out.println(Epan+"\t" +Ename+"\t" + inc+"\t" +tax);
}
}
Variable Name | Data type/ Variable method | Purpose |
---|---|---|
Epan | Int | To store personal account number |
inc | Double | To store annual taxable income |
tax | Double | To store tax that is calculated |
Ename | String | To store name |
Question 5.
Write a program in Java to store 10 numbers each in two different Single Dimensional Array. Now, merge the numbers of both the arrays in a Single Dimensional Array. Display the elements of merged array
Sample Input:
Array a: | a[0] | a[1] | a[2] | a[3] | a[4] |
10 | 21 | 44 | 45 | 32 | |
Array b: | b[0] | b[1] | b[2] | b[3] | b[4] |
35 | 56 | 27 | 91 | 64 |
Sample Output:
The list after merging of two arrays:
c[0] | c[1] | c[2] | c[3] | c[4] | c[5] | c[6] | c[7] | c[8] | c[9] |
10 | 21 | 44 | 45 | 32 | 35 | 56 | 27 | 91 | 64 |
Ans.
import java.io.*;
public class MergeArray
{
public static void main(String args[])throws IOException
{
int a[]=new int[5];
int b[]= new int[5];
int c[]= new int[10];
int k=0, i;
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(read);
System.out.println("Enter 5 numbers in the first array: ");
for(i=0;i<5; i++)
{
a[i]=Integer.parseInt(in.readLine());
}
System.out.println("Enter 5 numbers in the second array: ");
for(i= 0;i<5; i++)
{
b[i]= Integer.parseInt(in.readLine());
}
for(i=0; i<5; i++)
{
c[i]=a[i];
}
for(i= 5; i<10; i++ )
{
c[i]=b[k];
k= k+1;
}
System.out.println("The list after merging of two arrays");
for(i=0;i<10; i++)
{
System.out.println(c[i]+" ");
}
}
}
Variable Description table:Variable Name Data type/ Variable method Purpose a[ ], b[ ] Int To store input array c[ ] Int To store and display merged array i, k Int Loop variable
Question 6.
Write a class to design the given function to perform the related tasks:
double volume1( double side )- to find and return volume of cube using (side*side*side).
double volume2( double l, double b, double h)- to find and return volume of cuboid using:(length*breadth*height).
double volume3( double r )- to find and return volume of cylinder using: ((4/3)πr^3)
Ans.
import java.util.Scanner;
public class Fuctions01
{
public double volume1(double s)
{
return (s*s*s);
}
public double volume2(double l, double b, double h)
{
return (l*b*h);
}
public double volume3(double r)
{
return ((4/3)*3.14*r);
}
}
Variable Description table:Variable Name Data type/ Variable method Purpose s Double Function argument L, b, h Double Function argument r Double Function argument
Question 7.
Using the switch statement, write a menu driven program for the following:
1 . To print the Floyd’s triangle [Given below]
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
2 . To display the following pattern
I
I C
I C S
I C S E
Ans.
import java.util.Scanner;
public class ICSE_Triangle
{
public static void main(String[] args)
{
System.out.print("(1)To print the Floyd’s triangle:");
System.out.println("\n1 \n12 \n123 \n1234 \n12345");
System.out.print("(2)To display the following pattern:");
System.out.println("\nI \nIC \nICS \nICSE");
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice)
{
case 1:
System.out.println("Enter the number of rows: ");
int n = scanner.nextInt();
int currentNumber = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(currentNumber + " ");
currentNumber++;
}
System.out.println();
}
break;
case 2:
String word = "ICSE";
for (int i = 0; i < word.length(); i++)
{
for (int j = 0; j <= i; j++)
{
System.out.print(word.charAt(j) + " ");
}
System.out.println();
}
break;
default:
System.out.println("Invalid choice");
break;
}
}
}
Variable Description table:Variable Name Data type/ Variable method Purpose choice int To input choice given by user n int To input number for Floyd’s triangle i, j int Loop variable
Question 8.
Write a menu driven program to display
(i) print if given number is buzz number or not
(ii) print if given number is Armstrong number or not.
Enter ‘1’ to check if given number is buzz numbers or not and enter ‘2’ to check if given number is Armstrong number or not.
Ans.
import java.util.Scanner;
public class NumberMenu
{
public void Nmenu() {
Scanner in = new Scanner(System.in);
System.out.println("Enter '1' to check if given number is buzz number or not ");
System.out.println("Enter '2' to check if given number is Armstrong number or not ");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
int num;
System.out.println("Enter number:");
num= in.nextInt();
switch (ch) {
case 1:
if(num % 10 == 7 || num % 7 == 0)
System.out.println("Buzz Number");
else
System.out.println("Not a Buzz Number");
break;
case 2:
double sum = 0;
int orgNumber = num, digit;
while(num>0)
{
digit = num%10;
sum = sum+Math.pow(digit,3);
num = num/10;
}
if(orgNumber == sum)
System.out.println ("Number is Armstrong");
else
System.out.println ("Number is not Armstrong");
break;
default:
break;
}
}
}
Variable Description table:Variable Name Data type/ Variable method Purpose ch int To store input choice num int Input number to be checked orgNumber int To store original number sum double Help to calculate number
Question 9.
Write a program to initialize the following character arrays and print a suitable message after checking the arrays whether the two arrays are identical or not. Make suitable use of boolean data type.
X[]={‘m’, ‘n’. ‘o’. ‘p’) and Y[]={‘m’, ‘a’, ‘o’, ‘p’}
Ans.
import java.io.*;
class IdenticalArray
{
public void Check()
{
char X[ ] = {'m', 'n', 'o', 'p'};14
char Y[ ] = { 'm', 'n', 'o', 'p'};
int sizeX = X.length;
int sizeY = Y.length;
boolean result = true;
System.out.println("Elements of array X = ");
for(int v= 0; v < sizeX; v++)
{
System.out.print(X[v]+"\t");
}
System.out.println("\nElements of array Y =");
for(int v= 0; v < sizeY; v++)
{
System.out.print(Y[v]+"\t");
}
if( sizeX != sizeY)
System.out.println("The arrays are not identical, because sizes of both the arrays are not same");
else
{
for(int v =0; v<sizeX; v++)
{
if( x[v] !=Y[v])
{
result = false;
break;
}
}
if( result = = true)
System.out.println("\n Both the arrays are identical ");
else
System.out.println("The given arrays are not identical, because the elements are not same");
}
}
}
Variable Description table:Variable Name Data type/ Variable method Purpose X[] char character array having characters Y[] char character array having characters SizeX int to find number of elements of X[]