ICSE Class 10 COMPUTER APPLICATIONS previous year paper (2017)
- Categories Sample Papers
COMPUTER APPLICATIONS
SECTION A (40 Marks)
Attempt all questions
Question 1. [2 marks each]
(a) What is inheritance?
(b) Name the operators listed below:
(i) <
(ii) ++
(iii) &&
(iv) ? :
(c) State the number of bytes occupied by char and int data types.
(d) Write one difference between / and % operator.
(e) String x[] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”};
Give the output of the following statements:
(i) System.out.println(x[1]);
(ii) System.out.println(x[3].length ( ));
Ans.
(a) Inheritance allows a class to use the properties and methods of another class. In other words, the derived class inherits the states and behaviors from the base class. The derived class is also called subclass and the base class is also known as super-class OR Inheritance is the process by which one object acquires the properties of another object.
(b) (i) relational operator
(ii) unary increment operator
(iii) logical operator
(iv) ternary or conditional operator
(c) char – 2 bytes , int – 4 bytes
(d) / – It is a division operator. It gives the quotient.
% – It is a modulus operator. It gives the remainder.
(e) NOKIA
8
Question 2. [2 marks each]
(a) Name the following:
(i) A keyword used to call a package in the program.
(ii) Any one reference data type.
(b) What are the two ways of invoking functions?
(c) State the data type and value of res after the following is executed:
char ch=’t’;
res= Character.toUpperCase(ch);
(d) Give the output of the following program segment and also mention the number of times the loop is executed:
int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b ==0)
break;
}
System.out.println(a);
(e) Write the output:
char ch = ‘F’;
int m = ch;
m=m+5;
System.out.println(m + ” ” + ch);
Ans.
(a) (i) import
(ii) class / array / String/ interface
(b) (i) Call by value OR Pass by value
(ii) Call by reference OR Pass by reference
(c) char & T
(d) Output: 12,
Loop is executed two times.
(e) 75 F
Question 3. [2 marks each]
(a) Write a Java expression for the following:
axˆ5 + bxˆ3 +c
(b) What is the value of x1 if x=5?
x1= ++x – x++ + –x
(c) Why is an object called an instance of a class?
(d) Convert following do-while loop into for loop.
int i = 1;
int d=5;
do {
d=d*2;
System.out.println(d);
i++ ; } while ( i<=5);
(e) Differentiate between constructor and function.
(f) Write the output for the following:
String s="Today is Test" ;
System.out.println(s.indexOf('T'));
System.out.println(s.substring(0,7) + " " +"Holiday");
(g) What are the values stored in variables r1 and r2:
(i) double r1 = Math.abs(Math.min(-2.83, -5.83));
(ii) double r2 = Math.sqrt(Math.floor(16.3));
(h) Give the output of the following code:
String A ="26", B="100";
String D=A+B+"200";
int x= Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println("Result 1 = "+D);
System.out.println("Result 2 = " +d);
(i) Analyze the given program segment and answer the following questions:
for(int i=3;i<=4;i++ ) {
for(int j=2;j<i;j++ ) {
System.out.print("" ); }
System.out.println("WIN" ); }
(i) How many times does the inner loop execute?
(ii) Write the output of the program segment.
(j) What is the difference between the Scanner class functions next() and nextLine()?
Ans.
(a) a* Math.pow(x,5) +b*Math.pow( x,3)+c [OR]
a*(x*x*x*x*x)+b*(x*x*x)+c
(b) x1 = 6
(c) An object is based on the blueprint as specified by the class or the copy of the class, every object of a class reserves the memory of the same capacity of that of a class.
(d)
for (int i =1 ,d=5; i<=5 ; i++)
{
d= d*2;
System.out.println(d);
}
(e)
Constructor | Method/function |
---|---|
1. It is always defined by the same name as of the class | 1. It is defined by any name except class name and keyword. |
2. It has no return type not even void data type | 2. It must begin with either void or a valid return data type (such as int, float, char etc.). |
3. It initializes the data members of the class. | 3. A method contains one or more than one valid Java statements as its body. |
4. It can not be invoked/called like a method because a constructor automatically runs whenever an object of the class is created. | 4. A method must be invoked or called either by using object of the class or directly. |
(f) 0
Today i Holiday [OR] Today Holiday
(g)(i) 5.83
(ii) 4.0
(h) Result 1= 26100200
Result 2=126
(i) (i) 3
(ii) WIN
WIN
(j)
next() | nextLine() |
---|---|
Finds and returns the next complete token from this scanner. | nextLine() reads input including space between the words i.e. it reads till the end of line |
Can read the input only till the space. | Can read spaces |
It places the cursor in the same line after reading the input. | Once the input is read, nextLine() positions the cursor in the next line. |
SECTION B (60 Marks)
Attempt any four questions from this Section
Question 4. [15 marks]
Define a class Electric Bill with the following specifications:
class | ElectricBill |
---|---|
Instance variables / data member: | |
String n | to store the name of the customer |
int units | to store the number of units consumed |
double bill | to store the amount to be paid |
Member methods: | |
void accept( ) | to accept the name of the customer and number of units consumed |
void calculate( ) | to calculate the bill as per the given tariff: |
void print ( ) | To print the details as follows: Name of the customer: ……………………… Number of units consumed: ……………………… Bill amount: ……………………… |
Number of units Rate per unit
First 100 units Rs.2.00
Next 200 units Rs.3.00
Above 300 units Rs.5.00
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
public class ElectricBill {
int units;
String n;
double bill;
Scanner ob = new Scanner (System.in);
void accept() {
System.out.println("Enter Name of the customer");
n=ob.next();
System.out.println("Enter Number of units consumed");
units=ob.nextInt(); }
void calculate() {
if (units<=100)
bill=units*2;
else if (units >100 && units <=300)
bill=100*2+(units-100)*3;
else
bill=100*2+200*3+(units-300)*5;
if (units>300)
bill=bill+2.5/100*bill; }
void print() {
System.out.println("Name of the customer:"+n);
System.out.println("Number of Units consumed :"+units);
System.out.println("Bill Amount :"+bill); }
public static void main(String args[]) {
ElectricBill obj=new ElectricBill();
obj.accept();
obj.calculate();
obj.print(); }
}
Question 5. [15 marks]
Write a program to accept a number and check and display whether it is a spy number or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: consider the number 1124, Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1 × 1 × 2 × 4 = 8
Ans.
public class SpyNumber
{
void print (int n)
{
int i, s=0, p = 1,d;
while (n>0)
{
d=n%10;
n=n/10;
s+=d;
p*=d;
}
if (s==p)
System.out.println( "It is a spy number");
else
System.out.println( " It is not a spy number");
}
}
Question 6. [15 marks]
Using switch statement, write a menu driven program for the following:
(i) To find and display the sum of the series given below:
S = x^1 − x^2 + x^3 − x^4 + x^5. . . . . . . . . . . . . . . .. − x^20
(where x = 2)
(ii) To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be displayed.
Ans.
import java.util.*;
class series {
public static void main(String arg[]) {
System.out.println("1.series_1 2.series_2 ");
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
int choice=sc.nextInt();
switch(choice) {
case 1: double sum=0.0;
int x=2;
for (int i=1;i<=20;i++)
{
if (i%2==0)
sum =sum-Math.pow(x,i);
else
sum =sum+Math.pow(x,i);
}
System.out.println("sum is ="+sum);
break;
case 2 : int s=0;
for(int i=1 ;i<=5 ;i++)
{
s=s*10+1 ;
System.out.print(s +" " );
}
break;
default :System.out.println("invalid choice");
}
}
}
Question 7. [15 marks]
Write a program to input integer elements into an array of size 20 and perform the following operations:
(i) Display largest number from the array.
(ii) Display smallest number from the array.
(iii) Display sum of all the elements of the array.
Ans.
import java.util.*;
class array
{
public static void main(String arg[])
{
Scanner sc =new Scanner(System.in);
System.out.println("enter numbers");
int a[ ]=new int [20];
for(int i=0;i<20;i++)
{
a[i]=sc.nextInt();
}
int max=a[0];
int min=a[0];
int sum= 0;
for(int i=0;i<20;i++)
{
if( a[i]>max)
max = a[i];
if(a[i]<min)
min=a[i];
sum=sum+ a[i];
}
System.out.println("largest number is"+ max);
System.out.println("smallest number is"+min);
System.out.println("sum is "+ sum);
}
}
Question 8. [15 marks]
Design a class to overload a function check( ) as follows:
(i) void check (String str , char ch ) – to find and print the frequency of a character in a string.
Example:
Input: Output:
str = “success” number of s present is =3
ch = ‘s’
(ii) void check(String s1) – to display only vowels from string s1, after converting it to lower case.
Example:
Input:
s1 =”computer” Output: o u e
Ans.
class overload
{
public static void check(String s ,char ch)
{
int c=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)==ch)
c++;
}
System.out.println("number of "+ ch+ " present is="+c);
}
public static void check(String s1)
{
s1=s1.toLowerCase();
for(int i=0;i<s1.length();i++)
{
char ch = s1.charAt(i);
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
System.out.print(ch+" ");
}
}
public static void main(String arg[])
{
check("success", 's');
check("computer");
}
}
Question 9. [15 marks]
Write a program to input forty words in an array. Arrange these words in descending order of alphabets, using selection sort technique. Print the sorted array.
Ans.
public class Selection
{
String m[]=new String[40];
Selection(String z[])
{
m=z;
}
void sort()
{
int i, p, j; String s,t;
for (i=0;i<40;i++)
{
s=m[i];
p=i;
for (j=i+1;j<40;j++)
{
if (m[j].compareTo(s)>0)
{
s=m[j];
p=j;
}
}
t=m[i];
m[i]=m[p];
m[p]=t;
}
for (i=0;i<40;i++)
System.out.println(m[i]);
}
}