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

Guess Paper - 2013 Class - X Subject - Computer Applications

1. The document contains answers to questions on various computer science concepts like access specifiers, polymorphism, data abstraction, casting, escape sequences, and more. 2. A binary search program is described to search a phone number entered by the user in an array containing details of 10 people. It prints the matching details or a message if not found. 3. A program is outlined to accept a sentence from the user, form a word using the first letter of each word, reverse it, and check if it is a palindrome using a reverse() function.

Uploaded by

Anish Lahiri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Guess Paper - 2013 Class - X Subject - Computer Applications

1. The document contains answers to questions on various computer science concepts like access specifiers, polymorphism, data abstraction, casting, escape sequences, and more. 2. A binary search program is described to search a phone number entered by the user in an array containing details of 10 people. It prints the matching details or a message if not found. 3. A program is outlined to accept a sentence from the user, form a word using the first letter of each word, reverse it, and check if it is a palindrome using a reverse() function.

Uploaded by

Anish Lahiri
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1

Guess Paper 2013


Class X
Subject Computer Applications

1.a)Explain private and protected access specifiers.
Ans Private access specifier :- Private access specifer denotes a variable or method as
being private to the class and it can be accessed only by the class. It can not be
accessed outside the class. It is the most restrictive access level, We need the keyword
private to do declare any private member.
Eg. class test
{
private int a;
private void sum()
{+
Sysetm.out.print(it is a private access);
} }
Protected access specifier denotes a denotes a variable or method as being public to
the subclasses of the class but private to all other classes outside the current package.
Derived classes have the ability to access protected variables of its parent
Eg package test;
class demo
{ protected int a;
}

b) Difference between switch case and if else
Switch-case IF else
I) Switch case is a multiple branching if-else is a branching statement
Statement which can test equality which can test logical and relational
condition. condition.
ii) switch-case labels are constant so if-else can test ranges.
ranges can not be checked
iii) only char and int values can be any value like floating point and
strings can
checked. be checked.
eg. switch(a) if (a ==1)
{ x=1 ;
case 1. else
X=1; x=2;
Break;
Case 2:
X=2.
Break

}
c) What is the purpose of + operator in a string ?
Ans The + operator concatenates two strings. It adds two strings.
e.g. comp +uter will retrun computer.

d) What is the use of polymorphism ?

2
Ans. Polymorphism means the same operation or function may behave differently on
different classes. Polymorphism is implemented by function overloading in Java where
different function are defined by same name having either different data type, different
number of formal parameter or different return type.
public int sum(int a int b)
{ return a+b;}
public float sum(float a)
{
return a++);} }

e) How java implements data abstraction ?
Ans Abstraction refers to the act of representing essential features without including the
background details or explanations. In java abstraction focuses upon observable
behaviour. In java abstraction is a named collection of attributes and bahaviour relevant
to modeling a given entity for some particular purpose.

2 a) What is casting and why do we need it.
Ans The explicit conversion of an operand to a specific type is called casting or type
casting.It is a user-defined type conversion and it forces an expression to be of specific
type.
When user needs to convert a data type to a specific data type then user uses type
casting.
Eg. char x = (char) 65. here 65 is an integer. The user forces 65 to change to A.

b) True.

c) Difference between syntax error and logical error.
Syntax error logical error
a) The violation of grammatical rules in program- Apart from syntax error and
runtime
ming language is known as syntax error error the error that causes improper
output is known as logical error.
b) They are identified during program compilation This error is never identified
during
Or interpretation. Compilation.

c) then can be identified and corrected easily. It is not easy to identify a
logical error.
eg. systemoutrprentln(name eg for(i=5;i>=1;i++)
Eg. Systemoutprintlnmyname
What is the use of static keyword in java ?
Ans. Static means that there will only be only one instance of that object in the class. If
an object is not declared static a new copy of that object is made for every instance of
the class that is initialized. We can call static variable or method directly without having
to initialize the class at all, which is why if we declare the function main as static then
java does not have to initialize the object at all to access the entry point (main function).
Eg. static variable :- static int a;
Static method public static void main()
e) Using ternary operator rewrite the following code.
public void perfect(int no) {
int i,s=0;

3
for(i=1;i<no ;i++){
if (no%i == 0)
s+=i; }
if (s ==no)
system.out.println(n+perfect no ); }
ans :- public void percect(int no)
{
int i,s=0;
(for(i=1;i<no;i++) {
s=(no%i ==0) :s+i:s; }
System.out.println((s==no)?perfect no:not perfect no); }}

3a) Define escape sequence.
java allows certain non-graphic characters in character constants which cannot be
typed directly from keyboard like back space(\b), tabs(\t) etc. They are represented using
escape sequence. The escape sequence is represented using backslash and the
character like \b ,\t, \v,\n. etc. The characters used with escape sequence carry
special meaning and have special purpose. .

b) Define dynamic binding.
Dynamic binding is the process to link the function call with function signature during
program execution. The compiler generates address code of the function signature and
applies the function call position in the caller program. The control gets transferred to the
address available at function call position.
c) a = 48, b=10
a += b++ *5 /a++ + ++b
a+= 50/48 + 12
a+= 1+12
48+13 = 61 (it followed multiply then divide)
or
a+= 10 * 5/48 + 12
a+= 0+12
48 + 12 = 60 (it followed divide then multiply though the 2
nd
one is more applicable).

d) Define life time of a variable.
The life time of a variable can be defined as the period by which the variable is active
within a program.During the execution of a Java program, each variable has its own time
within which it can be accessed. This is called the lifetime of the variable. We can
determine the lifetime of variables by looking at the context in which they're defined.
e)what will be the output
int a;
for(a=0;a<10;a++)
if (a==5)
break;
System.out.printlln( + a);)
0
1
2
3
4
f) The following function find() show the dry run

4
Int find(int n, int p)
{
while(n>b)
{
n--;
p++;
System.out.print(n + \t + p);
}
outpuat if find(12,8)
11 9
10 10

4 a) identify errors
i) int new = 17
new is a keyword so new be used int x = 17.
ii) String a = a ans. string constants are used with so answer will be String a.
b) find outrput when val = 8 and n = 5
if (val >10)
n*= ++n +(--n);
else
n/= n++ *n + val
5/= 5*6+8
5/=30+8
5/= 38
ans may be 0 or 0.131

c) Difference between isUpper() and toUpper()
isUppercase() toUppercase()
isUpper is string function which toUppercase() is a String method that returns a
is used to check whether a charactercharacter to uppercase.
is in uppercase.
It returns a boolean value. It returns a character value.
Eg.if isUpper(x) == true x = toUppercase(a);
d) What is function prototype.
Function prototype is the first line of a function definition that tells the program about
the type of value returned by the function and the number and type of arguments.
Eg. public static int sum(int a, int b)
e)) create an object for the class employee
employee obj = new employee(compi,1,480);
SECTION B
5A computer keeps information of 10 person with their phone no, name and address.
Write a program using binary search where user enters any phone number and
computer prints the phone number, name and address. If information is not traced then
print information does not exist.
Ans. class BinSearch
{
public static void main(String args[]) throws IOException
{
int phno[] = new int [10].
String name[] = new String [10].
String add[] = new String [10].

5
int i, f,l, mid, pos, ph, flg;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.rpintln(enter 10 phone number, name and address);
for (i=0; i<10;i++)
{
phno[i] = Integer.parseInt(br.readLine());
name[i] = br.readLine();
add[i] = br.readLine();
}
System.out.rpintln(enter phone number to search);
ph = Integer.parseInt(br.readLine());
f=0,l=9;mid=0, pos =0,flg=0;
while
(f<=l)
{
mid = (f+l)/2;
if (phno[mid] == ph)
{
flg = 1;
pos = mid;
}
if (ph<phno[mid])
l=mid-1;
if(ph>[phno[mid]]
f = mid+1;
}// end of search
if (flg == 1)
{
System.out.println (phome number + \t+phno);
System.out.println (name + \t + name[pos]);
System.out.println (address + \t + add[pos]);
}
else
System.out.println (information does not exist);
} // end of main method
} // end of class
6. WAP to accept a sentence and form a word with the first letter of each word .
/using function reverse() reverse the word and check if it is a palindrome.
Ans. class Pallindrome
{
public static String reverse(String str)
{
String rv= ;
int len= str.length()
for(int I = len-1;i>=0;i--)
{
char x = str.charAt(i)
rv = rv+x;
}
return rv;
}

6
public static void main(String args[]) throws IOException
{
Sting sent,wrd = ;
int I,len, flg=0;
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.pintln(enter a sentence);
sent = br.readLine();
sent = + sent;
len = sent.length();
for(I = 0;i<len ;i++)
{
c = sent.charAt(i);
if (c == )
char ch= sent.charAt(i+1);
w = w +ch;
}//word formation complete
if (w.equalsIgnorecase(reverse(w)) == true)
System.out.println(It is a palindrome);
else
System.out.println(It is not a palindrome);
}
}
7. class courier
data members name,weight
parameterized constructor courier(String, int) to initialize variable with parameter.
Member function void display() to calculate bill fir 1
st
700 gms Rs. 20/- for each
additional 100 gms and fraction thereof Rs. 5 /-
Ans. Class courier {
String name;
int weight;
courier(String nm, int wt)
{ name = nm;
weight =wt;
}
void display()
{
double ch;
if (weight <= 700)
ch = 20;
if (weight>700)
ch = 20 +( (weight-700)/100) * 5;
System.out.println(Weight + \t + weight + \t+charge = +\t + ch);ll
}
public static void main(String args[])
{
courier obj = new courier(COMPUTER,750);
obj.display();
}}
8 Write a program to accept a word and arrange its letters in alphabetic order.
Ans. Class Arrange

7
{
public static void main(String args[]) throws IOException
{
String wd,ns = ;
char c;
int i,len,j,k;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.pintln(enter a word);
wd = br.readline();
len=wd.length();
char ch[] = new char[len];
for(i = 0;i<len;i++)
{ ch[i] = wd.charAt(i);
} // arrange
for(j=0;j<ch.length; j++)
(for( k = 0;k<ch.length-j-1; k++)
{
if (ch[k] > ch[k+1])
{
c = ch[kj];
ch[k] = ch[k+1];
ch[k+1]=c;
}}}
for(j=0;j<ch.length;j++)
{
ns = ns+ch[j];
}
System.out.println(ns);
}}//end of class
9. Write a program using following function i) void display(int n, char c) if c = s
then find the area of a square else find the area of a circle. ii) void display(int a,int b,
char c) if c = r then find the area of a rectangle else find the area of a triangle.


Ans. class Area
{
public static void display(int n, char c)
{
if (c ==s )
{
int ar= n*n;
System.out.println(Area of square +ar);
}
else
{
ar = 3.14 *n*n;
System.out.println(Area of circle +ar);
}}//end of method
public static void display(int a, int b, char c)
{
if (c ==r )

8
{
int ar= a*b;
System.out.println(Area of rectangle +ar);
}
else
{
ar = (a*b)/2;
System.out.println(Area of triangle +ar);
}}//end of method
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int x =5,y=9;
char ch=s;
char x1=r;
System.out.println(Enter 1 for area of circle or square and 2 for area of rectangle or
triangle);
c = Integer.parseInt(br.readLine());
switch(c)
{
case 1:
display(x,ch);
break;
case 2:
display(x,y,c1);
}//end of switch
}}//end of class
10. Write a menu driven program to perform the following:
(a) find the sum of all even Armstrong numbers between for a specific range.
(b) 1
11
121
1331
14641
class menu
{
public static boolean Armstrong(int n)
{
int r,copy = n,s = 0;
while(copy !=0)
{
r = copy%10;
copy/=10;
s = s + r;
}
if (s ==n)
return true;
else
return false;
}//ends method

9
public static void main(String args[])
{
int ch,I,x,m,n
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(Enter 1 for Armstrong number 2 for pattern);
ch= Integer.parseInt(br.readLine());

System.out.println(Enter number );
n= Integer.parseInt(br.readLine());
switch(ch)
{
case 1;
System.out.println(Enter lower and Upper limit);
m = Integer.parseInt(br.readLine());
n = Integer.parseInt(br.readLine());
int s = 0;
for(I = m;i<=n;i++){
if (Armstrong(n) ==true) &&( n%2 ==0)
s = s + I ; }
System.out.println(sum = +s); }
break;
case 2:
for(I = 0;i<=4;i++){
x= Math.pow(11,i);
System.out.println(x); }
break; }//end of switch }}
11. Write a program using function prime to print the prime Fibonacci numbers up to nth
term.
import java.io.*;
public class primefibo {
public static int isprime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i == 0) c++;
}
if(c == 2)
return(0);
else
return(1);
} //ends method
public static void main()throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
System.out.print("Enter range:-");
n=Integer.parseInt(br.readLine());
int a=0,b=1,c=0,i;

10
for(i=3;i<=n;i++)
{
c = a+b;
a=b;
b=c;
if (isprime(c) == 0)
{
System.out.print(c + " "); }}}}
12. Write menu driven program to print the i) special numbers within a specific range, ii)
check if a number is magic number
import java.io.*;
public class special_magic
{
public void special(int n)
{
int a = n,s=0,b,f,i;
while(n>0)
{
b = n%10;
f=1;
//find factorial
for(i=1;i<=b;i++)
{
f=f*i;
}
n/=10;
s = s+f;
}
//check special number
if (s==a)
System.out.println("Special number"+a);
else
System.out.println("not a special number "+ a);
}
public void magic(int n)
{
int s=0,no=n,r;
s=n;
while(s>9)
{s = 0;
while(n>0)
{
r = n%10;
n = n/10;

11
s = s +r;}
n=s;
}
if (s ==1)
System.out.println("the number is magic" + n);
else
{System.out.println("the number is not magic"+n);}}
public static void main()throws IOException
{
int n,ch,i,j,fact,c;
double s=0.00d,d=0.00d;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("1 special");
System.out.println("2 magic ");
//accept choice
System.out.print("Enter choice: ");
ch =Integer.parseInt(in.readLine());
System.out.print("Enter the no ");
n =Integer.parseInt(in.readLine());
special_magic obj = new special_magic();
switch(ch)
{
//first series
case 1:
obj.special(n);
break;
case 2:
obj.magic(n);
break;
}}}//class ends

12
13. Using function check() write a program to check is a number is Automorphic or a
number is duck number.
import java.io.*;
import java.lang.Math;
public class duck_auto {
public void check(int n){
int a = n,s=0,b=0,f,i;
s = n*n;
while(a>0) {
b++;
a/=10;}
double p=s%Math.pow(10,b);
if (p==n)
System.out.print("Automorphic no " + n); }
public int check(int a)
{
int b,x=0;
while(a>0)
{
b = a%10;
a/=10;
if (b ==0)
x++;}
if (x>=1)
return 1;
else
return 0;
}
public static void main()throws IOException {
int n,ch,i,j,fact,c;
double s=0.00d,d=0.00d;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("1 automorphic");
System.out.println("2 duck ");
//accept choice
System.out.print("Enter choice: ");
ch =Integer.parseInt(in.readLine());
System.out.print("Enter the no ");
n =Integer.parseInt(in.readLine());
duck_auto obj = new duck_auto();
switch(ch){
//first series
case 1:
obj.checkn);

13
break;
case 2:
int a = obj.check(n);
if (a == 0)
System.out.println(duck no);
else
System.out.println(not duck);
break;
}}}//class ends


Paper Submitted By:

Name: Susmita chakravarty
Email : [email protected]

You might also like