0% found this document useful (0 votes)
31 views12 pages

Computer Practise Paper 1 (Solved)

This document summarizes a question paper for a computer applications theory exam. The exam is divided into two sections, Section A with multiple choice questions worth 40 marks, and Section B with 4 out of several questions worth 60 marks. The summary is: Section A contains multiple choice questions worth 40 marks total. Candidates must attempt all questions in this section. Section B contains several questions worth 60 marks total, and candidates must attempt 4 questions from this section. The exam allows 2 hours for completion and the first 15 minutes are for reading the paper only.

Uploaded by

Deepali Koirala
Copyright
© © All Rights Reserved
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)
31 views12 pages

Computer Practise Paper 1 (Solved)

This document summarizes a question paper for a computer applications theory exam. The exam is divided into two sections, Section A with multiple choice questions worth 40 marks, and Section B with 4 out of several questions worth 60 marks. The summary is: Section A contains multiple choice questions worth 40 marks total. Candidates must attempt all questions in this section. Section B contains several questions worth 60 marks total, and candidates must attempt 4 questions from this section. The exam allows 2 hours for completion and the first 15 minutes are for reading the paper only.

Uploaded by

Deepali Koirala
Copyright
© © All Rights Reserved
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/ 12

Computer Applications

(THEORY)
(Ttwo Hours)
Answer to this paper must be written on the paper provided separately.
You will not be allowed to write answer for the first 15 minutes.

This time is to be spent on reading the question paper.


Ihe time given at the head of this paper is the time allowed for writing the answer

This paper is divided into two sections.


all questions from section A and any four questions from section B.
Attempt
The intended marks for questions or parts of questions are given in brackets [ ].

SECTION A (40 Marks)


Attempt all questions
While answering questions from this part,
indicate briefly your working and reasoning, wherever required.
Q.1 (a) Give one example each of a primitive data type and a composite
data type. 21
Ans. Example of primitive data type: int, float, double, long, char etc.
interface etc.
Example of composite data type : array, class,
(b) Give one point of difference between unary and binary operators
Ans. Unary operator is used to perform operation on single operand. Eg, +, , ++
(2
+
etc.
Binary operator performs operation on two operands. E.g, t, , *, / and %
(c) Differentiate between call by value and call by reference or pass by
reference.
2
Ans. Call by value Call by reference
The actual parameter is copied to the The actualparameter is referred by the
formal parameter in such a way that any formal parameter (Both use the same
change made in the formal parameter memory address) in such a
way that any
does not affect the actual parameter. The change made in the formal parameter
actual parameter remains intact. is reflected onto the actual
parameter
Hence, actual parameter also changes
accordingly
All primitive type data are passed to the All non-primitive type data are
method by using pass by value. E.g., int,
passed to
the function by using pass by reference
float, double, long, char etc. system. E.g., array, object etc.

(d) Write ajava expression for V(2as+u ). [2


Ans. Java expression : Math.sqrt(2*a*s + u*u);
(e) Name the type of error (syntax, runtime or logical error) in each case given
below:
i) Division by a variable that contains a value of zero.
(i) Multiplication operator used when the operation should be
division
(ii) Missing semicolon.
Ans. 1) Run
time error
(ii) Logical error
(iii) Syntax error
Q.2 (a) Create
classconstructor.
) Default
a
with one using:
2
variable
integer
(i) Parameterized constructor. nstance. Initialize
the

Ans. () class sample

int
sample()
a=0;
Default constructor

(ii) class sample

int a;

sample(int n) //
Parameterized constructor
a=n;

h) Complete the code below to


create
Scanner sc =
an
object of scanner class.
Scanner
Ans. The complete code is as follows: 2
Scanner sc= new
Scanner(System.in);
(c) What is array? Write a statement to declare an integer array of
an
10 elements.
2
Ans. An array is a memory structure created that contains a number of variables with
same variable name but with different subscripts in order to deal with a number
of data values.
Statement to declare an array to contain 10 integers:
int al ] = new int [10]; OR
int [ Ja = new int [10];
that: (21
(d) Name the search or sort algorithm next smallest item in
through the array, selecting the
(i) Makes several passes in the array.
and it where it belongs
placing
the array each time value with the key value of the

compares
the sought key
(11) At each stage,
middle element of the array.
Ans. () Selection Sort
member
(i) Binary Search modifiers for
the
private [21
between public and
Ditterentiate

of a class.
declared to be private has its cess
accee

appliedimited tn
member
modifier: A class
private
member be ann
Ans. Private can a

outssde
means

the class premises only. By n o


the class block.
that is
declared to be public can be accesse
class member
Public modifier: A detault, a class member
is
By
inside as

to be public.
well as outside the class
block.
dedared
and y when the following statements
What are the values of x
Q.3 (a)
are executed?

int a=63, b=36;


boolean x=(a>b)?a:b;
int y=(a<b)?a:b;
Ans. The statement given below is wrong:

boolean x=(a>b)?a:b;
should be:
boolean x=(a>b)?true: false; then,
x = true
y = 36

(b) State the values of n and ch. 21


char c="'A;
int n=c+1;
char ch=(char)n;
Ans. Value of-
1) n =66
(i) ch = B
(c) What will be the result stored in x after evaluating the following expression?

int x=4;x+=tx++)+(++x)+x;
Ans. x = 20

(d) Give the output of the following program segment 2


double x=2.9y=2.5;
System. out. println(Math.min(Math. floortx),y);
System. out. println(Math.max(Math.ceil(x),y);
Ans. 2.0
3.0
(e) State the output of the following program segment. 2
String s="Examination";
int n=s.length0;

System.out.println(s.startsWith(s.substring(5,n);
System.out-println(s.charAt(2)==s.charAt(6));
Ans. False
True
( State the method that:
(i) Converts a string to a primitive float data type.
ii) Determines if the specified eharacter is an uppercase character.
Ans. ) Float.parseFloat(String argument)
(i) Character.is UpperCase(Character argument)
Ctate the data type and
g
values of a and b after
segment 1s executed,
the
following
String s1-"Computer", s2="Applications"; 2
a (s1.compare To
(s2);
b= (s1.equals (s2);
a is int and
Data type of value is 2.
1ns.

b
type of i Boolean and value
Data is false.
will be the
h)
string s="malayalam"
What following code output?
code

121
System.out.printi
ntln(s.indexOf('m'));
System.outprintlnís.lastIndexOf('m'));
Ans. 0

rite the following program segment


Re using vhile instead of for statement.
21
int f=1,
f o r l i = 1 i < = 5 ; i + + )

f = i ; System.out.println();}

Ans. int =1,i=1;

whilei<=5)

System.out.println(f); i++
( -i;
t o the program given below, state the name and the value of the (2
or argument variable
) method argumernt
(ii) class variable

i ) local variable

(iv) instance variable

class myClass {
static int x=7;
int y=2;
void main(String args[]){
public static
= n e w myClass();
my Class obj
System.outprintin(x);

obj.sampleMethod(5);

int a=6;
System.out.println(a);|

void sampleMethod(int n){


System.out.println(n);
System.out.println(y);

n with value
5.
Method argument variable -

5, 0) argument or
with value
Class variables x with value 7 and y
() -

(un) Local variable - a with value 6.


wInstance variable -

obj (Object of the class).


SECTIONB (60 Marks)
Atlempt any four questions from this Section.
The answer in this section should consist of the Program either in Blue] enie
program environment with Java as the base. Each program should he
ariable description/Mnemonic Codes so that the logic of the program is clesi
ironment or o
en

Flow Charts and Algorithms are not required, clearty depicte


Q.4 Define a class called
library with the following description:
Instant variables / Data members:
int acc_num stores the accession number of
-

String title the boe


stores the title of the book. book.
String author stores name of the author.
Member methods:
() void input() To input and store accession
-

ii) void computel) To number, title and


accept the number of days late, calculate and
the fine Charge at the rate Rs.
2 per
Gii) void display() To display the details in the day.
Accession Number Title Author
following
format
Write a main method to create an
methods.
object of the class and call the above
Ans. import java.util.Scanner;
me
membe
class library

int acc_num;
String title;
String author;
Scanner in =new
void input() Scanner(System.in);

System.out.println("Enter accession number");


acc num in.nextlnt();
=

System.out.println("Enter
title = in.next();
title of the
book");
System.out.println("Enter
author = in.next(); author name");
void compute()

int n,fine;

System.out.println("Enter number of days late");


n in.nextint();
fine = n*2;

System.out.println("Fine to be
paid\t"+fine);
void display()
tln("Accession Number\t"+"Title\t"+"Author");
r i n t l n ( a c c _ n u m + " \ t " + t i t l e + " \ t " t a u t h o r ) ;

System.c
stem.out.print

class xyz

main(String
args[)
void.
static
pu bil
ublic

ibrary ob=new library();

ob.input);

ob.compute);

ob.display0

V a r i a b l e D e s c r i p t i o n :

Description
Data Type
Variable Accession number.

int
book.
Title of the
A c c _ n u m

String book.
title name of the
Author
String the book.
late in returning
author
Number of days
int library
to the
Fine to be paid male
int income tax for
rate of
fine
table showing
hypothetical

below is a
Given of 65 year: Rs.
0.5 below the age Income
Tax in
citizens
Rs.
income (T) in
Taxable
Nil
7 1,60,000 10%
exceed 1,60,000) x
Does not (TI
-

than or
and less
1,60,000
than 7
Is greater + 34,000
equal t o 5 , 0 0 . 0 0 0 5,00,000) x
20%]
[(TI
-

than or
and less
7 5,00,000
than
s greater + 94,000
equal to 8,00,000 8,00,000) x
30%]
T(TI
-

F 8,00,000 income
s greater than and
taxable
female)
(male or
female,
display
gender is
to input
the age, or the gender gender
and the
a program than 65 years
te to 65 years
If the age is given
more

than or equal the table


aperson. is less as per
If the age tax payable [15
"rOng category". the
income
.
and display
1s
male
e compute

above.
Ans. import java.util.Scanner;
class incometax

public static void main(String args|)


int age:String g;
double ti,tax=0.0D;
Scanner in=new Scanner(System.in);
System.out.println("Enter gender M-for male, F-for female");
g-in.next();
System.out.println("Enter age of the person )
age=in.nextlnt();
System.out.println("Enter taxable income");
ti-in.nextDouble();
if(age<=65 && g.equals("M"))
if(ti<=160000)
tax=0.0D;:
if(ti>160000 && ti<=500000)
tax=(ti-160000)*10.0/100.0;
if(ti>500000 && ti<=-800000)
tax=(ti-500000.0)*20.0/100.0)+34000.0;
if(ti>800000)
tax=((ti-800000)*30/100)+94000.0;
System.out.println("Income tax ="+tax);
else

System.out.println("Wrong category");
Variable Description:
Variable Data Type
Description
age Int
Age of the taxable person.
String Gender of the
person.
ti double Taxable income.
tax
double Tax to be
paid.
Q.6 Write a
program to accept
string. a
output the number of double letterConvert the string to uppercase. Coun
and

sequences that exist in the string


Sample input: SHE WAS FEEDING THE
"

Sample output : 4 LITLE RABBIT WITH


AN AP 15

Ans. import java.util.Scanner;


class stringop

public static void main(String args[|)


er in=new canner(System.in);
String str;
int il.count=0;

char cd;
Svstem.out.println("Enter a sentence"),

s t r = i n . n e x t L i n e ( ) ;

Estr.length();

for(i-0,i<l-1,it+)

cstr.charAt(i);

d-str.charAtfi+1);

if(c==d)

count++;

Custem.out.printn("Number of words with repeating characters" count)

Variable Description:

Variable Data Type Description


int Loop variable.

int Length of the string.


characters.
int To count the consecutive same
Count

String To store a string.


str
characters.
char To contain consecutive
cd
as follows:
class to overload a function polygon()
Q.7 Design a
with one integer and one character type
void polygonfint n, char ch) -

of
i) a filled square
argument to draw ch.
stored in
side n using the character
that draws a
with two integer arguments
x, int y)
-

(ii) void polygon(int x and breadth


filled rectangle of length
the symbol @.
y, using
that draws a filled
-
with no argument
(i) void polygon() rectangle shown below.

Example:
i) Input value of n=2, ch = "O

Output: O0
00
value of 2, y = 5
ii) Input x =

@@@@0®
Output:
(ii) Output:
*

*** [15
Ans. class pattern

void
polygon(int n, char ch)
int ij;
tori=1;i<=n;i++)
for(j=1j<=nj++)
System.out.print(ch);
System.out.println|);
void
polygon(int x, int y)
int ij;
fori=1;i<=x;i++)
for(j=1;j<=yj++)
System.out.print(®);
System.out.println();
void polygon()

int ij
for(i=1;i<=3;i++)
forj=1j<=ij++)
System.out.print("*);
System.out.printn();

Variable Description:
Variable Data Type
Description
n int Number of rows.
ch char Character to be
displayed.
int
Loop variables.
int
Length and breadth of rectangle.

Q.8 Using a
switch statement write a menu driven
i) Generate and display the first 10 terms of program to:
the Fibonacci series
0, 1, 1, 2, 3, 5..
The first two Fibonacci numbers are 0 and
1, and each subsequent number
is the sum of the previous two.
) Find the sum of the
Sample Input:
digits of an
integer that is
15390 input.
Sample Output: Sum of the
For an incorrect choice, an
digits =
18

displayed. appropriate error message should be

Ans. import java.util.Scanner: 115)


class numbers

public static void


main(String args[])
int i,j,k,l,n,s.ch,r;
Scanner in=new Scanner(System.in);
System.out.println("1. Generate fibonacci series"
System.out.printin("2. Sum of digits");
System.out.println(Enter your choice")
ch-in.nextlnt);
switch(ch)

case 1:
i-0;
j=1;
System.out.println("Elements of fibonacci series");
System.out.println(i);
System.out.println(j);
for(l-0;lk=8;1++)

k=i+j;
System.out.printn(k);
ij
j=k;
break;
case 2:
System.out.println("Enter a number");
n=in.nextlnt();
s=0;
while(n>0)

r=n%10;
S-S+r;
n=n/10;

System.out.println("Sum of series \t"+s)


break;
default:
ystem.out.println("Invalid choice");
Variable Description: Description

Variable Data Type


initial value 0.
contain
To
int
value 1.
contain initial
To
int
To contain sum ofi and j.
k int
Loop variable.

1 int
Switch variable.
ch int
Number to input.
n int

Sum of digits of the number.


S int

digit from the


int To obtain a

number.

Write program to accept


the names of 10 cities in a single dimensin
Q.9 a
(Subscribers trunk dialing) codes in another sin
string array and their STD
dimension integer array. Search for the name of a city input by the userin
list. If found, display "Search Successful" and print the name of the city alon
with its STD code, or else display the message "Search unsuccessful, no Sueh

city in the list". [15


Ans. import java.util.Scanner;
class city

public static void main(String args[})

Scanner in=new Scanner(System.in);


String ctll=new String[10);
int std[=new int[10];
int i,f=0;
String cty
System.out.printin("Enter city name and std codes");
fori=0;i<10;i++)

ctlij=in.next|);
std[1]=in.nextlnt();

System.out.println("Enter a city name to be searched");

cty=in.next();
f-0;
for(i=0;i<10;i++)
if(cty.equals(ct[i]))

f=1;
break;

iff-=1)
System.out.println("Search successful with city name\t"+ct[i]+"Std code

t+stdli]);

Crstem.out.println("Search unsuccessful, no such city in the list");

Variable Description:

Variable Data Type Description


ct[ ] String To contain the names of 10 cities.

int To contain std code of the cities.


std[
int Loop variable.

int Flag variable.

City to be searched.
cty String name

You might also like