12 Computer Science Lyp 2010 Delhi PDF
12 Computer Science Lyp 2010 Delhi PDF
General Instructions:
1. (a) What is the difference between automatic type conversion and type casting? Also,
give a suitable C++ code to illustrate both. (2)
int N = 65;
cout<<C;
OUTPUT:
cout<<C;
OUTPUT:
0.5
void main( )
cout<<setw(5)<<Eno<<setw(25)<<EName<<endl;
OR
(c) Rewrite the following c++ program code after removing the syntax error(s) (if any).
Underline each correction. (2)
include <iostream.h>
class TRAIN
long TrainNo;
char Description[25];
public
void Entry ( )
cout<<TrainNo<<“:”<<Description<<endl;
};
void main( )
TRAIN T;
Entry. T( ); Display. T( );
Ans. #include<iostream.h>
#include<stdio.h>
class TRAIN
long TrainNo;
public:
void Entry ()
cout<<TrainNo<<“:”<<Description<<end1;
};
void main ()
TRAIN T;
T.Entry(); T.Display();
#inc1ude <iostream.h>
struct POINT
{int X, Y, Z;};
P.X+=Step;
P.Y-=Step;
P.Z+=Step;
P.X-=Step;
P.Y+=Step;
P.Z–=Step;
void main ( )
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl;
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
6, 34, 16
18, 22, 28
#include <iostream.h>
#include <ctype.h>
Text[K]=tolower (Text[K]);
else
if (Text[K]=’E’ || Text[K]==’e’)
Text[K]==C;
else
if (K%2==O)
Text[K]=toupper(Text[K]);
else
Text[K]=Text[K-l];
void main ( )
ChangeIt(OldText,’%’);
cout<<“New TEXT:”<<OldText<<endl;
(f) The following code is from a game, which generates a set of 4 random numbers.
Yallav is playing this game, help him to identify the correct option(s) out of the four
choices given below as the possible set of such numbers generated from the program
code so that he wins the game. Justify your answer. (2)
#include <iostream.h>
#include <stdlib.h>
void main ( )
randomize( ) ;
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iv) 19:16:15:16:338
Justification is as follows:
I POINT Number
Minimum Maximum
1 5 15 19
2 4 15 18
3 3 15 17
4 2 15 16
Ans. The process of using an -operator or a function in different ways for different set of
inputs given is known- as polymorphism. Function overloading is- an example of
polymorphism, where the functions having same name with different set of parameters
perform different operations.
Example:
cout<<“Hello”<<endl;
for(int I=1;I<=N;I++)
cout<<I<<endl;
cout<<N<<“x”<<I<<“=”<<N*I<<endl;
void main ( )
//ranging from 5 to 10
(b) Answer the questions (i) and (ii) after going through the following class: (2)
class TEST
TEST() //Function 1
Regno= 101;Max=100;Min=40;Score=75;
Regno=Pregno;Max=100;Min=40;Score=Pscore;
~TEST() //Function 3
cout<<“TEST Over”<<endl;
cout<<Regno<<“:”<<Max<<“:”<<Min<<endl;
cout<<“[Score]”<<Score<<endl;
};
(i) As per Object Oriented Programming, which. concept is illustrated by Function 1 and
Function 2 together?
Ans. Polymorphism
Function Overloading
OR
Constructor Overloading
(ii) What is Function 3 specifically referred as? When do you think, Function 3 will be
invoked/called?
Private Members
If Qty<=50 Offer is 0
If 50<Qty<=100 Offer is 5
If Qty>100 Offer is 10
Public Members
A function GetStock() to allow user to enter values for Code, Iname, Price, Qty
and call function GetOffer() to calculate the offer
A function ShowItem() to allow user to view the content of all the data members
float Price;
int Qty;
float Offer;
void GetOffer() ;
public:
void GetStock ()
cin>>Code;
cin>>Price>>Qty;
GetOffer() ;342
void ShowItern ( )
cout<<Code<<Iname<<Price<<Qty<<Offer;
};
if (Qty<=50)
else
(d) Answer the questions (i) to (iv) based on the following: (4)
class Chairperson
char CName[20];
protected:
void Allocate();
public:
Chairperson();
void Assign();
void Show();
};
class Director
char Dname[20];
protected:
char Profile[30];
public:
Director();
void Input();
void output();
};
public:
Company();
void Enter();
void Display();
};
(i) Which type of inheritance out of the following is specifically is illustrated in the
above C++ code?
(ii) Write the names of data members, which are accessible by objects of class type
Company.
Ans. None
(iii) Write the names of all member functions, which are accessible by objects of class
type Company.
(iv) Write the names of all members, which are accessible from member functions of
class Director.
3. (a) Write a function CHANGEO in C++, which accepts an array of integer and its size
as parameters and divide all those array elements by 7 which are divisible by 7 and
multiply other-array elements by 3. (3)
21 12 35 42 18
3 36 5 6 54
if (A[I]%7 = = 0)
else
A[I] = A[I] * 3;
OR
(b) An array P[50] [60] is stored in the memory along the column with each of the element
occupying 2 bytes, find out the memory location for the element P[10]
= 6800 + 2 (10+1000)
= 6800 + 2*1010
= 6800 + 2020
= 8820
= 6800 + 2 x 1010
= 6800 + 2020
= 8820
OR
= BaseAddress + W((I–LBR)+(J–LBC)*M)
Address of P[10][20]=6800+2((10-1)+(20-l)x50)
= 6800 + 2 (9 + 19 x 50 )
= 6800 + 2 x 959
= 6800 + 1918
= 8718
Ans. #include<iostream.h>
#include<stdio.h>
struct Node
};
class Stack
Node *Top;
public:
void Push() ;
void Pop() ;
void Display() ;
~Stack () ;
};
void Stack::Push()
Top = Temp;
void Stack::Pop()
delete Temp;
else
cout<<“stack Empty”;
void Stack::Display()
Stack::~Stack ()
while (Top!=NULL)
NODE *Temp=Top;
Top=Top->Link;
delete Temp;
void main ( )
do
cout<<“p/O/D/Q” ;
cin>>Ch;
switch (Ch)
} while (Ch!=’Q’);
Hint:
4 5 1
2 8 7
9 6 3
int S=0:
S = S + A [I][J];
return S;
OR
int S=0;
S = S + A [I][J];
return S;
OR
J = l;
else
J = 0;
S = S + A[I][J];
return S;
OR
if (C%2 == 0)
S = S + A[I][J];
C++;
return S;
OR
S = S + A[I][J];
C++
return S;
OR
int S=0;
if ((I+J)%2 == 0)
S = S + A[I][J];
return S;
OR
Ans.
False False
OR False
OR False
Step 1: Push
False
Step 2: Push
True
False
Step 5: Push
True
False
Step 6: Push
False
True
False
Step 8: OR
Step 9: Pop
OR
Any other method for evaluating the given postfix expression showing the Stack Status.
4. (a) Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using tellg() and seekp() functions for performing the
required task. (1)
#include <fstream.h>
class Client
public:
void Modify() ;
};
{ Client C;
fstream F;
F.open (“INFO.DAT”,ios::binary|ios::in|ios::out);
changed cin>>Cnoc;
if (Cnoc==C.ReturnCno())
C.Modify();
//Statement 1
// Statement 2
//modified record
F.write((char*)&C, sizeof(C));
F.close();
Ans. Statement 1:
F. tellg ();
Statement 2:
F. seekp(Pos-sizeof(C)) ;
OR
F.seekp(-sizeof(C), ios::cur);
OR
(b) Write a function in C++ to count the words “this” and “these” present in a text file
“ARTICLE.TXT”. (2)
[Note that the words “this” and “these” are complete words]
ifstream Fil;
Fil.open(“ARTICLE.TXT”);
int C1 = 0, C2 = 0
Fil>>Word;
if (strcmp(Word,“this”) ==0)
Cl++;
C2++;
Fil.close(); //gnore
OR
void COUNT( )
int C = 0;
while(!Fil.eof())
{ Fil>>Word;
C++;
Fil.close(); //Ignore
OR
void COUNT( )
ifstream Fil(“ARTICLE.TXT”);
char STR[l0];
if (strcmp(STR,“this”)==0)
Cl++;
else if (strcmp(STR,“these”)==0)
C2++;
OR
void COUNT ( )
while(Fil.get(Ch))
Word[I++] = Ch;
else
Word[I] = ‘\0’;
if (strcmp (Word,“this”)==0)
Cl++;
else if (strcmp(Word,“these”)==0)
I=0,
Fil.close(); //Ignore
OR
(c) Write a function in C++ to search and display details of all flights, whose destination
is “Mumbai” from a binary file “FLIGHT. DAT”. Assuming the binary file is containing
the objects of the following class. (3)
class FLIGHT
public:
void Display(){cout<<Fno<<“:”<<From<<“:”<<To<<endl;}
};
FLIGHT F;
ifstream fin;
while(fin.read((char*)&F, sizeof(F)))
if (strcmp(F. GetTo(),“Mumbai”))
F.Display() ;
fin.close(); //Ignore
OR
void Read ()
FLIGHT F;
ifstream fin;
while(!fin.eof())
if (strcmp(F. GetTo(),“Mumbai”))
F.Display();
Fin.read((char*)&F,sizeof(F))
Fin.close(); //Ignore
OR
5. (a) What do you understand by Candidate Keys in a table? Give a suitable example of
Candidate Keys from a table containing some meaningful data. (2)
Ans. A table may have more than one such attribute/group of attribute that identifies a tuple
uniquely, all such attribute(s) are known as Candidate Keys.
Table: Item
Table: STORE
Table: SUPPLIERS
Scode Sname
23 Soft Plastics
22 Terta Supply
(i) To display details of all the items in the Store table in ascending order of LastBuy.
(ii) To display ItemNo and Item name of those items from Store table whose Rate is
more than 15 Rupees.
(iii) To display the details of those items whose Supplier code (Scode) is 22 or Quantity
in Store (Qty) is more than 110 from the table Store.
(iv) Todisplay Minimum Rate of items for each Supplier individually as per Scode from
the table Store.
Ans. SELECT Scode, MIN(Rate) FROM STORE GROUP BY Scode; (b2) Give the output of the
following SQL queries: (2)
Ans.
Ans.
(A’+B’).(A +B)=A’.B+A.B’
Ans. LHS
= 0 + A’.B + A.B’+ 0
= A’.B + A.B’
= RHS (Verified)
OR
(b) Write the equivalent Boolean Expression for the following Logic circuit: (2)
(c) Write the POS form of a Boolean function H, which is represented in a truth table as
follows: (1)
X Y Z H
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
OR
H(X,Y,Z) = Π (1, 5, 6)
Note:
F(U,V,W,Z) = WZ + VZ + UV’W
7. (a) What was the role of ARPANET in the Computer Network? (1)
Ans. The first computer network was jointly designed by The Advanced-Research Projects
Agency (ARPA) and Department of Defence (DoD) of United States in 1969 and was called
ARPANET. It was an experimental project, which connected a few computers from some of
the reputed universities of USA and DoD. ARPANET allowed access to computer resource
This ARPANET was handed over to Defence Communication Agency (DCA) for further
development.
(1 Mark for mentioning that ARPANET was the first computer network)
OR
(b) Which of the following is not an unit for data transfer rate? (1)
(i) bps
(ii) abps
(iii) gbps
(iv) kbps
Ans. (ii)abps
(c) What is the difference between Trojan Horse and Virus in terms of computers? (1)
VIRUS: Virus is a malicious program that damages data and files and causes harm to
computer system.
OR
(d) What term we use for a software/hardware device, which is used to block,
unauthorized access while permitting authorized communications. This term is also
Ans. Firewall
(e) “Learn Together” is an educational NGO. It is setting up its new campus at Jabalpur for its
web based activities. The campus has 4 compounds as shown in the diagram below:
Center to center distances between various Compounds as per architectural drawings (in
Metre) is as follows:
Resources Compound 15
Accounts Compound 20
OR
(e2) Suggest the most suitable place (i.e. compound) to house the server for this NGO.
Also, provide a suitable reason for your suggestion. (1)
OR
(e3) Suggest the placement of the following devices with justification: (1)
(i) Repeater
(ii) Hub/Switch
Ans. (i) A Repeater should be placed when the distance between any two connecting
compounds exceeds 70 m.
(ii) Every compound will need one Hub I Switch, to send signals to all of the workstations
connected to it
OR
(e4) The NGO is planning to connect its International office situated in Mumbai, which
(f1) GNU
(f2) XML
(g) Write one advantage of each for Open Source Software and Proprietary Software.
(1)
Ans. An Open Source Software is freely and liberally licensed because of which users have
right to study, change. and improve its design and source code.
A Proprietary Software has a copyright owner, who can restrict the user's control over the
software, its modification, or restrictions in publishing of modified or unmodified versions.
(½ Mark for writing correct advantage / definition for Open Source Software)