ICSE Class 10 COMPUTER APPLICATIONS previous year paper (2016)
- Categories Sample Papers
COMPUTER APPLICATIONS
SECTION A (40 Marks)
Attempt all questions
Question 1. [2 marks each]
(a) Define Encapsulation.
(b) What are keywords? Give an example.
(c) Name any two library packages.
(d) Name the type of error ( syntax, runtime or logical error ) in each case given below:
(i) Math.sqrt (36 – 45)
(ii) int a;b;c;
(e) If int x [ ] = { 4, 3 , 7, 8, 9, 10}; what are the values of p and q?
(i) p = x.length
(ii) q= x[2] + x[5] * x[1]
Ans.
(a) The wrapping up of data and functions (that operate on the data) into a single unit( called class) is known as encapsulation
OR
It is the way of combining both data and the functions that operate on that data under a single unit.
(b) Keywords are the words that convey a special meaning to the language Compiler. These are reserved for special purpose and must not be used as normal identifiers.
(c) java.io.* or io package
java.util.* or util package
(d) (i) Runtime error
(ii) Syntax error
(e) (i ) 6
(ii) 37
Question 2. [2 marks each]
(a) State the difference between == operator and equals ( ) method .
(b) What are the types of casting shown by the following examples:
(i) char c = (char)120;
(ii) int x = ‘t’;
(c) Differentiate between formal parameter and actual parameter.
(d) Write a function prototype of the following :
A function PosChar which takes a string argument and a character argument and returns an integer value.
(e) Name any two types of access specifiers.
Ans.
(a) == is an operator which is used to check the equality between primitive data type equals () function checks the equality between Strings
(b) (i) explicit type casting
(ii) implicit type casting
(c) Actual parameter : The parameter which is present in the function call statement is called actual parameter. It stores the original value.
The parameter which is present in function prototype or function signature is called formal parameter. It stores the duplicate value.
(d) int PosChar( String s, char ch)
(e) public /private/protected
Question 3. [2 marks each]
(a) Give the output of the following string functions :
(i) “MISSISSIPPI”.indexOf(‘S’)+ “MISSISSIPPI”.lastIndexOf(‘I’)
(ii) “CABLE”.compareTo(“CADET”)
(b) Give the output of the following Math functions :
(i) Math.ceil(4.2)
(ii) Math.abs(-4)
(c) What is a parameterized constructor?
(d) Write down java expression for :
T = √(A² + B² + C²)
(e) Rewrite the following using ternary operator:
if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
(f) Convert the following while loop to the corresponding for loop:
int m = 5, n = 10;
while (n>=1)
{
System.out.println(m*n);
n-- ;
}
(g) Write one difference between primitive data types and composite data types
(h) Analyze the given program segment and answer the following questions:
(i) Write the output of the program segment
(ii) How many times does the body of the loop gets executed?
for (int m=5; m<=20; m+=5)
{
if (m%3==0)
break;
else
if (m%5==0)
System.out.println(m);
continue;
}
(i) Give the output of the following expression :
a+= a++ + ++a + –a + a– ; when a = 7
(j) Write the return type of the following library functions:
(i) isLetterOrDigit(char)
(ii) replace(char, char)
Ans.
(a) (i) 2 +10 = 12
(ii) – 2
(b) (i) 5.0
(ii) 4
(c) Constructors that take arguments are called parameterized constructors
(d) Math.sqrt(Math.pow(A,2)+ Math.pow( B,2)+ Math.pow(C,2))
OR
Math.sqrt((A*A+B*B+C*C))
(e) System.out.println((x%2==0)?”EVEN”:”ODD”);
(f)
for ( int m = 5 , n = 10; n > = 1; n-- )
{
System.out.println ( m * n ) ;
}
(g)
Primitive Data Type | Composite data types. |
---|---|
Data types that are provided by Java are called primitive types | Data types created by programmers which make use of primitive type to create a variable as per the user’s requirement are called non-primitive or composite data types. |
The size is fixed. | The size depends on the number of member variables and their types. |
When a variable of primitive data type is defined only one memory location is allocated | When an object(variable) of class type is defined the memory allocated will vary. |
To create a variable of primitive type ‘new’ keyword is not used. | To create an object variable we make use of ‘new’ keyword. |
(h) m = 5
10 Loop is executed 3 times
(i) a = 7 + 7 + 9 + 8 + 8 = 39
(j) boolean and String
SECTION B (60 Marks)
Attempt any four questions from this Section
Question 4. [15 marks]
Define a class named BookFair with the following description :
class name | BookFair |
---|---|
Instance variables /Data members : | |
String Bname – | stores the name of the book |
double price – | stores the price of the book |
Member methods : | |
BookFair() | Default constructor to initialize data members |
void Input() | To input and store the name and the price of the book. |
void display() | To display the name and price of the book after discount. |
void calculate() | To calculate the price after discount. Discount is calculated based on the following criteria |
Price Discount
Less than or equal to Rs.1000 2% of price
More than Rs. 1000 and less than or equal to Rs. 3000 10% of price
More than Rs. 3000 15% of price
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class BookFair {
String Bname;
double price;
BookFair() {
Bname="";
price =0.0d; }
void input() {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Name and Price " );
Bname=sc.next();
price=sc.nextDouble(); }
void calculate() {
if(price<=1000)
price= price-price*2/100;
else if(price<=3000)
price =price-price*10/100;
else
price =price-price*15/100; }
void display() {
System.out.println("Name :" +Bname);
System.out.println("Price :" +price); }
public static void main(String args[])
{
BookFair obj=new BookFair();
obj.input();
obj. calculate();
obj.display();
}
}
Question 5. [15 marks]
Using the switch statement , write a menu driven program for the following:
(i) To print the Floyd’s triangle [Given below]
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
(ii) To display the following pattern
I
I C
I C S
I C S E
For an incorrect option, an appropriate error message should be displayed.
Ans.
import java .util.*;
class ques5 {
public static void main(String args[]) {
Scanner obj = new Scanner (System.in);
int choice,x; System.out.println("Enter 1 pattern1 , 2 Pattern2");
choice =obj.nextInt();
switch(choice) {
case 1: int r, c, k = 1;
for (r = 1; r <= 5 ; r ++) {
for (c=1;c<=r;c++) {
System.out.print(“ “+k);
k++;
}
System.out.println();
}
break;
case 2:
String s="ÏCSE";
for(int i=0;i<s.length();i++ ) {
System.out.println(s.substring(0,i+1)); }
break;
default : System.out.println("Sorry wrong choice");
}
}
}
Question 6. [15 marks]
Special words are those words which starts and ends with the same letter.
Examples:
EXISTENCE
COMIC
WINDOW
Palindrome words are those words which read the same from left to right and vice-versa
Examples:
MALAYALAM
MADAM
LEVEL
ROTATOR
CIVIC
All palindromes are special words, but all special words are not palindromes. Write a program to accept a word check and print whether the word is a palindrome or only special word.
Ans.
import java .util.*;
class ques6
{
public static void main (String s[])//throws IOException
{
Scanner obj = new Scanner(System.in);
System.out.println(" enter a word ");
String word = obj.nextLine();
String rword="";
int l,x;
l= word.length();
for(x=l-1;x>=0;x--)
rword = rword+ word.charAt(x);
if(word.equals(rword))
System.out.println( word +" is palindrome");
else
if(word.charAt(0) == word.charAt(l-1))
System.out.println( word +"is a special word");
}
}
Question 7. [15 marks]
Design a class to overload a function SumSeries() as follows :
(i) void SumSeries(int n, double x) – with one integer argument and one double argument to find and display the sum of the series given below :
s = x/1 – x/2 + x/3 – x/4 + x/5… to n terms
(ii) void SumSeries() – To find and display the sum of the following series :
s = 1 + (1 × 2) + (1 × 2 × 3)+. … + (1 × 2 × 3 × 4 … × 20)
Ans.
import java.util.*;
class Q7 {
void SumSeries(int n, double x) {
double sum=0.0d;
int i;
for(i=1;i<=n;i++)
{ if (i%2==0 )
sum=sum-x/(double)i;
else
sum=sum+x/(double)i; }
System.out.println("sum="+sum);
}
void SumSeries() {
int s=0, p=1;
for(int i=1;i<=20;i++) {
p=p*i;
s=s+p; }
System.out.println("sum="+s);
}
public static void main(String args[]) {
Q7 obj=new Q7();
obj.SumSeries(5,2.0);
obj.SumSeries();
}
}
}
Question 8. [15 marks]
Write a program to accept a number and check and display whether it is a Niven number or not. (Niven number is that number which is divisible by its sum of digits).
Example :
Consider the number 126.
Sum of its digits is 1+2+6 = 9 and 126 is divisible by 9.
Ans.
import java.util.*;
class Niven
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
System.out.println("enter number");
int num=sc.nextInt( );
int n=num;
int rem;
int sum=0;
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
if(n%sum==0)
System.out.println("Niven number");
else
System.out.println("not Niven Number");
}
}
Question 9. [15 marks]
Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for a name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”.
Seven wonders – CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations – MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example – Country Name : INDIA Output : INDIA – TAJMAHAL Country Name : USA Output : Sorry Not Found!
Ans.
import java.util.*;
class wonders
{
public static void main(String args[])
{
String w[]={"CHICHEN ITZA","CHRIST THE REDEEMER", "TAJMAHAL", "GREATWALL OF CHINA","MACHU PICCHU","PETRA","COLOSSEUM"};
String l[]={"MEXICO","BRAZIL","INDIA","CHINA","PERU","JORDAN","ITALY"};
String s;int i,len;
Scanner br=new Scanner(System.in);
System.out.println("Enter the name of the country to be searched for " );
s=br.nextLine();
len=w.length; // OR len = l.length;
boolean flag=false;
for (i=0;i<len;i++) // OR for( i=0;i<7;i++)
{
if(s.equalsIgnoreCase(l[i]))
{
System.out.println(l[i]+" - "+ w[i]);
flag =true; break;
}
}
if(flag== false)
System.out.println("Sorry Not Found");
}
}