0% found this document useful (0 votes)
7 views

2016

The document contains a solved question paper for ICSE Class 10 Computer Applications from 2016. It includes various programming concepts such as encapsulation, keywords, error types, string functions, and class definitions, along with sample code for different programming tasks. Additionally, it covers topics like constructors, access specifiers, and menu-driven programs.

Uploaded by

amalambikaschool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

2016

The document contains a solved question paper for ICSE Class 10 Computer Applications from 2016. It includes various programming concepts such as encapsulation, keywords, error types, string functions, and class definitions, along with sample code for different programming tasks. Additionally, it covers topics like constructors, access specifiers, and menu-driven programs.

Uploaded by

amalambikaschool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

2016

Solved 2016 Question Paper


ICSE Class 10 Computer
Applications
Class 10 - ICSE Computer Applications
Solved Question Papers

Section A

Question 1

(a) Define Encapsulation.

Answer

Encapsulation is a mechanism that binds together code and the data it manipulates. It keeps
them both safe from the outside world, preventing any unauthorised access or misuse. Only
member methods, which are wrapped inside the class, can access the data and other methods.

(b) What are keywords ? Give an example.

Answer

Keywords are reserved words that have a special meaning to the Java compiler. Example:
class, public, int, etc.

(c) Name any two library packages.

Answer

Two library packages are:

1. java.io
2. java.util

(d) Name the type of error ( syntax, runtime or logical error) in each case given below:

1. Math.sqrt (36 – 45)


2. int a;b;c;

Answer
1. Runtime Error
2. Syntax Error

(e) If int x[] = { 4, 3, 7, 8, 9, 10}; what are the values of p and q ?

1. p = x.length
2. q = x[2] + x[5] * x[1]

Answer

1. 6
2. q = x[2] + x[5] * x[1]
q = 7 + 10 * 3
q = 7 + 30
q = 37

Question 2

(a) State the difference between == operator and equals() method.

Answer

equals() ==

It is a method It is a relational operator

It is used to check if the contents of two strings It is used to check if two variables refer to the same
are same or not object in memory

Example: Example:
String s1 = new String("hello"); String s1 = new String("hello");
String s2 = new String("hello"); String s2 = new String("hello");
boolean res = s1.equals(s2); boolean res = s1 == s2;
System.out.println(res); System.out.println(res);

The output of this code snippet is true as contents The output of this code snippet is false as s1 and s2
of s1 and s2 are the same. point to different String objects.

(b) What are the types of casting shown by the following examples:

1. char c = (char) 120;


2. int x = ‘t’;

Answer

1. Explicit Cast.
2. Implicit Cast.
(c) Differentiate between formal parameter and actual parameter.

Answer

Formal parameter Actual parameter

Actual parameters appear in function call


Formal parameters appear in function definition.
statement.

They represent the values received by the called They represent the values passed to the called
function. function.

(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.

Answer

int PosChar(String s, char ch)

(e) Name any two types of access specifiers.

Answer

1. public
2. private

Question 3

(a) Give the output of the following string functions:

1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
2. "CABLE".compareTo("CADET")

Answer

1. 2 + 10 = 12

⇒ 66 - 68
2. ASCII Code of B - ASCII Code of D

⇒ -2

(b) Give the output of the following Math functions:

1. Math.ceil(4.2)
2. Math.abs(-4)

Answer

1. 5.0
2. 4

(c) What is a parameterized constructor ?

Answer

A Parameterised constructor receives parameters at the time of creating an object and


initializes the object with the received values.

(d) Write down java expression for:

T=A2+B2+C2T=A2+B2+C2
Answer

T = Math.sqrt(a*a + b*b + c*c)

(e) Rewrite the following using ternary operator:

if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
Answer

System.out.print(x%2 == 0 ? "EVEN" : "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--;
}
Answer

int m = 5;
for (int n = 10; n >= 1; n--) {
System.out.println(m*n);
}
(g) Write one difference between primitive data types and composite data types.

Answer

Primitive Data Types are built-in data types defined by Java language specification whereas
Composite Data Types are defined by the programmer.

(h) Analyze the given program segment and answer the following questions:
1. Write the output of the program segment.
2. 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;
}
Answer

Output

5
10
Loop executes 3 times.

Below dry run of the loop explains its working.

m Output Remarks

5 5 1st Iteration

5
10 2nd Iteration
10

5
15 3rd Iteration — As m % 3 becomes true, break statement exists the loop.
10

(i) Give the output of the following expression:

a+= a++ + ++a + --a + a-- ; when a = 7

Answer

⇒ a = a + (a++ + ++a + --a + a--)


a+= a++ + ++a + --a + a--

⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39

(j) Write the return type of the following library functions:

1. isLetterOrDigit(char)
2. replace(char, char)
Answer

1. boolean
2. String

Section B

Question 4

Define a class named BookFair with the following description:

Instance variables/Data members:


String Bname — stores the name of the book
double price — stores the price of the book

Member methods:
(i) BookFair() — Default constructor to initialize data members
(ii) void Input() — To input and store the name and the price of the book.
(iii) void calculate() — To calculate the price after discount. Discount is calculated based on
the following criteria.

Price Discount

Less than or equal to ₹1000 2% of price

More than ₹1000 and less than or equal to ₹3000 10% of price

More than ₹3000 15% of price

(iv) void display() — To display the name and price of the book after discount.

Write a main method to create an object of the class and call the above member methods.

Answer

import java.util.Scanner;

public class BookFair


{
private String bname;
private double price;

public BookFair() {
bname = "";
price = 0.0;
}
public void input() {
Scanner in = new Scanner(System.in);
System.out.print("Enter name of the book: ");
bname = in.nextLine();
System.out.print("Enter price of the book: ");
price = in.nextDouble();
}

public void calculate() {


double disc;
if (price <= 1000)
disc = price * 0.02;
else if (price <= 3000)
disc = price * 0.1;
else
disc = price * 0.15;

price -= disc;
}

public void display() {


System.out.println("Book Name: " + bname);
System.out.println("Price after discount: " + price);
}

public static void main(String args[]) {


BookFair obj = new BookFair();
obj.input();
obj.calculate();
obj.display();
}
}

Output
Question 5

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

(b) To display the following pattern:


I
IC
ICS
ICSE

For an incorrect option, an appropriate error message should be displayed.

Answer

import java.util.Scanner;
public class KboatPattern
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Floyd's triangle");
System.out.println("Type 2 for an ICSE pattern");

System.out.print("Enter your choice: ");


int ch = in.nextInt();

switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;

case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;

default:
System.out.println("Incorrect Choice");
}
}
}

Output
Question 6

Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice-
versa.
Example: MALYALAM, 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 display whether the word is a palindrome or
only a special word or none of them.

Answer

import java.util.Scanner;

public class KboatSpecialPalindrome


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.next();
str = str.toUpperCase();
int len = str.length();

if (str.charAt(0) == str.charAt(len - 1)) {


boolean isPalin = true;
for (int i = 1; i < len / 2; i++) {
if (str.charAt(i) != str.charAt(len - 1 - i))
{
isPalin = false;
break;
}
}

if (isPalin) {
System.out.println("Palindrome");
}
else {
System.out.println("Special");
}
}
else {
System.out.println("Neither Special nor
Palindrome");
}

}
}

Output
Question 7

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=x1−x2+x3−x4+x5... ... ... to n termss=1x−2x+3x−4x+5x


... ... ... 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)s=1+
(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)
Answer

public class KboatOverload


{
void sumSeries(int n, double x) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double t = x / i;
if (i % 2 == 0)
sum -= t;
else
sum += t;
}
System.out.println("Sum = " + sum);
}

void sumSeries() {
long sum = 0, term = 1;
for (int i = 1; i <= 20; i++) {
term *= i;
sum += term;
}
System.out.println("Sum=" + sum);
}
}

Output
Question 8

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.

Answer

import java.util.Scanner;

public class KboatNivenNumber


{
public void checkNiven() {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();
int orgNum = num;

int digitSum = 0;

while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
}

/*
* digitSum != 0 check prevents
* division by zero error for the
* case when users gives the number
* 0 as input
*/
if (digitSum != 0 && orgNum % digitSum == 0)
System.out.println(orgNum + " is a Niven number");
else
System.out.println(orgNum + " is not a Niven
number");
}
}

Output

Question 9

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, TAJ MAHAL, GREAT WALL OF CHINA,
MACHU PICCHU, PETRA, COLOSSEUM
Locations:
MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY

Examples:
Country name: INDIA
Output: TAJ MAHAL

Country name: USA


Output: Sorry Not found!

Answer

import java.util.Scanner;

public class Kboat7Wonders


{
public static void main(String args[]) {

String wonders[] = {"CHICHEN ITZA", "CHRIST THE


REDEEMER", "TAJMAHAL",
"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA",
"COLOSSEUM"};

String locations[] = {"MEXICO", "BRAZIL", "INDIA",


"CHINA", "PERU", "JORDAN",
"ITALY"};

Scanner in = new Scanner(System.in);


System.out.print("Enter country: ");
String c = in.nextLine();
int i;

for (i = 0; i < locations.length; i++) {


if (locations[i].equals(c)) {
System.out.println(locations[i] + " - " +
wonders[i]);
break;
}
}

if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}

Output

You might also like