ICSE Class 10 COMPUTER APPLICATIONS previous year paper (2018)
- Categories Sample Papers
COMPUTER APPLICATIONS
SECTION A (40 Marks)
Attempt all questions
Question 1. [2 marks each]
(a) Define abstraction.
(b) Differentiate between searching and sorting.
(c) Write a difference between the functions isUpperCase( ) and toUpperCase( ).
(d) How are private members of a class different from public members?
(e) Classify the following as primitive or non-primitive datatypes:
(i) char
(ii) arrays
(iii) int
(iv) classes
Ans.
(a) abstraction: the act of representing essential features and hide unnecessary or background details is called abstraction.
(b)
Searching | Sorting |
---|---|
To find an element in an array is called searching. | To arrange the elements in an order is called sorting. |
(c)
isUpperCase | toUpperCase |
---|---|
CHECKS whether a given character is an uppercase letter or not | CONVERTS the character to its upper case |
Output of this function is boolean | Output of this function is character. |
(d) public members can be accessed from any other class.
private members can only be accessed within the declared class.
(e) char – primitive array – non-primitive int – primitive class – non primitive
Question 2. [2 marks each]
(a) (i) int res = ‘A’;
What is the value of res?
(ii) Name the package that contains wrapper classes.
(b) State the difference between while and do while loop.
(c) System.out.print(“BEST “);
System.out.println(“OF LUCK”);
Choose the correct option for the output of the above statements
(i) BEST OF LUCK
(ii) BEST
OF LUCK
(d) Write the prototype of a function check which takes an integer as an argument and returns a character.
(e) Write the return data type of the following function.
(i) endsWith()
(ii) log()
Ans.
(a) (i) 65
(ii) lang
(b)
WHILE | DO-WHILE |
---|---|
Condition is checked first then statement(s) is executed. | Statement(s) is executed atleast once, thereafter condition is checked. |
It might occur statement(s) is executed zero times, If condition is false. | At least once the statement(s) is executed. |
No semicolon at the end of while. while(condition) | Semicolon at the end of while. while(condition); |
If there is a single statement, brackets are not required. | Brackets are always required. |
Syntax while (expression) { statement(s) } | do { statement(s) } while (expression); |
(c) (i) BEST OF LUCK
(d) char check (int n)
(e) (i) boolean
(ii) double
Question 3. [2 marks each]
(a) Write a Java expression for the following:
(b) What is the value of y after evaluating the expression given below?
y+= ++y + y– + — y; when int y=8
(c) Give the output of the following:
(i) Math.floor (-4.7)
(ii) Math.ceil(3.4) + Math.pow(2, 3)
(d) Write two characteristics of a constructor.
(e) Write the output for the following:
System.out.println(“Incredible”+”\n”+”world”);
(f) Convert the following if else if construct into switch case
if( var==1)
System.out.println("good");
else if(var==2)
System.out.println("better");
else if(var==3)
System.out.println("best");
else
System.out.println("invalid");
(g) Give the output of the following string functions:
(i) “ACHIEVEMENT”.replace(‘E’, ‘A’)
(ii) “DEDICATE”.compareTo(“DEVOTE”)
(h) Consider the following String array and give the output
String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
System.out.println(arr[0].length()> arr[3].length());
System.out.print(arr[4].substring(0,3));
(i) Rewrite the following using ternary operator:
if (bill >10000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
(j) Give the output of the following program segment and also mention how many times the loop is executed:
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i );
System.out.println( i * 4 );
Ans.
(a) Math. sqrt(3 ∗ x + x ∗ xx)/(a+ b) OR
Math.sqrt(3*x+Math.pow(x,2))/(a+b);
(b) 33
(c) i. -5.0
ii. 12.0
(d)(i) Constructors have the same name as that of the class they belong to.
(ii) Constructors are executed when an object is created.
(e) Incredible
world
(f)
switch(var)
{
case 1: System.out.println("good");
break;
case 2: System.out.println("better");
break;
case 3: System.out.println("best");
break;
default: System.out.println("invalid");
}
(g) (i) ACHIAVAMANT
(ii) -18
(h) (i) false
(ii) JAI
(i) discount = bill>1000? bill*10.0/100: bill *5.0/100;
(j) Output: 20
Loop is not executed even once
SECTION B (60 Marks)
Attempt any four questions from this Section
Question 4. [15 marks]
Design a class RailwayTicket with following description:
class | RailwayTicket |
---|---|
Instance variables/data members | |
String name | To store the name of the customer |
String coach | To store the type of coach customer wants to travel |
long mobno | To store customer’s mobile number |
int amt | To store basic amount of ticket |
int totalamt | To store the amount to be paid after updating the original amount |
void accept () | To take input for name, coach, mobile number and amount. |
void update () | To update the amount as per the coach selected |
void display () | To display all details of a customer such as name, coach, total amount and mobile number. |
(extra amount to be added in the amount as follows)
Type of Coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
Write a main method to create an object of the class and call the above member methods.
Ans.
import java.util.*;
class RailwayTicket
{
String name, coach;
long mobno;
int amt ,totalamt;
void accept()
{
Scanner sc = new Scanner(System.in);
System.out.println("enter name , coach and mobile no and amount");
name=sc.next();
coach=sc.next();
mobno=sc.nextLong();
amt=sc.nextInt(); }
void update()
{
if(coach. equalsIgnoreCase ("First_AC"))
totalamt=amt+700;
else if(coach. equalsIgnoreCase ("Second_AC"))
totalamt=amt+500;
else if(coach. equalsIgnoreCase ("Third_AC"))
totalamt=amt+250;
else
totalamt=amt;
}
void display() {
System.out.println("name is :"+name);
System.out.println("mobile no is :"+mobno);
System.out.println("coach is :"+ coach);
System.out.println("total amount is :"+totalamt); }
public static void main (String arg[])
{
RailwayTicket ob =new RailwayTicket();
ob.accept();
ob.update();
ob.display();
}
}
Question 5. [15 marks]
Write a program to input a number and check and print whether it is a Pronic number or not. (Pronic number is the number which is the product of two consecutive integers)
Examples: 12 = 3 × 4
20 = 4 × 5
42 = 6 × 7
Ans.
import java.util.*;
class pronic {
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
System.out.println("enter the number");
int num=sc.nextInt();
int flag=0;
for(int i=0;i<num;i++)
{
if( i*(i+1)==num)
{
flag=1;
break;
}
}
if(flag==1)
System.out.println("Pronic number");
else
System.out.println("Not a pronic number");
}
}
Question 6. [15 marks]
Write a program in Java to accept a string in lower case and change the first letter of every word to upper case. Display the new string.
Sample input: we are in cyber world
Sample output: We Are In Cyber World
Ans.
import java.util.*;
class ques6 {
public static void main(String args[]) {
Scanner obj= new Scanner(System.in);
String s="";
System.out.println(" enter a string");
String sen=obj.nextLine();
sen=' ' +sen;
int l= sen.length();
for(int x= 0; x<l; x++) {
char ch= sen.charAt(x);
if (ch==' ') {
int i= sen.charAt(x+1);
i=i-32;
s= s+ ' '+ (char)i;
x++; }
else s=s+ch;}
System.out.print(s);
}
}
Question 7. [15 marks]
Design a class to overload a function volume() as follows:
(i) double volume (double R) – with radius (R) as an argument, returns the volume of sphere using the formula.
V = 4/3 × 22/7 × R3
(ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.
V = 22/7 × R2 × H
(iii) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.
V = L × B × H
Ans.
import java .io.*;
public class mensuration
{
double volume(double R)
{
double V= 4.0/3* 22.0/7*Math.pow(R,3);
return(V);
}
double volume( double H,double R)
{
double V= 22.0/7 * Math.pow(R,2) *H;
return(V);
}
double volume( double L, double B , double H)
{
double V = L*B*H;
return( V);
}
}
Question 8. [15 marks]
Write a menu driven program to display the pattern as per user’s choice.
Pattern 1 Pattern 2
ABCDE B
ABCD LL
ABC UUU
AB EEEE
A
For an incorrect option, an appropriate error message should be displayed.
Ans.
import java .util.*;
class series
{
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
System.out.println("1.Series1 2.series2");
System.out.println("enter the choice");
int choice=sc.nextInt();
switch(choice)
{
case 1:String s="ABCDE";
for(int i=s.length();i>0;i––)
{
System.out.println(s.substring(0,i));
}
break;
case 2 :String s1="BLUE";
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<=i;j++)
{
System.out.print(s1.charAt(i)); }
System.out.println();
}
break;
default :System.out.println("invalid choice");
}
}
}
Question 9. [15 marks]
Write a program to accept name and total marks of N number of students in two single subscript array name[] and totalmarks[].
Calculate and print:
(i) The average of the total marks obtained by N number of students.
[average = (sum of total marks of all the students)/N]
(ii) Deviation of each student’s total marks with the average.
[deviation = total marks of a student – average]
Ans.
import java .io.*;
import java.util.*;
class ques9
{
public static void main(String aa[])
{
Scanner obj = new Scanner(System.in);
int n;
System.out.println("enter number of students");
n= obj.nextInt();
String name[] = new String[n];
double marks[] = new double[n];
double ave, total=0.0;
for(int x=0; x<n; x++)
{
System.out.println(" enter name and totalmarks");
name[x]= obj.nextLine();
marks[x]= obj.nextDouble();
total=total+ marks[x];
}
ave= total/n;
System.out.println("Name " + " " + " Deviation");
for(int x= 0; x<n;x++)
System.out.println( (marks[x]–ave));
}
}