You are on page 1of 14

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION

CLASS XII-FIRST COMMON PRE-BOARD EXAMINATION - 2013-14


COMPUTER SCIENCE(083)
ANSWER KEY
Time Allowed: 3hrs

Maximum Marks: 70

Instructions:
(i)
All questions are compulsory.
(ii)
Programming language: C++
1. (a) What do you understand by default argument and constant argument? Explain 2
with example.
Ans.
Default Argument
Constant Argument
An argument declared with some An argument declared with const
value known as default value in a keyword in a function definition.
function definition.
When calling the function the default Argument must be passed while
argument may or may not be passed. calling the function.
If the argument is not passed a value Argument is not allowed to be
it will assume the default value for the modified by the function.
argument. Argument is allowed to be
modified by the function.
E.g:
void function(const int a, int b=20)
{
a = a + b ; //error can not modify const a
cout<<b; //will display value of b(if passed) or 20 (if not passed)
}
void main()
{
int m;
m=10;
function(m); //second argument not passed, will use default value
}
1-mark for explanation
1-mark for correct example
(b) Write the header files compulsory required to execute the following c++ code:
1
void main(){
char Text[40];
strcpy(Text,"AISSCE");
puts(Text);
Page 1 of 14

}
Ans:
(i).string.h
(ii). Stdio.h
(1/2 marks for each)
(c) Read the given C++ code carefully, which is supposed to count the number of 2
character a or character A from a string argument str. But it contains some
logical error and does not produce the required output. Write the corrected
required code without adding any new statement in the code:
void count_a_A(char str[30])
{
int i,count=0;
for(i=0; i!='\0' ; i++)
{
if(str[i]='a' && str[i]='A')
count + 1 ;
}
cout<<"Count = "<<count<<endl;
}
Ans:
void count_a_A(char str[30])
{
int i,count=0;
for(i=0; str[i]!='\0' ; i++)
{
if(str[i]=='a' || str[i]=='A')
count=count + 1 ;
}
cout<<"Count = "<<count<<endl;
}
marks for each correction (1/2 marks for both == correction)
(d) Observe the following C++ code carefully and write the output:
3
#include<iostream.h>
int a=5;
void callme(int i,int &j, int k=1)
{
a+=i;
j=i+k;
k++;
cout<<i<<','<<j<<','<<k<<endl;
}
void main()
{
int a=10, b=20;
Page 2 of 14

callme(a,::a,b);
cout<<a<<','<<::a<<','<<b<<endl;
callme(::a,a);
}
Ans:
10,30,21
10,30,20
30,31,2
1-mark for each line of correct output
(e) Observe the following C++ code carefully and write the output:
2
#include<iostream.h>
void main()
{
int a[]={30,33,44,55,66},i=0;
while( i++ < 4 )
{
a[i]%2!=0 ? cout<<a[i]<<'#' : cout<<a[i]<<endl;
}
}
Ans:
33#44
55#66
1-mark for each line of correct output
(f) Observe the given c++ code carefully and select the incorrect output out of 2
options (i) to (iv), if the value of n is 4. Also justify your answer:
#include<iostream.h>
#include<stdlib.h>
void main()
{
int n,k,i;
cout<<"Enter value of n: ";
cin>>n;
randomize();
for(i=0;i<4;i++)
{
k=random(n);
n--;
cout<<k<<':';
}
}
(i). 3:2:1:0:
(ii). 2:2:1:0:
(iii). 3:2:3:0:
(iv). 0:0:0:0:
Page 3 of 14

Ans:
(iii). 3:2:3:0
Reason: Loop runs 4 times
1st time value of k(random(4)) can be between 0-3
2nd time value of k (random(3)) can be between 0-2
3rd time value of k (random(2)) can be between 0-1,
Hence in option (iii) 3rd number can not be 3, as it can be either 0/1. So it is
wrong option.
4th time value of k (random(1)) can be only 0.
1-mark for correct option
1-mark for justification
2. (a) What do you mean by polymorphism? Explain with the help of c++ code.
2
Ans:
1-mark for correct definition
1-mark for correct code example of function overloading
(b) Given the following C++ code, answer (i) & (ii):
2
class Date
{
int dd,mm,yy;
public:
Date();
//function-1
Date(int,int,int);//function-2
Date(Date &d); //funciton-3
void getDate(); //function-4
~Date();
//funciton-5
};
(i). Which function(s) will be invoked if the following statement is executed:
Date d1;
Date d2(d1);
(ii). Define the coding of function-3 outside the class.
Ans:
(i). function-1 and function-3
(ii). Date::Date(Date &d)
{dd=d.dd; mm=d.mm; yy=d.yy; }
(1-mark for each subdivision)
(c) Define a class Ticket as per the given details:
4
Private Members:
To of type string (for storing destination city)
From of type string (for storing start city)
Distance of type integer.
Fare of type float.
BasicFare of type float.
A function AssignFare() to assign the value of Fare as BaseFare +
DistanceFare, where DistanceFare is calculated as per the distance and Rate
Page 4 of 14

per KM as given below:


Distance(in KM)
Rate/KM(in Rs)
<=500
20 Rs/Km
>500 & <=1000
15 Rs/Km
>1000
10 Rs/Km
Public Members:
A function Input() to accept the values of all data members except Fare from
user and to call the function AssignFare() to calculate and assign value of Fare.
A function Output() to display all data members.
1-mark for correct class syntax with correct data member declaration
1-mark for correct AssignFare() function
1-mark for Input()
1-mark for Output()
Cut mark if not calling AssignFare() from Input() correctly.
(d) Answer (i) to (iv) based on the given code:
4
class MNC
{
int Cname[25];
protected:
char Hoffice[25];
public:
MNC();
char Country[25];
void EnterData();
void DisplayData();
};
class Branch : public MNC
{
int NOE;
char Country[25];
protected:
void Association();
public:
Branch();
void Add();
void Show();
};
class Outlet : public Branch
{
char State[25];
public:
Outlet();
void Enter();
void Output();
Page 5 of 14

};
(i). Which classs constructor will be called first at the time of declaration of an
object of class Outlet.
(ii). How many bytes does an object belonging to class Outlet require?
(iii). Which one out of the following can not be accessed by the member function
of class Outlet:
(a). State[ ] (b). Association( ) (c). Hoffice[ ] (d). Cname[ ]
(iv). Name the data member(s) which are accessible from the object of class
Branch.
Ans:
(i). MNC()
(ii). 152 bytes
(iii).Cname[]
(iv). Country[]
1-mark for each
3. (a) Write a function Rearrange(int A[ ][30],int B[ ], int r,int c, int &s) in C++ which 2
should copy all the elements of 2-D array A into 1-D array B row wise. (where r is
row size, c is column size, and s is the number of elements in array B after
copying the elements of A).
E.g. if the 2-d array A is
10 20 30 40
50 60 70 80
then the content of array B should be:
10 20 30 40 50 60 70 80
Ans:
void Rearrange(int A[ ][30],int B[ ], int r,int c, int &s)
{
int i,j,k;
for(i=0,k=0;i<r;i++)
for(j=0;j<c;j++,k++) //1mark for correct loop
B[k]=A[i][j]; //1/2 mark for correct assignment
s=k; //1/2 mark (including function syntax & variables)
}
(b) Write a function merge(?) in C++ which accepts two 1-D array and their sizes as 3
arguments and copy the elements in a third 1-D array such that the first element
is from first array, second element is from second array, third element is from first
array, fourth element is from second array and so on. If any one of them is
exhausted it should copy all the remaining elements of another array.
e.g. if the given array is
10 17 15 13 12
and the second array is
20 25 29
then the resultant array should be:
10 20 17 25 15 29 13 12
Ans:
Page 6 of 14

void merge(int a[],int b[],int c[], int sa,int sb)


{
int i,j,k;
for(i=0,j=0,k=0;i<sa&&j<sb;) //1mark for correct loop
{
if(k%2==0)//1-mark for correct alternate assignment
c[k++]=a[i++];
else
c[k++]=b[j++];
}
while(i<sa) //1mark for assigning remaining elements
c[k++]=a[i++];
while(j<sb)
c[k++]=b[j++];
}
(c) An array DATA[1..10][1..10] requires 4 bytes for each element. If the base 3
address of the array is 1500, determine the location of DATA[4][5], when the
array is row wise.
Row wise formula: (1/2 mark)
&A[i][j]=BA+ES[(i-Lr)C + (j-Lc)]
(1/2 marks for correct identification of parameters and substitution)
Lr=1 , Lc=1, Ur=10, Uc=10
I=4 , j=5
BA=1500 , ES=4
(1/2 mark for finding Column Size)
Column size = Uc-Lc+1 = 10-1+1 = 10
C=10
(1.5 marks for correct calculation and answer)
&DATA[4][5] = 1500 + 4*[(4-1)*10 + (5-1) ]
=1500 + 4 * 34 = 1500 + 136 = 1636
ANS = 1636
(d) Define function stackPush() to insert nodes and stackPop() to delete nodes, for a 4
linked list implemented stack having the following structure for each node:
struct node
{
char name[20];
int age;
node *Link;
};
class stack
{
node *top;
public:
Page 7 of 14

stack()
{ top=NULL; }
void stackPush();
void stackPop();
};
Ans:
void stack::stackPush()
{
node *newnode;
newnode = new node ;
if(newnode==NULL)
{
cout<<"Overflow";
getch();
return;
}
cout<<"Enter name and age: ";
gets(newnode->name);
cin>>newnode->age;
newnode->Link=top;
top=newnode;
}
void stack::stackPop()
{
node *temp;
if(top==NULL)
{
cout<<"Underflow.";
getch();
return;
}
temp=top;
top=top->Link;
cout<<"Following node is deleted:\n";
cout<<"Name: "<<temp->name<<endl;
cout<<"Age: "<<temp->age<<endl;
delete temp;
}
2-marks for each function
(e) Convert the following infix expression to its equivalent postfix expression 2
showing stack contents for the conversion:
A + B * (C - D) / E
Ans: (A + B * (C - D) / E)
Page 8 of 14

Element
Stack
Output Expression
(
(
A
(
A
+
(+
A
B
(+
AB
*
(+*
AB
(
(+*(
AB
C
(+*(
ABC
(+*(ABC
D
(+*(ABCD
)
(+*
ABCD/
(+/
ABCD-*
E
(+/
ABCD-*E
)
ABCD-*E/+
ANS: ABCD-*E/+
(1-mark for correct table)
(1-mark for correct answer)
4. (a) Observe the given C++ code and write statement-1 & statement-2 to perform the 1
required task:
class score
{
char playername[30];
long score;
public:
void getscore();
void putscore();
};
void main()
{
ifstream file;
file.open("file.dat",ios::in|ios::binary);
score s;
____________________//statement-1
____________________//statement-2
s.putscore(); //displaying last record
file.close();
}
(i). Write statement-1 to place the get pointer/cursor at the beginning of last
record.
(ii). Write statement-2 to read the record at current cursor position.
Ans:
(i). file.seekg(-1*sizeof(s),ios::end);
(ii). file.read((char*)&s,sizeof(s));
1-mark for each
(b) Write a C++ function which opens a text file welcome.txt and displays the words 2
starting with vowel characters(lower/upper case).
Page 9 of 14

Ans:
struct node
{
char name[20];
int age;
node *Link;
};
class stack
{
node *top;
public:
stack()
{ top=NULL; }
void stackPush();
void stackPop();
};
void disp_vowel_words()
{
ifstream file;
file.open("WELCOME.TXT",ios::in);
if(!file)
{
cout<<"File not opened.";
getch();
return;
}
char str[30];
while(file)
{
file.getline(str,30,' ');
switch(str[0])
{
case 'a':case'A':
case 'e':case'E':
case 'i':case'I':
case 'o':case'O':
case 'u':case'U': cout<<str<<end;
}
}
file.close();
}
1-mark for correctly open/close & loop
1-mark for correctly reading & checking 1st char
(c) A file ALLBOOKS.DAT contains the objects of class Book as given below:
Page 10 of 14

enum bool {true,false};


class Book
{
int Bno;
char Btitle[30];
bool issued;
public:
bool isIssued()
{ return issued; }
};
Write a C++ function to read from file ALLBOOKS.DAT and store all the books
which have been issued in another file named ISSUED.DAT.
Ans:
void copy()
{
ifstream fin;
ofstream fout;
fin.open("ALLBOOKS.DAT",ios::in|ios::binary);
fout.open("ISSUED.DAT",ios::out|ios::bianry);
if(!fin||!fout)
{
cout<<"file not opened.";
getch();
return;
}
Book b;
while(fin.read((char*)&b,sizeof(b)))
{
if(b.isIssued()==true)
fout.write((char*)&b,sizeof(b));
}
fin.close();
fout.close();
}
1-mark for correctly opening/closing both the files
1-mark for correct loop and reading
1-mark for correct checking and writing
5. (a) Write the difference between a table and a view in DBMS with the help of 2
suitable example.
1-mark for explanation
1-mark for example

Page 11 of 14

(b) Consider the following tables SCHOOL and ADMIN. Write SQL commands for
the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
SCHOOL
CODE

1001
1009
1203
1045
1123
1167
1215

TEACHERNAME

SUBJECT

DOJ

PERIODS

EXPERIENCE

RAVI SHANKAR
PRIYA RAI
LISA ANAND
YASHRAJ
GANAN
HARISH B
UMESH

ENGLISH
PHYSICS
ENGLISH
MATHS
PHYSICS
CHEMISTRY
PHYSICS

12/03/2000
03/09/1998
09/04/2000
24/08/2000
16/07/1999
19/10/1999
11/05/1998

24
26
27
24
28
27
22

10
12
5
15
3
5
16

CODE
1001
1009
1203
1045
1123
1167
1215

ADMIN
GENDER
DESIGNATION
MALE
VICE PRINCIPAL
FEMALE
COORDINATOR
FEMALE
COORDINATOR
MALE
HOD
MALE
SENIOR TEACHER
MALE
SENIOR TEACHER
MALE
HOD

i) To display TEACHERNAME, PERIODS of all teachers whose periods less


than 25.
ii) To display TEACHERNAME, CODE and DESIGNATION from tables
SCHOOL and ADMIN whose gender is male.
iii) To display subject & the number of teachers in each subject.
iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who
have joined the school after 01/01/1999.
v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY
SUBJECT;
vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE
DESIGNATION = COORDINATOR AND SCHOOL.CODE=ADMIN.CODE;
vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY
DESIGNATION HAVING COUNT (*) <2;
viii) SELECT COUNT (DISTINCT SUBJECT) FROM SCHOOL;
Ans:
1-mark for each correct query
mark for each correct output
6. (a) State(both) and prove(any one) Demorgan law algebraically.
1-mark for both expression
1-mark for algebraic proof
(b) Convert the following Boolean expression into its equivalent Canonical Product
of Sum form:
1-mark for correct result
(c) Draw the logic circuit for the following boolean expression:
F ( X , Y , Z ) ( X Y ).( X Z ).(Y Z )

2-marks for full correct


1-mark can be given for partial correct(with little errors)
Page 12 of 14

(d) Simplify the following boolean expression using K-map:


F ( A, B, C , D ) (0,2,3,4,6,7,8,10,12)
7. (a)
(b)
(c)
(d)
(e)

3 marks for full method and correct answer


What is VOIP?
1-mark for correct definition
What is the difference between IP Address and MAC Address?
1-mark for specific difference
What is meant by spyware?
1-mark for correct definition
What is meant by the terms Hackers and Crackers?
1-mark for correct explanation
East and West Public Ltd has decided to network all its offices spread in five building as
shown below:

Buildin
g2

Buildin
g1

Buildin
g3

Buildin
g4

Buildin
g5

The distance between various buildings is as follows:


Building 1 to Building 2
Building 3 to Building 5
Building 2 to Building 3
Building 1 to Building 5
Building 3 to Building 4
Building 2 to Building 5
Building 4 to Building 5
Number of Computers in each building:
Building 1
Building 2
Building 3
Building 4
Building 5

20m
70m
50m
65m
120m
50m
30m

40
45
110
60
70

(i) Suggest a cable layout for connecting all the buildings together.
(ii) Suggest the most suitable building to install the server of the organization with a
suitable reason.
(iii) Building 3 is used for many critical operations. It is tried that PC gets maximum
possible bandwidth. Which network device is/should be used for this?
(iv).The organization also has another office in same city but at a distant location
about25-30 Km away. How can link be established with building 1. (Suggest the
Page 13 of 14

1
1
1
1
4

transmission media).
1-mark for each correct answer
(f) What is meant by Open Source Software?
1-mark for correct answer
(g) Explain the difference between Bus Topology and Star Topology.
1-mark for correct difference

Page 14 of 14

1
1

You might also like